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