fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
2.1 KiB84 linesraw
1{ config, pkgs, lib, ... }:
2
3with lib;
4
5let
6
7  cfg = config.services.cachix-agent;
8
9in {
10  meta.maintainers = [ maintainers.rycee ];
11
12  options.services.cachix-agent = {
13    enable =
14      mkEnableOption "Cachix Deploy Agent: <https://docs.cachix.org/deploy/>";
15
16    name = mkOption {
17      type = types.str;
18      description = "The unique agent name.";
19    };
20
21    verbose = mkEnableOption "verbose output";
22
23    profile = mkOption {
24      type = types.str;
25      default = "home-manager";
26      description = ''
27        The Nix profile name.
28      '';
29    };
30
31    host = mkOption {
32      type = types.nullOr types.str;
33      default = null;
34      description = "Cachix URI to use.";
35    };
36
37    package = mkPackageOption pkgs "cachix" { };
38
39    credentialsFile = mkOption {
40      type = types.path;
41      default = "${config.xdg.configHome}/cachix-agent.token";
42      defaultText =
43        literalExpression ''"''${config.xdg.configHome}/cachix-agent.token"'';
44      description = ''
45        Required file that needs to contain
46        `CACHIX_AGENT_TOKEN=...`.
47      '';
48    };
49  };
50
51  config = mkIf cfg.enable {
52    assertions = [
53      (lib.hm.assertions.assertPlatform "services.cachix-agent" pkgs
54        lib.platforms.linux)
55    ];
56
57    systemd.user.services.cachix-agent = {
58      Unit.Description = "Cachix Deploy Agent";
59
60      Service = {
61        Environment = [
62          "PATH=${
63            if config.nix.enable && config.nix.package != null then
64              config.nix.package
65            else
66              pkgs.nix
67          }/bin"
68        ];
69        EnvironmentFile = cfg.credentialsFile;
70
71        # We don't want to kill children processes as those are deployments.
72        KillMode = "process";
73        Restart = "on-failure";
74        ExecStart = escapeShellArgs ([ "${cfg.package}/bin/cachix" ]
75          ++ optional cfg.verbose "--verbose"
76          ++ optional (cfg.host != null) "--host ${cfg.host}"
77          ++ [ "deploy" "agent" cfg.name ]
78          ++ optional (cfg.profile != null) cfg.profile);
79      };
80
81      Install.WantedBy = [ "default.target" ];
82    };
83  };
84}