Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
262 changes: 145 additions & 117 deletions modules/services/lorri.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,124 +31,152 @@ in
};
};

config = lib.mkIf cfg.enable {
assertions = [
(lib.hm.assertions.assertPlatform "services.lorri" pkgs lib.platforms.linux)
];
Comment on lines -35 to -37
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're removing the platform limitation, it would be nice to create a news entry and update the test suite to test on darwin, as well.


home.packages = [ cfg.package ];

systemd.user = {
services.lorri = {
Unit = {
Description = "lorri build daemon";
Requires = "lorri.socket";
After = "lorri.socket";
RefuseManualStart = true;
config = lib.mkIf cfg.enable (
let
path =
with pkgs;
lib.makeSearchPath "bin" [
cfg.nixPackage
gitMinimal
gnutar
gzip
];
in
lib.mkMerge [
{
home.packages = [ cfg.package ];
}
(lib.mkIf pkgs.stdenv.isDarwin {
warnings =
if cfg.enableNotifications then
[
"services.lorri.enableNotifications is not currently supported for Darwin."
]
else
[ ];
Comment on lines +50 to +56
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could probably make it not visible and read-only on darwin, as well.

launchd.agents.lorri = {
enable = true;
config = {
ProgramArguments = [
"${cfg.package}/bin/lorri"
"daemon"
];

EnvironmentVariables = {
PATH = "${path}";
};

RunAtLoad = true;
KeepAlive = {
Crashed = true;
SuccessfulExit = false;
};
};
};

Service = {
ExecStart = "${cfg.package}/bin/lorri daemon";
PrivateTmp = true;
ProtectSystem = "strict";
ProtectHome = "read-only";
ReadWritePaths = [
# /run/user/1000 for the socket
"%t"
# Needs to update own cache
"%C/lorri"
# Needs %C/nix/fetcher-cache-v1.sqlite
"%C/nix"
];
CacheDirectory = [ "lorri" ];
Restart = "on-failure";
Environment =
let
path =
with pkgs;
lib.makeSearchPath "bin" [
cfg.nixPackage
gitMinimal
gnutar
gzip
];
in
[ "PATH=${path}" ];
};
};

sockets.lorri = {
Unit = {
Description = "Socket for lorri build daemon";
};

Socket = {
ListenStream = "%t/lorri/daemon.socket";
RuntimeDirectory = "lorri";
};

Install = {
WantedBy = [ "sockets.target" ];
};
};

services.lorri-notify = lib.mkIf cfg.enableNotifications {
Unit = {
Description = "lorri build notifications";
After = "lorri.service";
Requires = "lorri.service";
};

Service = {
# Don't start until lorri daemon is actually running
ExecStartPre = pkgs.writeShellScript "lorri-notify-check" ''
lorri info --shell-file . | grep 'Lorri Daemon Status:.*running'
'';
RestartSec = "5s";

ExecStart =
let
jqFile = ''
(
(.Started? | values | ["Build starting", .nix_file, "emblem-synchronizing"]),
(.Completed? | values | ["Build complete", .nix_file, "checkmark"]),
(.Failure? | values | ["Build failed", .nix_file, "dialog-error"])
)
| @tsv
'';

notifyScript = pkgs.writeShellScript "lorri-notify" ''
set -o pipefail
lorri internal stream-events --kind live \
| jq --unbuffered -r '${jqFile}' \
| while IFS=$'\t' read -r status nixFile icon; do
notify-send --app-name "Lorri" --hint=int:transient:1 \
--icon "$icon" "$status" "$nixFile"
done
})
(lib.mkIf pkgs.stdenv.isLinux {
systemd.user = {
services.lorri = {
Unit = {
Description = "lorri build daemon";
Requires = "lorri.socket";
After = "lorri.socket";
RefuseManualStart = true;
};

Service = {
ExecStart = "${cfg.package}/bin/lorri daemon";
PrivateTmp = true;
ProtectSystem = "strict";
ProtectHome = "read-only";
ReadWritePaths = [
# /run/user/1000 for the socket
"%t"
# Needs to update own cache
"%C/lorri"
# Needs %C/nix/fetcher-cache-v1.sqlite
"%C/nix"
];
CacheDirectory = [ "lorri" ];
Restart = "on-failure";
Environment = [ "PATH=${path}" ];
};
};

sockets.lorri = {
Unit = {
Description = "Socket for lorri build daemon";
};

Socket = {
ListenStream = "%t/lorri/daemon.socket";
RuntimeDirectory = "lorri";
};

Install = {
WantedBy = [ "sockets.target" ];
};
};

services.lorri-notify = lib.mkIf cfg.enableNotifications {
Unit = {
Description = "lorri build notifications";
After = "lorri.service";
Requires = "lorri.service";
};

Service = {
# Don't start until lorri daemon is actually running
ExecStartPre = pkgs.writeShellScript "lorri-notify-check" ''
lorri info --shell-file . | grep 'Lorri Daemon Status:.*running'
'';
in
toString notifyScript;
Restart = "on-failure";
Environment =
let
path = lib.makeSearchPath "bin" (
with pkgs;
[
bash
gnugrep
jq
libnotify
cfg.package
]
);
in
"PATH=${path}";
RestartSec = "5s";

ExecStart =
let
jqFile = ''
(
(.Started? | values | ["Build starting", .nix_file, "emblem-synchronizing"]),
(.Completed? | values | ["Build complete", .nix_file, "checkmark"]),
(.Failure? | values | ["Build failed", .nix_file, "dialog-error"])
)
| @tsv
'';

notifyScript = pkgs.writeShellScript "lorri-notify" ''
set -o pipefail
lorri internal stream-events --kind live \
| jq --unbuffered -r '${jqFile}' \
| while IFS=$'\t' read -r status nixFile icon; do
notify-send --app-name "Lorri" --hint=int:transient:1 \
--icon "$icon" "$status" "$nixFile"
done
'';
in
toString notifyScript;
Restart = "on-failure";
Environment =
let
path = lib.makeSearchPath "bin" (
with pkgs;
[
bash
gnugrep
jq
libnotify
cfg.package
]
);
in
"PATH=${path}";
};

Install = {
WantedBy = [ "lorri.service" ];
};
};
};

Install = {
WantedBy = [ "lorri.service" ];
};
};
};
};
})
]
);
}