Skip to content

Commit 6b31252

Browse files
committed
loptland: modularize config a little by pulling out modules for gitea-runner and hydra
1 parent 71e8eab commit 6b31252

File tree

3 files changed

+230
-54
lines changed

3 files changed

+230
-54
lines changed
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
{
2+
lib,
3+
config,
4+
namespace,
5+
pkgs,
6+
...
7+
}:
8+
with lib.${namespace};
9+
let
10+
cfg = config.${namespace}.services.gitea-runner;
11+
inherit (lib) mkIf mkOption mkEnableOption;
12+
inherit (lib.types)
13+
attrsOf
14+
package
15+
path
16+
submodule
17+
str
18+
;
19+
in
20+
{
21+
options.${namespace}.services.gitea-runner = {
22+
enable = mkEnableOption "Enable gitea/forgejo runner";
23+
git-url = mkOption {
24+
type = str;
25+
default = "https://git.christophhollizeck.dev";
26+
};
27+
sopsFile = mkOption {
28+
type = path;
29+
default = lib.snowfall.fs.get-file "secrets/secrets.yaml";
30+
description = "SecretFile";
31+
};
32+
runner-package = mkOption {
33+
type = package;
34+
default = pkgs.forgejo-actions-runner;
35+
description = "Which runner to use Gitea/Forgjo";
36+
};
37+
## taken from nixos/modules/services/continuous-integration/gitea-actions-runner.nix
38+
runner-instances = mkOption {
39+
default = { };
40+
description = ''
41+
Gitea Actions Runner instances.
42+
'';
43+
type = attrsOf (submodule {
44+
options = {
45+
enable = mkEnableOption "Gitea Actions Runner instance";
46+
name = mkOption {
47+
type = str;
48+
example = literalExpression "config.networking.hostName";
49+
description = ''
50+
The name identifying the runner instance towards the Gitea/Forgejo instance.
51+
'';
52+
};
53+
url = mkOption {
54+
type = str;
55+
example = "https://forge.example.com";
56+
description = ''
57+
Base URL of your Gitea/Forgejo instance.
58+
'';
59+
};
60+
tokenFile = mkOption {
61+
type = nullOr (either str path);
62+
default = null;
63+
description = ''
64+
Path to an environment file, containing the `TOKEN` environment
65+
variable, that holds a token to register at the configured
66+
Gitea/Forgejo instance.
67+
'';
68+
};
69+
labels = mkOption {
70+
type = listOf str;
71+
example = literalExpression ''
72+
[
73+
# provide a debian base with nodejs for actions
74+
"debian-latest:docker://node:18-bullseye"
75+
# fake the ubuntu name, because node provides no ubuntu builds
76+
"ubuntu-latest:docker://node:18-bullseye"
77+
# provide native execution on the host
78+
#"native:host"
79+
]
80+
'';
81+
description = ''
82+
Labels used to map jobs to their runtime environment. Changing these
83+
labels currently requires a new registration token.
84+
85+
Many common actions require bash, git and nodejs, as well as a filesystem
86+
that follows the filesystem hierarchy standard.
87+
'';
88+
};
89+
settings = mkOption {
90+
description = ''
91+
Configuration for `act_runner daemon`.
92+
See https://gitea.com/gitea/act_runner/src/branch/main/internal/pkg/config/config.example.yaml for an example configuration
93+
'';
94+
95+
type = types.submodule {
96+
freeformType = settingsFormat.type;
97+
};
98+
99+
default = { };
100+
};
101+
102+
hostPackages = mkOption {
103+
type = listOf package;
104+
default = with pkgs; [
105+
bash
106+
coreutils
107+
curl
108+
gawk
109+
gitMinimal
110+
gnused
111+
nodejs
112+
wget
113+
];
114+
defaultText = literalExpression ''
115+
with pkgs; [
116+
bash
117+
coreutils
118+
curl
119+
gawk
120+
gitMinimal
121+
gnused
122+
nodejs
123+
wget
124+
]
125+
'';
126+
description = ''
127+
List of packages, that are available to actions, when the runner is configured
128+
with a host execution label.
129+
'';
130+
};
131+
};
132+
});
133+
};
134+
};
135+
136+
config = mkIf cfg.enable {
137+
sops = {
138+
secrets = {
139+
"forgejo/runner/token" = {
140+
inherit (cfg) sopsFile;
141+
};
142+
};
143+
};
144+
145+
services.gitea-actions-runner = {
146+
package = cfg.runner-package;
147+
instances = {
148+
native = {
149+
enable = true;
150+
name = "monolith";
151+
url = cfg.git-url;
152+
tokenFile = config.sops.secrets."forgejo/runner/token".path;
153+
labels = [
154+
"native:host"
155+
];
156+
hostPackages = with pkgs; [
157+
bash
158+
coreutils
159+
curl
160+
gawk
161+
gitMinimal
162+
gnused
163+
nodejs
164+
wget
165+
lix
166+
];
167+
settings = {
168+
log.level = "info";
169+
runner = {
170+
capacity = 1;
171+
timeout = "3h";
172+
shutdown_timeout = "5s";
173+
fetch_timeout = "10s";
174+
fetch_inteval = "5s";
175+
};
176+
};
177+
};
178+
} // cfg.runner-instances;
179+
};
180+
181+
};
182+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
lib,
3+
config,
4+
namespace,
5+
...
6+
}:
7+
let
8+
cfg = config.${namespace}.services.hydra;
9+
inherit (lib) mkIf mkOption mkEnableOption;
10+
in
11+
{
12+
options.${namespace}.services.hydra = {
13+
enable = mkEnableOption "Enable Hydra CI";
14+
httpPort = mkOption {
15+
type = lib.types.int;
16+
default = 2000;
17+
description = "The path to host the http server on, relevant for nginx forwarding";
18+
};
19+
20+
enableCache = mkEnableOption "Enable cache using nix-server";
21+
};
22+
23+
config = mkIf cfg.enable {
24+
services.nix-serve = mkIf cfg.enableCache {
25+
enable = true;
26+
secretKeyFile = "/var/cache-priv-key.pem";
27+
};
28+
29+
services.hydra = {
30+
enable = true;
31+
hydraURL = "http://localhost:${toString cfg.httpPort}";
32+
port = cfg.httpPort;
33+
notificationSender = "hydra@localhost";
34+
useSubstitutes = true;
35+
};
36+
};
37+
}

systems/x86_64-linux/loptland/default.nix

Lines changed: 11 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ in
3535
"forgejo/mail/passwordHash" = {
3636
inherit sopsFile;
3737
};
38-
"forgejo/runner/token" = {
39-
inherit sopsFile;
40-
};
4138
};
4239
};
4340

@@ -55,7 +52,7 @@ in
5552
};
5653
};
5754

58-
"hydra.${domainName}" = {
55+
"hydra.${domainName}" = mkIf config.${namespace}.services.hydra.enable {
5956
forceSSL = cfg.enableAcme;
6057
useACMEHost = mkIf cfg.enableAcme domainName;
6158

@@ -78,7 +75,7 @@ in
7875
};
7976
};
8077

81-
"nixcache.${domainName}" = {
78+
"nixcache.${domainName}" = mkIf config.${namespace}.services.hydra.enableCache {
8279
forceSSL = cfg.enableAcme;
8380
useACMEHost = mkIf cfg.enableAcme domainName;
8481

@@ -180,60 +177,11 @@ in
180177
];
181178
};
182179

183-
services.nix-serve = {
184-
enable = true;
185-
secretKeyFile = "/var/cache-priv-key.pem";
186-
};
187-
188-
services.hydra = {
189-
enable = true;
190-
hydraURL = "http://localhost:${toString hydraPort}";
191-
port = hydraPort;
192-
notificationSender = "hydra@localhost";
193-
useSubstitutes = true;
194-
};
195-
196180
services.tailscale = {
197181
enable = true;
198182
useRoutingFeatures = "client";
199183
};
200184

201-
services.gitea-actions-runner = {
202-
package = pkgs.forgejo-actions-runner;
203-
instances = {
204-
native = {
205-
enable = true;
206-
name = "monolith";
207-
url = "https://git.${domainName}";
208-
tokenFile = config.sops.secrets."forgejo/runner/token".path;
209-
labels = [
210-
"native:host"
211-
];
212-
hostPackages = with pkgs; [
213-
bash
214-
coreutils
215-
curl
216-
gawk
217-
gitMinimal
218-
gnused
219-
nodejs
220-
wget
221-
lix
222-
];
223-
settings = {
224-
log.level = "info";
225-
runner = {
226-
capacity = 1;
227-
timeout = "3h";
228-
shutdown_timeout = "5s";
229-
fetch_timeout = "10s";
230-
fetch_inteval = "5s";
231-
};
232-
};
233-
};
234-
};
235-
};
236-
237185
networking.firewall.allowedTCPPorts = [
238186
forgejoPort
239187
80
@@ -251,6 +199,15 @@ in
251199
inherit sopsFile;
252200
};
253201
openssh = enabled;
202+
hydra = {
203+
enable = true;
204+
httpPort = hydraPort;
205+
enableCache = true;
206+
};
207+
gitea-runner = {
208+
enable = true;
209+
inherit sopsFile;
210+
};
254211
};
255212

256213
security = {

0 commit comments

Comments
 (0)