|
| 1 | +{ |
| 2 | + lib, |
| 3 | + pkgs, |
| 4 | + config, |
| 5 | + ... |
| 6 | +}: |
| 7 | +let |
| 8 | + cfg = config.services.buildbot-nix.master; |
| 9 | + bb-lib = import ./lib.nix; |
| 10 | +in |
| 11 | +{ |
| 12 | + options.services.buildbot-nix.master.cachix = { |
| 13 | + enable = lib.mkEnableOption "Enable Cachix integration"; |
| 14 | + |
| 15 | + name = lib.mkOption { |
| 16 | + type = lib.types.str; |
| 17 | + description = "Cachix name"; |
| 18 | + }; |
| 19 | + |
| 20 | + auth = lib.mkOption { |
| 21 | + type = lib.types.attrTag { |
| 22 | + signingKey = lib.mkOption { |
| 23 | + description = '' |
| 24 | + Use a signing key to authenticate with Cachix. |
| 25 | + ''; |
| 26 | + |
| 27 | + type = lib.types.submodule { |
| 28 | + options.file = lib.mkOption { |
| 29 | + type = lib.types.path; |
| 30 | + description = '' |
| 31 | + Path to a file containing the signing key. |
| 32 | + ''; |
| 33 | + }; |
| 34 | + }; |
| 35 | + }; |
| 36 | + |
| 37 | + authToken = lib.mkOption { |
| 38 | + description = '' |
| 39 | + Use an authentication token to authenticate with Cachix. |
| 40 | + ''; |
| 41 | + |
| 42 | + type = lib.types.submodule { |
| 43 | + options.file = lib.mkOption { |
| 44 | + type = lib.types.path; |
| 45 | + description = '' |
| 46 | + Path to a file containing the authentication token. |
| 47 | + ''; |
| 48 | + }; |
| 49 | + }; |
| 50 | + }; |
| 51 | + }; |
| 52 | + }; |
| 53 | + |
| 54 | + signingKeyFile = lib.mkOption { |
| 55 | + type = lib.types.nullOr lib.types.path; |
| 56 | + default = null; |
| 57 | + visible = false; |
| 58 | + description = "Cachix signing key"; |
| 59 | + }; |
| 60 | + |
| 61 | + authTokenFile = lib.mkOption { |
| 62 | + type = lib.types.nullOr lib.types.path; |
| 63 | + default = null; |
| 64 | + visible = false; |
| 65 | + description = "Cachix auth token"; |
| 66 | + }; |
| 67 | + }; |
| 68 | + |
| 69 | + config = lib.mkIf cfg.cachix.enable { |
| 70 | + services.buildbot-nix.master.cachix.auth = |
| 71 | + lib.mkIf (cfg.cachix.authTokenFile != null || cfg.cachix.signingKeyFile != null) |
| 72 | + ( |
| 73 | + if (cfg.cachix.authTokenFile != null) then |
| 74 | + lib.warn |
| 75 | + "Obsolete option `services.buildbot-nix.master.cachix.authTokenFile' is used. It was renamed to `services.buildbot-nix.master.cachix.auth.authToken.file'." |
| 76 | + { authToken.file = cfg.cachix.authTokenFile; } |
| 77 | + else if (cfg.cachix.signingKeyFile != null) then |
| 78 | + lib.warn |
| 79 | + "Obsolete option `services.buildbot-nix.master.cachix.signingKeyFile' is used. It was renamed to `services.buildbot-nix.master.cachix.auth.signingKey.file'." |
| 80 | + { signingKey.file = cfg.cachix.signingKeyFile; } |
| 81 | + else |
| 82 | + throw "Impossible, guarded by mkIf." |
| 83 | + ); |
| 84 | + |
| 85 | + assertions = [ |
| 86 | + { |
| 87 | + assertion = |
| 88 | + let |
| 89 | + isNull = x: x == null; |
| 90 | + in |
| 91 | + isNull cfg.cachix.authTokenFile && isNull cfg.cachix.signingKeyFile |
| 92 | + || isNull cfg.cachix.authTokenFile && cfg.cachix.enable |
| 93 | + || isNull cfg.cachix.signingKeyFile && cfg.cachix.enable; |
| 94 | + message = '' |
| 95 | + The semantics of `options.services.buildbot-nix.master.cachix` recently changed |
| 96 | + slightly, the option `name` is no longer null-able. To enable Cachix support |
| 97 | + use `services.buildbot-nix.master.cachix.enable = true`. |
| 98 | +
|
| 99 | + Furthermore, the options `services.buildbot-nix.master.cachix.authTokenFile` and |
| 100 | + `services.buildbot-nix.master.cachix.signingKeyFile` were renamed to |
| 101 | + `services.buildbot-nix.master.cachix.auth.authToken.file` and |
| 102 | + `services.buildbot-nix.master.cachix.auth.signingKey.file` respectively. |
| 103 | + ''; |
| 104 | + } |
| 105 | + ]; |
| 106 | + |
| 107 | + systemd.services.buildbot-master.serviceConfig.LoadCredential = |
| 108 | + lib.optional ( |
| 109 | + cfg.cachix.auth ? "signingKey" |
| 110 | + ) "cachix-signing-key:${builtins.toString cfg.cachix.auth.signingKey.file}" |
| 111 | + ++ lib.optional ( |
| 112 | + cfg.cachix.auth ? "authToken" |
| 113 | + ) "cachix-auth-token:${builtins.toString cfg.cachix.auth.authToken.file}"; |
| 114 | + |
| 115 | + services.buildbot-nix.master.postBuildSteps = [ |
| 116 | + { |
| 117 | + name = "Upload cachix"; |
| 118 | + environment = lib.mkMerge [ |
| 119 | + (lib.optionalAttrs (cfg.cachix.auth ? "signingKey") { |
| 120 | + CACHIX_SIGNING_KEY = bb-lib.interpolate "%(secret:cachix-signing-key)s"; |
| 121 | + }) |
| 122 | + (lib.optionalAttrs (cfg.cachix.auth ? "authToken") { |
| 123 | + CACHIX_AUTH_TOKEN = bb-lib.interpolate "%(secret:cachix-auth-token)s"; |
| 124 | + }) |
| 125 | + ]; |
| 126 | + command = [ |
| 127 | + "cachix" # note that this is the cachix from the worker's $PATH |
| 128 | + "push" |
| 129 | + cfg.cachix.name |
| 130 | + (bb-lib.interpolate "result-%(prop:attr)s") |
| 131 | + ]; |
| 132 | + } |
| 133 | + ]; |
| 134 | + }; |
| 135 | +} |
0 commit comments