summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--custom/thinklight.nix58
-rw-r--r--hel.nix3
2 files changed, 60 insertions, 1 deletions
diff --git a/custom/thinklight.nix b/custom/thinklight.nix
new file mode 100644
index 00000000..d3d4e7ca
--- /dev/null
+++ b/custom/thinklight.nix
@@ -0,0 +1,58 @@
1{ stdenv, haskellPackages, thinklight ? "thinklight", makeWrapper }:
2
3stdenv.mkDerivation {
4 name = "thinklight-0.1";
5 ghc = haskellPackages.ghcWithPackages (self: [self.strict]);
6 outputs = [ "out" ];
7 builder = builtins.toFile "builder.sh" ''
8 source $stdenv/setup
9 mkdir -p $out/bin
10 $ghc/bin/ghc $src -o $out/bin/thinklight
11 wrapProgram $out/bin/thinklight --set THINKLIGHT ${thinklight}
12 '';
13 src = builtins.toFile "source.hs" ''
14 import Control.Monad (sequence)
15 import System.IO.Error
16 import System.Environment
17 import System.FilePath
18 import Control.Concurrent (threadDelay)
19 import System.IO.Strict (readFile)
20 import Prelude hiding (readFile)
21 import Data.List (intersperse)
22
23 data Mode = On | Off | Toggle | Blink deriving (Read, Show, Eq)
24
25 main :: IO ()
26 main = do
27 args <- getArgs
28 let mode = if length args >= 1 then read $ head args else Toggle
29 sequence $ map (\g -> catchIOError g (\e -> if isDoesNotExistError e then return () else ioError e)) [thinklight mode]
30 return ()
31
32 findBase :: IO FilePath
33 findBase = do
34 env <- fromMaybe "thinklight" <$> lookupEnv "THINKLIGHT"
35 return $ "/sys/class/leds/tpacpi::" ++ env
36
37 readMax, readCurrent :: IO String
38 readMax = readFile =<< ((</> "max_brightness") <$> findBase)
39 readCurrent = readFile =<< ((</> "brightness") <$> findBase)
40 writeCurrent :: String -> IO ()
41 writeCurrent str = flip writeFile str =<< ((</> "brightness") <$> findBase)
42
43 thinklight :: Mode -> IO ()
44 thinklight On = readMax >>= writeCurrent . show
45 thinklight Off = writeCurrent "0"
46 thinklight Toggle = do
47 c <- readCurrent
48 m <- readMax
49 let m' = read m :: Int
50 let c' = read c :: Int
51 writeCurrent $ show $ if c' /= 0 then 0 else m'
52 thinklight Blink = do
53 args <- getArgs
54 thinklight Toggle
55 sequence $ intersperse (thinklight Toggle) $ map (\i -> threadDelay $ (read i) * 10^3) (tail args)
56 thinklight Toggle
57 '';
58}
diff --git a/hel.nix b/hel.nix
index b46b7525..29ae5ba9 100644
--- a/hel.nix
+++ b/hel.nix
@@ -48,6 +48,7 @@
48 git 48 git
49 slock 49 slock
50 shadow 50 shadow
51 (callPackage ./custom/thinklight.nix { thinklight = "kbd_backlight"; })
51 ]; 52 ];
52 53
53 services = { 54 services = {
@@ -141,7 +142,7 @@
141 %wheel ALL=(ALL) NOPASSWD: SYSCTRL 142 %wheel ALL=(ALL) NOPASSWD: SYSCTRL
142 ''; 143 '';
143 144
144 setuidPrograms = ["slock" "mount" "mount.nfs" "umount" "newgrp"]; 145 setuidPrograms = ["slock" "mount" "mount.nfs" "umount" "newgrp" "thinklight"];
145 }; 146 };
146 147
147 time.timeZone = "Europe/Berlin"; 148 time.timeZone = "Europe/Berlin";