fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Judson Lesterlorri: add nixPackage and enableNotifications optionsa7f0cc2d

master
2.8 KiB106 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.services.lorri;
8
9in {
10  meta.maintainers = [ maintainers.gerschtli ];
11
12  options.services.lorri = {
13    enable = mkEnableOption "lorri build daemon";
14
15    enableNotifications = mkEnableOption "lorri build notifications";
16
17    package = mkOption {
18      type = types.package;
19      default = pkgs.lorri;
20      defaultText = literalExpression "pkgs.lorri";
21      description = "Which lorri package to install.";
22    };
23
24    nixPackage = mkOption {
25      type = types.package;
26      default = pkgs.nix;
27      defaultText = literalExpression "pkgs.nix";
28      example = literalExpression "pkgs.nixVersions.unstable";
29      description = "Which nix package to use.";
30    };
31  };
32
33  config = mkIf cfg.enable {
34    assertions = [
35      (lib.hm.assertions.assertPlatform "services.lorri" pkgs
36        lib.platforms.linux)
37    ];
38
39    home.packages = [ cfg.package ];
40
41    systemd.user = {
42      services.lorri = {
43        Unit = {
44          Description = "lorri build daemon";
45          Requires = "lorri.socket";
46          After = "lorri.socket";
47          RefuseManualStart = true;
48        };
49
50        Service = {
51          ExecStart = "${cfg.package}/bin/lorri daemon";
52          PrivateTmp = true;
53          ProtectSystem = "strict";
54          ProtectHome = "read-only";
55          Restart = "on-failure";
56          Environment = let
57            path = with pkgs;
58              makeSearchPath "bin" [ cfg.nixPackage gitMinimal gnutar gzip ];
59          in [ "PATH=${path}" ];
60        };
61      };
62
63      sockets.lorri = {
64        Unit = { Description = "Socket for lorri build daemon"; };
65
66        Socket = {
67          ListenStream = "%t/lorri/daemon.socket";
68          RuntimeDirectory = "lorri";
69        };
70
71        Install = { WantedBy = [ "sockets.target" ]; };
72      };
73
74      services.lorri-notify = mkIf cfg.enableNotifications {
75        Unit = {
76          Description = "lorri build notifications";
77          After = "lorri.service";
78          Requires = "lorri.service";
79        };
80
81        Service = {
82          ExecStart = let
83            jqFile = ''
84              (
85                (.Started?   | values | "Build starting in \(.nix_file)"),
86                (.Completed? | values | "Build complete in \(.nix_file)"),
87                (.Failure?   | values | "Build failed in \(.nix_file)")
88              )
89            '';
90
91            notifyScript = pkgs.writeShellScript "lorri-notify" ''
92              lorri internal stream-events --kind live \
93                | jq --unbuffered '${jqFile}' \
94                | xargs -n 1 notify-send "Lorri Build"
95            '';
96          in toString notifyScript;
97          Restart = "on-failure";
98          Environment = let
99            path = makeSearchPath "bin"
100              (with pkgs; [ bash jq findutils libnotify cfg.package ]);
101          in "PATH=${path}";
102        };
103      };
104    };
105  };
106}