diff options
Diffstat (limited to 'custom/thinklight.nix')
-rw-r--r-- | custom/thinklight.nix | 8 |
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) |