|
4 | 4 | ...
|
5 | 5 | }:
|
6 | 6 | let
|
7 |
| - inherit (lib) mkEnableOption mkOption types; |
| 7 | + cfg = config.secshell.gitea.woodpecker; |
| 8 | + inherit (lib) |
| 9 | + mkIf |
| 10 | + mkEnableOption |
| 11 | + mkOption |
| 12 | + types |
| 13 | + mkMerge |
| 14 | + mkAfter |
| 15 | + ; |
8 | 16 | mkDisableOption =
|
9 | 17 | name:
|
10 | 18 | mkEnableOption name
|
|
47 | 55 | };
|
48 | 56 | };
|
49 | 57 |
|
50 |
| - imports = [ |
51 |
| - ./woodpecker-server.nix |
52 |
| - ./woodpecker-agent.nix |
53 |
| - ]; |
| 58 | + config = mkIf (config.secshell.gitea.enable && cfg.enable) (mkMerge [ |
| 59 | + # base |
| 60 | + { |
| 61 | + sops = { |
| 62 | + secrets."woodpecker/secret" = { }; |
| 63 | + templates."woodpecker/environment-agent".content = '' |
| 64 | + WOODPECKER_AGENT_SECRET=${config.sops.placeholder."woodpecker/secret"} |
| 65 | + ''; |
| 66 | + }; |
| 67 | + } |
| 68 | + |
| 69 | + # server |
| 70 | + (mkIf cfg.enableServers { |
| 71 | + sops = { |
| 72 | + secrets = { |
| 73 | + "woodpecker/oidcClientId" = { }; |
| 74 | + "woodpecker/oidcSecret" = { }; |
| 75 | + }; |
| 76 | + templates."woodpecker/environment".content = mkAfter '' |
| 77 | + WOODPECKER_GITEA_CLIENT=${config.sops.placeholder."woodpecker/oidcClientId"} |
| 78 | + WOODPECKER_GITEA_SECRET=${config.sops.placeholder."woodpecker/oidcSecret"} |
| 79 | + ''; |
| 80 | + }; |
| 81 | + |
| 82 | + services = { |
| 83 | + woodpecker-server = { |
| 84 | + enable = true; |
| 85 | + environment = { |
| 86 | + WOODPECKER_HOST = "https://${cfg.domain}"; |
| 87 | + WOODPECKER_SERVER_ADDR = "127.0.0.1:${toString cfg.internal_port}"; |
| 88 | + WOODPECKER_GRPC_ADDR = "${cfg.grpc_addr}:${toString cfg.grpc_port}"; |
| 89 | + WOODPECKER_OPEN = "true"; |
| 90 | + |
| 91 | + WOODPECKER_GITEA = "true"; |
| 92 | + WOODPECKER_GITEA_URL = config.services.gitea.settings.server.ROOT_URL; |
| 93 | + WOODPECKER_AUTHENTICATE_PUBLIC_REPOS = "true"; |
| 94 | + }; |
| 95 | + environmentFile = config.sops.templates."woodpecker/environment".path; |
| 96 | + }; |
| 97 | + |
| 98 | + nginx = lib.mkIf cfg.enableServer { |
| 99 | + enable = true; |
| 100 | + virtualHosts."${toString cfg.domain}" = { |
| 101 | + locations = { |
| 102 | + "/".proxyPass = "http://127.0.0.1:${toString cfg.internal_port}"; |
| 103 | + }; |
| 104 | + serverName = toString cfg.domain; |
| 105 | + |
| 106 | + # use ACME DNS-01 challenge |
| 107 | + useACMEHost = toString cfg.domain; |
| 108 | + forceSSL = true; |
| 109 | + }; |
| 110 | + }; |
| 111 | + }; |
| 112 | + security.acme.certs."${toString cfg.domain}" = { }; |
| 113 | + }) |
| 114 | + |
| 115 | + # agent |
| 116 | + (mkIf cfg.enableAgent { |
| 117 | + services.woodpecker-agents.agents.docker = { |
| 118 | + enable = true; |
| 119 | + extraGroups = [ "podman" ]; |
| 120 | + environment = { |
| 121 | + WOODPECKER_SERVER = "${toString cfg.domain}:${toString cfg.grpc_port}"; |
| 122 | + |
| 123 | + WOODPECKER_MAX_WORKFLOWS = "4"; |
| 124 | + |
| 125 | + WOODPECKER_BACKEND = "docker"; |
| 126 | + DOCKER_HOST = "unix:///run/podman/podman.sock"; |
| 127 | + }; |
| 128 | + environmentFile = [ config.sops.templates."woodpecker/environment-agent".path ]; |
| 129 | + }; |
| 130 | + |
| 131 | + virtualisation.podman = { |
| 132 | + enable = true; |
| 133 | + defaultNetwork.settings = { |
| 134 | + dns_enabled = true; |
| 135 | + }; |
| 136 | + dockerCompat = true; |
| 137 | + }; |
| 138 | + |
| 139 | + # This is needed for podman to be able to talk over dns |
| 140 | + networking.firewall.interfaces."podman0" = { |
| 141 | + allowedUDPPorts = [ 53 ]; |
| 142 | + allowedTCPPorts = [ 53 ]; |
| 143 | + }; |
| 144 | + |
| 145 | + # Adjust runner service for nix usage |
| 146 | + systemd.services.woodpecker-agent-docker = { |
| 147 | + after = [ |
| 148 | + "podman.socket" |
| 149 | + ] |
| 150 | + ++ (lib.optionals cfg.enableServer [ |
| 151 | + "woodpecker-server.service" |
| 152 | + ]); |
| 153 | + # might break deployment |
| 154 | + restartIfChanged = false; |
| 155 | + serviceConfig = { |
| 156 | + BindPaths = [ "/run/podman/podman.sock" ]; |
| 157 | + }; |
| 158 | + }; |
| 159 | + }) |
| 160 | + ]); |
54 | 161 | }
|
0 commit comments