summaryrefslogtreecommitdiff
path: root/custom/notify-user.nix
diff options
context:
space:
mode:
authorGregor Kleen <pngwjpgh@users.noreply.github.com>2016-07-21 22:01:28 +0200
committerGregor Kleen <pngwjpgh@users.noreply.github.com>2016-07-21 22:01:28 +0200
commited8801ddec7a2a046231b34e1f84ad39fb26af48 (patch)
tree5b06a6bdd751cecf69432b7dde0b16cdc5a90121 /custom/notify-user.nix
parentd61f49772f4b7ad39dc2fcbd463ad8671e819a3a (diff)
downloadnixos-ed8801ddec7a2a046231b34e1f84ad39fb26af48.tar
nixos-ed8801ddec7a2a046231b34e1f84ad39fb26af48.tar.gz
nixos-ed8801ddec7a2a046231b34e1f84ad39fb26af48.tar.bz2
nixos-ed8801ddec7a2a046231b34e1f84ad39fb26af48.tar.xz
nixos-ed8801ddec7a2a046231b34e1f84ad39fb26af48.zip
custom escaping
Diffstat (limited to 'custom/notify-user.nix')
-rw-r--r--custom/notify-user.nix11
1 files changed, 6 insertions, 5 deletions
diff --git a/custom/notify-user.nix b/custom/notify-user.nix
index d3e69bcd..808d1615 100644
--- a/custom/notify-user.nix
+++ b/custom/notify-user.nix
@@ -10,24 +10,25 @@ stdenv.mkDerivation {
10 import System.FilePath.Glob (glob) 10 import System.FilePath.Glob (glob)
11 import System.Environment (setEnv, getArgs) 11 import System.Environment (setEnv, getArgs)
12 import System.Process (callProcess) 12 import System.Process (callProcess)
13 import System.Posix.Escape (escape)
14 13
15 import Data.List (isPrefixOf, dropWhileEnd) 14 import Data.List (isPrefixOf, dropWhileEnd)
16 import Data.Char (isSpace) 15 import Data.Char (isSpace)
17 16
18 import Control.Monad (forM_) 17 import Control.Monad (forM_)
19 18
20 main = do 19 main = do
21 envFiles <- glob "/home/${user}/.dbus/session-bus/*" 20 envFiles <- glob "/home/${user}/.dbus/session-bus/*"
22 forM_ envFiles $ \envFile -> do 21 forM_ envFiles $ \envFile -> do
23 sessionAddr <- tail . snd . break (== '=') . head . filter ("DBUS_SESSION_BUS_ADDRESS=" `isPrefixOf`) . lines <$> readFile envFile 22 sessionAddr <- tail . snd . break (== '=') . head . filter ("DBUS_SESSION_BUS_ADDRESS=" `isPrefixOf`) . lines <$> readFile envFile
24 setEnv "DBUS_SESSION_BUS_ADDRESS" sessionAddr 23 setEnv "DBUS_SESSION_BUS_ADDRESS" sessionAddr
25 callProcess "${libnotify}/bin/notify-send" =<< (++) <$> getArgs <*> (pure . escape . dropWhileEnd isSpace <$> getContents) 24 callProcess "${libnotify}/bin/notify-send" =<< (++) <$> getArgs <*> (pure . concatMap escape . dropWhileEnd isSpace <$> getContents)
26 25 where
26 escape '\\' = "\\\\"
27 escape x = pure x
27 ''; }; 28 ''; };
28 phases = [ "buildPhase" "installPhase" ]; 29 phases = [ "buildPhase" "installPhase" ];
29 buildPhase = '' 30 buildPhase = ''
30 ${ghcWithPackages (p: with p; [ Glob process posix-escape ])}/bin/ghc -odir . -hidir . $src -o notify-${user} 31 ${ghcWithPackages (p: with p; [ Glob process ])}/bin/ghc -odir . -hidir . $src -o notify-${user}
31 ''; 32 '';
32 installPhase = '' 33 installPhase = ''
33 mkdir -p $out/bin 34 mkdir -p $out/bin