summaryrefslogtreecommitdiff
path: root/custom/thinklight.nix
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-05-14 19:11:29 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2016-05-14 19:11:29 +0200
commit6c320e9fd6e6098ca13f69f0422c9ca93c3af94c (patch)
tree56afd05fabc1347f86803ef2d2f1f9a1003e4dd7 /custom/thinklight.nix
parentc1b34ef94cc4aab4b362fe4630a154f6acff490f (diff)
downloadnixos-6c320e9fd6e6098ca13f69f0422c9ca93c3af94c.tar
nixos-6c320e9fd6e6098ca13f69f0422c9ca93c3af94c.tar.gz
nixos-6c320e9fd6e6098ca13f69f0422c9ca93c3af94c.tar.bz2
nixos-6c320e9fd6e6098ca13f69f0422c9ca93c3af94c.tar.xz
nixos-6c320e9fd6e6098ca13f69f0422c9ca93c3af94c.zip
antiquotation instead of wrapper
Diffstat (limited to 'custom/thinklight.nix')
-rw-r--r--custom/thinklight.nix8
1 files changed, 2 insertions, 6 deletions
diff --git a/custom/thinklight.nix b/custom/thinklight.nix
index ced11d02..346bd21a 100644
--- a/custom/thinklight.nix
+++ b/custom/thinklight.nix
@@ -9,7 +9,7 @@ stdenv.mkDerivation {
9 source $stdenv/setup 9 source $stdenv/setup
10 mkdir -p $out/bin 10 mkdir -p $out/bin
11 $ghc/bin/ghc $src -o $out/bin/thinklight 11 $ghc/bin/ghc $src -o $out/bin/thinklight
12 wrapProgram $out/bin/thinklight --set THINKLIGHT ${thinklight} 12 chmod +4000 $out/bin/thinklight
13 ''; 13 '';
14 src = builtins.toFile "source.hs" '' 14 src = builtins.toFile "source.hs" ''
15 import Control.Monad (sequence) 15 import Control.Monad (sequence)
@@ -21,7 +21,6 @@ stdenv.mkDerivation {
21 import Prelude hiding (readFile) 21 import Prelude hiding (readFile)
22 import Data.List (intersperse) 22 import Data.List (intersperse)
23 import Data.Maybe (fromMaybe) 23 import Data.Maybe (fromMaybe)
24 import System.Posix.User (setEffectiveUserID)
25 24
26 data Mode = On | Off | Toggle | Blink deriving (Read, Show, Eq) 25 data Mode = On | Off | Toggle | Blink deriving (Read, Show, Eq)
27 26
@@ -29,14 +28,11 @@ stdenv.mkDerivation {
29 main = do 28 main = do
30 args <- getArgs 29 args <- getArgs
31 let mode = if length args >= 1 then read $ head args else Toggle 30 let mode = if length args >= 1 then read $ head args else Toggle
32 setEffectiveUserID 0
33 sequence $ map (\g -> catchIOError g (\e -> if isDoesNotExistError e then return () else ioError e)) [thinklight mode] 31 sequence $ map (\g -> catchIOError g (\e -> if isDoesNotExistError e then return () else ioError e)) [thinklight mode]
34 return () 32 return ()
35 33
36 findBase :: IO FilePath 34 findBase :: IO FilePath
37 findBase = do 35 findBase = return "/sys/class/leds/tpacpi::${thinklight}"
38 env <- fromMaybe "thinklight" <$> lookupEnv "THINKLIGHT"
39 return $ "/sys/class/leds/tpacpi::" ++ env
40 36
41 readMax, readCurrent :: IO String 37 readMax, readCurrent :: IO String
42 readMax = readFile =<< ((</> "max_brightness") <$> findBase) 38 readMax = readFile =<< ((</> "max_brightness") <$> findBase)