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 = lib.mdDoc ''
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 = lib.mdDoc ''
22 The lorri package to use.
23 '';
24 defaultText = lib.literalExpression "pkgs.lorri";
25 };
26 };
27 };
28
29 config = lib.mkIf cfg.enable {
30 systemd.user.sockets.lorri = {
31 description = "Socket for Lorri Daemon";
32 wantedBy = [ "sockets.target" ];
33 socketConfig = {
34 ListenStream = "%t/${socketPath}";
35 RuntimeDirectory = "lorri";
36 };
37 };
38
39 systemd.user.services.lorri = {
40 description = "Lorri Daemon";
41 requires = [ "lorri.socket" ];
42 after = [ "lorri.socket" ];
43 path = with pkgs; [ config.nix.package git gnutar gzip ];
44 serviceConfig = {
45 ExecStart = "${cfg.package}/bin/lorri daemon";
46 PrivateTmp = true;
47 ProtectSystem = "strict";
48 ProtectHome = "read-only";
49 Restart = "on-failure";
50 };
51 };
52
53 environment.systemPackages = [ cfg.package pkgs.direnv ];
54 };
55}