|
8 | 8 | cfg = config.services.buildbot-nix.master;
|
9 | 9 | inherit (config.services.buildbot-nix) packages;
|
10 | 10 | inherit (lib) mkRemovedOptionModule mkRenamedOptionModule;
|
| 11 | + bb-lib = import ./lib.nix; |
11 | 12 |
|
12 | 13 | interpolateType = lib.mkOptionType {
|
13 | 14 | name = "interpolate";
|
|
685 | 686 | isSystemUser = true;
|
686 | 687 | };
|
687 | 688 |
|
688 |
| - services.buildbot-nix.master.cachix.auth = |
689 |
| - lib.mkIf (cfg.cachix.authTokenFile != null || cfg.cachix.signingKeyFile != null) |
690 |
| - ( |
691 |
| - if (cfg.cachix.authTokenFile != null) then |
692 |
| - lib.warn |
693 |
| - "Obsolete option `services.buildbot-nix.master.cachix.authTokenFile' is used. It was renamed to `services.buildbot-nix.master.cachix.auth.authToken.file'." |
694 |
| - { authToken.file = cfg.cachix.authTokenFile; } |
695 |
| - else if (cfg.cachix.signingKeyFile != null) then |
696 |
| - lib.warn |
697 |
| - "Obsolete option `services.buildbot-nix.master.cachix.signingKeyFile' is used. It was renamed to `services.buildbot-nix.master.cachix.auth.signingKey.file'." |
698 |
| - { signingKey.file = cfg.cachix.signingKeyFile; } |
699 |
| - else |
700 |
| - throw "Impossible, guarded by mkIf." |
701 |
| - ); |
702 |
| - |
703 | 689 | assertions = [
|
704 |
| - { |
705 |
| - assertion = |
706 |
| - let |
707 |
| - isNull = x: x == null; |
708 |
| - in |
709 |
| - isNull cfg.cachix.authTokenFile && isNull cfg.cachix.signingKeyFile |
710 |
| - || isNull cfg.cachix.authTokenFile && cfg.cachix.enable |
711 |
| - || isNull cfg.cachix.signingKeyFile && cfg.cachix.enable; |
712 |
| - message = '' |
713 |
| - The semantics of `options.services.buildbot-nix.master.cachix` recently changed |
714 |
| - slightly, the option `name` is no longer null-able. To enable Cachix support |
715 |
| - use `services.buildbot-nix.master.cachix.enable = true`. |
716 |
| -
|
717 |
| - Furthermore, the options `services.buildbot-nix.master.cachix.authTokenFile` and |
718 |
| - `services.buildbot-nix.master.cachix.signingKeyFile` were renamed to |
719 |
| - `services.buildbot-nix.master.cachix.auth.authToken.file` and |
720 |
| - `services.buildbot-nix.master.cachix.auth.signingKey.file` respectively. |
721 |
| - ''; |
722 |
| - } |
723 | 690 | {
|
724 | 691 | assertion = lib.versionAtLeast packages.buildbot.version "4.0.0";
|
725 | 692 | message = ''
|
|
780 | 747 | (pkgs.formats.json { }).generate "buildbot-nix-config.json" {
|
781 | 748 | db_url = cfg.dbUrl;
|
782 | 749 | auth_backend = cfg.authBackend;
|
783 |
| - cachix = |
784 |
| - if !cfg.cachix.enable then |
785 |
| - null |
786 |
| - else |
787 |
| - { |
788 |
| - name = cfg.cachix.name; |
789 |
| - signing_key_file = if cfg.cachix.auth ? "signingKey" then "cachix-signing-key" else null; |
790 |
| - auth_token_file = if cfg.cachix.auth ? "authToken" then "cachix-auth-token" else null; |
791 |
| - }; |
792 | 750 | gitea =
|
793 | 751 | if !cfg.gitea.enable then
|
794 | 752 | null
|
|
902 | 860 | )
|
903 | 861 | ++ lib.optional (cfg.authBackend == "gitea") "gitea-oauth-secret:${cfg.gitea.oauthSecretFile}"
|
904 | 862 | ++ lib.optional (cfg.authBackend == "github") "github-oauth-secret:${cfg.github.oauthSecretFile}"
|
905 |
| - ++ lib.optional ( |
906 |
| - cfg.cachix.enable && cfg.cachix.auth ? "signingKey" |
907 |
| - ) "cachix-signing-key:${builtins.toString cfg.cachix.auth.signingKey.file}" |
908 |
| - ++ lib.optional ( |
909 |
| - cfg.cachix.enable && cfg.cachix.auth ? "authToken" |
910 |
| - ) "cachix-auth-token:${builtins.toString cfg.cachix.auth.authToken.file}" |
911 | 863 | ++ lib.optionals cfg.gitea.enable [
|
912 | 864 | "gitea-token:${cfg.gitea.tokenFile}"
|
913 | 865 | "gitea-webhook-secret:${cfg.gitea.webhookSecretFile}"
|
|
1031 | 983 | '';
|
1032 | 984 | };
|
1033 | 985 | })
|
| 986 | + (lib.mkIf cfg.cachix.enable { |
| 987 | + services.buildbot-nix.master.cachix.auth = |
| 988 | + lib.mkIf (cfg.cachix.authTokenFile != null || cfg.cachix.signingKeyFile != null) |
| 989 | + ( |
| 990 | + if (cfg.cachix.authTokenFile != null) then |
| 991 | + lib.warn |
| 992 | + "Obsolete option `services.buildbot-nix.master.cachix.authTokenFile' is used. It was renamed to `services.buildbot-nix.master.cachix.auth.authToken.file'." |
| 993 | + { authToken.file = cfg.cachix.authTokenFile; } |
| 994 | + else if (cfg.cachix.signingKeyFile != null) then |
| 995 | + lib.warn |
| 996 | + "Obsolete option `services.buildbot-nix.master.cachix.signingKeyFile' is used. It was renamed to `services.buildbot-nix.master.cachix.auth.signingKey.file'." |
| 997 | + { signingKey.file = cfg.cachix.signingKeyFile; } |
| 998 | + else |
| 999 | + throw "Impossible, guarded by mkIf." |
| 1000 | + ); |
| 1001 | + |
| 1002 | + assertions = [ |
| 1003 | + { |
| 1004 | + assertion = |
| 1005 | + let |
| 1006 | + isNull = x: x == null; |
| 1007 | + in |
| 1008 | + isNull cfg.cachix.authTokenFile && isNull cfg.cachix.signingKeyFile |
| 1009 | + || isNull cfg.cachix.authTokenFile && cfg.cachix.enable |
| 1010 | + || isNull cfg.cachix.signingKeyFile && cfg.cachix.enable; |
| 1011 | + message = '' |
| 1012 | + The semantics of `options.services.buildbot-nix.master.cachix` recently changed |
| 1013 | + slightly, the option `name` is no longer null-able. To enable Cachix support |
| 1014 | + use `services.buildbot-nix.master.cachix.enable = true`. |
| 1015 | +
|
| 1016 | + Furthermore, the options `services.buildbot-nix.master.cachix.authTokenFile` and |
| 1017 | + `services.buildbot-nix.master.cachix.signingKeyFile` were renamed to |
| 1018 | + `services.buildbot-nix.master.cachix.auth.authToken.file` and |
| 1019 | + `services.buildbot-nix.master.cachix.auth.signingKey.file` respectively. |
| 1020 | + ''; |
| 1021 | + } |
| 1022 | + ]; |
| 1023 | + |
| 1024 | + systemd.services.buildbot-master.serviceConfig.LoadCredential = |
| 1025 | + lib.optional ( |
| 1026 | + cfg.cachix.auth ? "signingKey" |
| 1027 | + ) "cachix-signing-key:${builtins.toString cfg.cachix.auth.signingKey.file}" |
| 1028 | + ++ lib.optional ( |
| 1029 | + cfg.cachix.auth ? "authToken" |
| 1030 | + ) "cachix-auth-token:${builtins.toString cfg.cachix.auth.authToken.file}"; |
| 1031 | + |
| 1032 | + services.buildbot-nix.master.postBuildSteps = [ |
| 1033 | + { |
| 1034 | + name = "Upload cachix"; |
| 1035 | + environment = { |
| 1036 | + CACHIX_SIGNING_KEY = bb-lib.interpolate "%(secret:cachix-signing-key)s"; |
| 1037 | + CACHIX_AUTH_TOKEN = bb-lib.interpolate "%(secret:cachix-auth-token)s"; |
| 1038 | + }; |
| 1039 | + command = [ |
| 1040 | + "cachix" # note that this is the cachix from the worker's $PATH |
| 1041 | + "push" |
| 1042 | + cfg.cachix.name |
| 1043 | + (bb-lib.interpolate "result-%(prop:attr)s") |
| 1044 | + ]; |
| 1045 | + } |
| 1046 | + ]; |
| 1047 | + }) |
1034 | 1048 | ];
|
1035 | 1049 | }
|
0 commit comments