diff options
Diffstat (limited to 'custom/notify-users.nix')
-rw-r--r-- | custom/notify-users.nix | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/custom/notify-users.nix b/custom/notify-users.nix new file mode 100644 index 00000000..e68b0be2 --- /dev/null +++ b/custom/notify-users.nix | |||
@@ -0,0 +1,53 @@ | |||
1 | { config, lib, pkgs, ... }: | ||
2 | |||
3 | with lib; | ||
4 | |||
5 | let | ||
6 | cfg = config.services.notify-users; | ||
7 | |||
8 | notify-user = userName: with pkgs; stdenv.mkDerivation { | ||
9 | name = "notify-${userName}"; | ||
10 | src = ./notify-user.hs; | ||
11 | |||
12 | phases = [ "unpackPhase" "buildPhase" "installPhase" ]; | ||
13 | |||
14 | unpackPhase = '' | ||
15 | cp $src notify-user.hs | ||
16 | ''; | ||
17 | |||
18 | inherit userName; | ||
19 | userHome = config.users.users."${userName}".home; | ||
20 | |||
21 | buildPhase = '' | ||
22 | substituteAllInPlace notify-user.hs | ||
23 | ${ghcWithPackages (p: with p; [ Glob process libnotify getopt-simple containers ])}/bin/ghc -odir . -hidir . $src -o notify-${userName} | ||
24 | ''; | ||
25 | |||
26 | installPhase = '' | ||
27 | mkdir -p $out/bin | ||
28 | |||
29 | install -m 755 -t $out/bin \ | ||
30 | notify-${userName} | ||
31 | ''; | ||
32 | }; | ||
33 | in { | ||
34 | options = { | ||
35 | services.notify-users = mkOption { | ||
36 | type = with types; listOf str; | ||
37 | default = []; | ||
38 | description = '' | ||
39 | Users to install a notify-user script for | ||
40 | ''; | ||
41 | }; | ||
42 | }; | ||
43 | |||
44 | config = mkIf (cfg != []) { | ||
45 | security.wrappers = listToAttrs (map (user: nameValuePair "notify-${user}" { | ||
46 | owner = user; | ||
47 | setuid = true; | ||
48 | setgid = false; | ||
49 | permissions = "u+rx,g+x,o+x"; | ||
50 | source = "${notify-user user}/bin/notify-${user}"; | ||
51 | }) cfg); | ||
52 | }; | ||
53 | } | ||