summaryrefslogtreecommitdiff
path: root/custom/notify-user.nix
blob: a437bf9b1ea1eee56a0c07a0f3920194b247ab86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{ stdenv, writeTextFile
, ghcWithPackages
, user ? "gkleen"
, libnotify
}:

stdenv.mkDerivation {
  name = ''notify-${user}'';
  src = writeTextFile { name = ''notify-${user}.hs''; text = ''
    import System.FilePath.Glob (glob)
    import System.Directory (setCurrentDirectory)
    import System.Environment (setEnv, getArgs)

    import Data.List (isPrefixOf)

    main = do
      setCurrentDirectory "/"
      (envFile:_) <- glob "/home/${user}/.dbus/session-bus/*"
      sessionAddr <- snd . break (== '=') . head . filter ("DBUS_SESSION_BUS_ADDRESS=" `isPrefixOf`) . lines <$> readFile envFile
      setEnv "DBUS_SESSION_BUS_ADDRESS" sessionAddr
      proc "${libnotify}/bin/notify-send" =<< getArgs
      
  ''; };
  phases = [ "buildPhase" "installPhase" ];
  buildPhase = ''
    ${ghcWithPackages (p: with p; [ Glob directory process ])}/bin/ghc -odir . -hidir . $src -o notify-${user}
  '';
  installPhase = ''
    mkdir -p $out/bin
    cp notify-${user} $out/bin
    chmod +x $out/bin/notify-${user}
  '';
}