-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvm.nix
61 lines (52 loc) · 1.77 KB
/
vm.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{ pkgs, lib, config, ... }:
{
virtualisation.memorySize = 2048;
virtualisation.forwardPorts = [{
from = "host";
host.port = 8443;
guest.port = 443;
}];
virtualisation.graphics = false;
services.multi-packit = {
domain = lib.mkForce "localhost:8443";
};
vault.secrets = lib.mkForce {
github-oauth = {
key = "packit/githubauth/auth/githubclient";
path = "/var/secrets/github-oauth";
fields.PACKIT_GITHUB_CLIENT_ID = "id";
fields.PACKIT_GITHUB_CLIENT_SECRET = "secret";
format = "env";
};
};
users.motd = ''
Server is available at https://${config.services.multi-packit.domain}.
Use the 'Ctrl-A x' sequence or the `shutdown now` command to terminate the VM session.
'';
systemd.services."generate-secrets" =
let
packit-units = map (name: "packit-api-${name}.service") config.services.multi-packit.instances;
in
{
wants = [ "network-online.target" ];
after = [ "network-online.target" ];
wantedBy = [ "multi-user.target" "nginx.service" ] ++ packit-units;
before = [ "nginx.service" ] ++ packit-units;
serviceConfig.Type = "oneshot";
script = ''
mkdir -p /var/secrets
if [[ ! -f /var/secrets/packit.key ]]; then
${pkgs.openssl}/bin/openssl \
req -x509 -days 365 \
-subj "/CN=localhost" \
-newkey rsa:2048 -noenc \
-keyout /var/secrets/packit.key -out /var/secrets/packit.cert
chown nginx:nginx /var/secrets/packit.key
fi
if [[ -f /sys/firmware/qemu_fw_cfg/by_name/opt/vault-token/raw ]]; then
${lib.getExe config.vault.tool} --token-file /sys/firmware/qemu_fw_cfg/by_name/opt/vault-token/raw
fi
'';
};
services.getty.autologinUser = "root";
}