summaryrefslogtreecommitdiff
path: root/custom/notify-user.nix
blob: d1716e05973b1a1169150f0c246c8c864fbf4377 (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
{ 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
    install notify-${user} $out/bin
  '';
}