1{ config, lib, pkgs, ... }:
2
3let
4 cfg = config.services.lorri;
5 socketPath = "lorri/daemon.socket";
6in {
7 options = {
8 services.lorri = {
9 enable = lib.mkOption {
10 default = false;
11 type = lib.types.bool;
12 description = ''
13 Enables the daemon for `lorri`, a nix-shell replacement for project
14 development. The socket-activated daemon starts on the first request
15 issued by the `lorri` command.
16 '';
17 };
18 package = lib.mkOption {
19 default = pkgs.lorri;
20 type = lib.types.package;
21 description = ''
22 The lorri package to use.
23 '';
24 defaultText = lib.literalExample "pkgs.lorri";
25 example = lib.literalExample "pkgs.lorri";
26 };
27 };
28 };
29
30 config = lib.mkIf cfg.enable {
31 systemd.user.sockets.lorri = {
32 description = "Socket for Lorri Daemon";
33 wantedBy = [ "sockets.target" ];
34 socketConfig = {
35 ListenStream = "%t/${socketPath}";
36 RuntimeDirectory = "lorri";
37 };
38 };
39
40 systemd.user.services.lorri = {
41 description = "Lorri Daemon";
42 requires = [ "lorri.socket" ];
43 after = [ "lorri.socket" ];
44 path = with pkgs; [ config.nix.package git gnutar gzip ];
45 serviceConfig = {
46 ExecStart = "${cfg.package}/bin/lorri daemon";
47 PrivateTmp = true;
48 ProtectSystem = "strict";
49 ProtectHome = "read-only";
50 Restart = "on-failure";
51 };
52 };
53
54 environment.systemPackages = [ cfg.package ];
55 };
56}