summaryrefslogtreecommitdiff
path: root/custom/notify-user.nix
blob: f95bc43db006283d08fe381b2463650a212ae92a (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
34
{ stdenv, writeTextFile
, ghcWithPackages
, user ? "gkleen"
, libnotify
}:

stdenv.mkDerivation {
  name = ''notify-${user}'';
  src = writeTextFile { name = ''notify-${user}.hs''; text = ''
    import Control.Shell
    import System.FilePath.Glob (glob)

    import Data.List (isPrefixOf)

    import Data.Either (either)

    main = do
      env <- shellEnv
      either print return =<< runSh (env { envWorkDir = "/" } ) $ do
        (envFile:_) <- liftIO $ glob "/home/${user}/.dbus/session-bus/*-0"
        sessionAddr <- snd . break (== '=') . head . filter ("DBUS_SESSION_BUS_ADDRESS=" `isPrefixOf`) . lines <$> input envFile 
        env <- getShellEnv
        withEnv "DBUS_SESSION_BUS_ADDRESS" sessionAddr $ run "${libnotify}/bin/notify-send" cmdline
  ''; };
  phases = [ "buildPhase" "installPhase" ];
  buildPhase = ''
    ${ghcWithPackages (p: with p; [ shellmate Glob ])}/bin/ghc -odir . -hidir . $src -o notify-${user}
  '';
  installPhase = ''
    mkdir -p $out/bin
    cp notify-${user} $out/bin
    chmod +x $out/bin/notify-${user}
  '';
}