~james/core

core/nix/modules/shuttle.nix -rw-r--r-- 1.4 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 16 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{
  config,
  lib,
  pkgs,
  ...
}: let
  cfg = config.services.tangled.shuttle;

  postBuildHook = pkgs.writeShellApplication {
    name = "spindle-post-build-hook";
    text = ''
      set -f

      if [ -z "''${OUT_PATHS:-}" ]; then
        exit 0
      fi

      # OUT_PATHS is intentionally split into individual store paths for the agent
      # shellcheck disable=SC2086
      exec ${cfg.package}/bin/shuttle enqueue-built-paths $OUT_PATHS
    '';
  };
in {
  options.services.tangled.shuttle = {
    enable = lib.mkEnableOption "the shuttle guest agent";

    package = lib.mkOption {
      type = lib.types.package;
      description = "package providing the shuttle executable.";
    };
  };

  config = lib.mkIf cfg.enable {
    nix.settings.post-build-hook = "${postBuildHook}/bin/spindle-post-build-hook";

    systemd.services.shuttle = {
      description = "shuttle guest agent";
      wantedBy = ["multi-user.target"];
      wants = ["network-online.target"];
      after = [
        "local-fs.target"
        "network-online.target"
      ];
      before = ["nix-daemon.service"];
      restartIfChanged = false;
      # nix flakes require git
      path = [pkgs.gitMinimal];
      environment = {
        NIX_PATH = lib.concatStringsSep ":" config.nix.nixPath;
      };
      serviceConfig = {
        Type = "simple";
        ExecStart = "${cfg.package}/bin/shuttle";
        Restart = "always";
        RestartSec = "1s";
      };
    };
  };
}