summaryrefslogtreecommitdiff
path: root/custom/notify-user.nix
blob: f433f4a756a9684b843f987f86c40e2c94005f0a (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
{ 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)

    main = shell_ $ 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}
  '';
}