Monorepo for Tangled
tangled.org
1{
2 config,
3 lib,
4 pkgs,
5 ...
6}: let
7 cfg = config.services.tangled.shuttle;
8
9 postBuildHook = pkgs.writeShellApplication {
10 name = "spindle-post-build-hook";
11 text = ''
12 set -f
13
14 if [ -z "''${OUT_PATHS:-}" ]; then
15 exit 0
16 fi
17
18 # OUT_PATHS is intentionally split into individual store paths for the agent
19 # shellcheck disable=SC2086
20 exec ${cfg.package}/bin/shuttle enqueue-built-paths $OUT_PATHS
21 '';
22 };
23in {
24 options.services.tangled.shuttle = {
25 enable = lib.mkEnableOption "the shuttle guest agent";
26
27 package = lib.mkOption {
28 type = lib.types.package;
29 description = "package providing the shuttle executable.";
30 };
31 };
32
33 config = lib.mkIf cfg.enable {
34 nix.settings.post-build-hook = "${postBuildHook}/bin/spindle-post-build-hook";
35
36 systemd.services.shuttle = {
37 description = "shuttle guest agent";
38 wantedBy = ["multi-user.target"];
39 wants = ["network-online.target"];
40 after = [
41 "local-fs.target"
42 "network-online.target"
43 ];
44 before = ["nix-daemon.service"];
45 restartIfChanged = false;
46 environment = {
47 NIX_PATH = lib.concatStringsSep ":" config.nix.nixPath;
48 };
49 serviceConfig = {
50 Type = "simple";
51 ExecStart = "${cfg.package}/bin/shuttle";
52 Restart = "always";
53 RestartSec = "1s";
54 };
55 };
56 };
57}