summaryrefslogtreecommitdiff
path: root/custom/notify-user.nix
blob: 0b98d672333468f4c3e2e74e4b2556845fbc6eb3 (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 Control.Shell
    import System.FilePath.Glob (glob)
    import System.Directory (setCurrentDirectory)

    import Data.List (isPrefixOf)

    main = do
      setCurrentDirectory "/"
      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 directory ])}/bin/ghc -odir . -hidir . $src -o notify-${user}
  '';
  installPhase = ''
    mkdir -p $out/bin
    cp notify-${user} $out/bin
    chmod +x $out/bin/notify-${user}
  '';
}