treewide: reformat everything else

This commit is contained in:
Ilya K 2024-08-09 18:46:56 +03:00
parent 306cc77e05
commit 514d43fd42
45 changed files with 1095 additions and 734 deletions

View file

@ -1,16 +1,17 @@
let let
keys = import ./ssh-keys.nix; keys = import ./ssh-keys.nix;
in { in
{
users.users.root.openssh.authorizedKeys.keys = users.users.root.openssh.authorizedKeys.keys =
keys.users.delroth ++ keys.users.delroth
keys.users.emilylange ++ ++ keys.users.emilylange
keys.users.hexchen ++ ++ keys.users.hexchen
keys.users.jade ++ ++ keys.users.jade
keys.users.janik ++ ++ keys.users.janik
keys.users.k900 ++ ++ keys.users.k900
keys.users.lukegb ++ ++ keys.users.lukegb
keys.users.maxine ++ ++ keys.users.maxine
keys.users.raito ++ ++ keys.users.raito
keys.users.thubrecht ++ ++ keys.users.thubrecht
keys.users.yuka; ++ keys.users.yuka;
} }

View file

@ -1,7 +1,6 @@
{ lib, pkgs, ... }: { { lib, pkgs, ... }:
imports = [ {
./known-ssh-keys.nix imports = [ ./known-ssh-keys.nix ];
];
nixpkgs.overlays = import ../overlays; nixpkgs.overlays = import ../overlays;
@ -36,7 +35,8 @@
services.journald.extraConfig = "SystemMaxUse=512M"; services.journald.extraConfig = "SystemMaxUse=512M";
boot.kernelParams = [ boot.kernelParams = [
"panic=30" "boot.panic_on_fail" "panic=30"
"boot.panic_on_fail"
]; ];
boot.kernel.sysctl = { boot.kernel.sysctl = {

View file

@ -3,9 +3,9 @@
{ {
nix.settings.allowed-users = [ "root" ]; nix.settings.allowed-users = [ "root" ];
boot.specialFileSystems = lib.mkIf (!config.security.rtkit.enable && !config.security.polkit.enable) { boot.specialFileSystems = lib.mkIf (
"/proc".options = [ "hidepid=2" ]; !config.security.rtkit.enable && !config.security.polkit.enable
}; ) { "/proc".options = [ "hidepid=2" ]; };
boot.kernel.sysctl."kernel.dmesg_restrict" = 1; boot.kernel.sysctl."kernel.dmesg_restrict" = 1;
@ -14,9 +14,7 @@
settings.KbdInteractiveAuthentication = false; settings.KbdInteractiveAuthentication = false;
# prevents mutable /home/$user/.ssh/authorized_keys from being loaded to ensure that all user keys are config managed # prevents mutable /home/$user/.ssh/authorized_keys from being loaded to ensure that all user keys are config managed
authorizedKeysFiles = lib.mkForce [ authorizedKeysFiles = lib.mkForce [ "/etc/ssh/authorized_keys.d/%u" ];
"/etc/ssh/authorized_keys.d/%u"
];
}; };
users.mutableUsers = false; users.mutableUsers = false;

View file

@ -11,12 +11,33 @@ in
services.nginx = { services.nginx = {
# IPv6-only server # IPv6-only server
defaultListen = [ defaultListen = [
{ addr = "[::0]"; proxyProtocol = true; port = 444; ssl = true; } {
{ addr = "[::0]"; port = 443; ssl = true; } addr = "[::0]";
{ addr = "[::0]"; port = 80; ssl = false; } proxyProtocol = true;
port = 444;
ssl = true;
}
{
addr = "[::0]";
port = 443;
ssl = true;
}
{
addr = "[::0]";
port = 80;
ssl = false;
}
# Private networking # Private networking
{ addr = "127.0.0.1"; port = 80; ssl = false; } {
{ addr = "[::1]"; port = 80; ssl = false; } addr = "127.0.0.1";
port = 80;
ssl = false;
}
{
addr = "[::1]";
port = 80;
ssl = false;
}
]; ];
appendHttpConfig = '' appendHttpConfig = ''

View file

@ -1,7 +1,12 @@
{ lib, config, ... }: { lib, config, ... }:
let let
cfg = config.bagel.hardware.raito-vm; cfg = config.bagel.hardware.raito-vm;
inherit (lib) mkEnableOption mkIf mkOption types; inherit (lib)
mkEnableOption
mkIf
mkOption
types
;
in in
{ {
options.bagel.hardware.raito-vm = { options.bagel.hardware.raito-vm = {

View file

@ -23,7 +23,9 @@
users = { users = {
delroth = [ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAII3tjB4KYDok3KlWxdBp/yEmqhhmybd+w0VO4xUwLKKV" ]; delroth = [ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAII3tjB4KYDok3KlWxdBp/yEmqhhmybd+w0VO4xUwLKKV" ];
emilylange = [ "no-touch-required sk-ssh-ed25519@openssh.com AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29tAAAAIL7jgq3i+N3gVJhs4shm7Kmw6dIocs2OuR0GBMG1RxfKAAAABHNzaDo=" ]; emilylange = [
"no-touch-required sk-ssh-ed25519@openssh.com AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29tAAAAIL7jgq3i+N3gVJhs4shm7Kmw6dIocs2OuR0GBMG1RxfKAAAABHNzaDo="
];
hexchen = [ hexchen = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINJ0tCxsEilAzV6LaNpUpcjzyEn4ptw8kFz3R+Z3YjEF hexchen@backup" "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINJ0tCxsEilAzV6LaNpUpcjzyEn4ptw8kFz3R+Z3YjEF hexchen@backup"
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDI3T1eFS77URHZ/HVWkMOqx7W1U54zJtn9C7QWsHOtyH72i/4EVj8SxYqLllElh1kuKUXSUipPeEzVsipFVvfH0wEuTDgFffiSQ3a8lfUgdEBuoySwceEoPgc5deapkOmiDIDeeWlrRe3nqspLRrSWU1DirMxoFPbwqJXRvpl6qJPxRg+2IolDcXlZ6yxB4Vv48vzRfVzZNUz7Pjmy2ebU8PbDoFWL/S3m7yOzQpv3L7KYBz7+rkjuF3AU2vy6CAfIySkVpspZZLtkTGCIJF228ev0e8NvhuN6ZnjzXxVTQOy32HCdPdbBbicu0uHfZ5O7JX9DjGd8kk1r2dnZwwy/ hexchen@yubi5" "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDI3T1eFS77URHZ/HVWkMOqx7W1U54zJtn9C7QWsHOtyH72i/4EVj8SxYqLllElh1kuKUXSUipPeEzVsipFVvfH0wEuTDgFffiSQ3a8lfUgdEBuoySwceEoPgc5deapkOmiDIDeeWlrRe3nqspLRrSWU1DirMxoFPbwqJXRvpl6qJPxRg+2IolDcXlZ6yxB4Vv48vzRfVzZNUz7Pjmy2ebU8PbDoFWL/S3m7yOzQpv3L7KYBz7+rkjuF3AU2vy6CAfIySkVpspZZLtkTGCIJF228ev0e8NvhuN6ZnjzXxVTQOy32HCdPdbBbicu0uHfZ5O7JX9DjGd8kk1r2dnZwwy/ hexchen@yubi5"
@ -40,7 +42,9 @@
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBLZxVITpJ8xbiCa/u2gjSSIupeiqOnRh+8tFIoVhCON" "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBLZxVITpJ8xbiCa/u2gjSSIupeiqOnRh+8tFIoVhCON"
]; ];
k900 = [ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOi9vgVGs+S5kEsUqHPvyMMh1Q9gqL4TcbHoe5d73tun" ]; k900 = [ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOi9vgVGs+S5kEsUqHPvyMMh1Q9gqL4TcbHoe5d73tun" ];
lukegb = [ ''cert-authority,principals="lukegb" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEqNOwlR7Qa8cbGpDfSCOweDPbAGQOZIcoRgh6s/J8DR'' ]; lukegb = [
''cert-authority,principals="lukegb" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEqNOwlR7Qa8cbGpDfSCOweDPbAGQOZIcoRgh6s/J8DR''
];
maxine = [ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILpWQfhNFdrxMTP/1DwBVuk49f3df9iH7Tbdu8ltIKjr" ]; maxine = [ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILpWQfhNFdrxMTP/1DwBVuk49f3df9iH7Tbdu8ltIKjr" ];
raito = [ raito = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICaw9ihTG7ucB8P38XdalEWev8+q96e2yNm4B+/I9IJp" "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICaw9ihTG7ucB8P38XdalEWev8+q96e2yNm4B+/I9IJp"
@ -49,6 +53,8 @@
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKiXXYkhRh+s7ixZ8rvG8ntIqd6FELQ9hh7HoaHQJRPU" "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKiXXYkhRh+s7ixZ8rvG8ntIqd6FELQ9hh7HoaHQJRPU"
]; ];
thubrecht = [ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPM1jpXR7BWQa7Sed7ii3SbvIPRRlKb3G91qC0vOwfJn" ]; thubrecht = [ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPM1jpXR7BWQa7Sed7ii3SbvIPRRlKb3G91qC0vOwfJn" ];
yuka = [ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKath4/fDnlv/4fzxkPrQN1ttmoPRNu/m9bEtdPJBDfY cardno:16_933_242" ]; yuka = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKath4/fDnlv/4fzxkPrQN1ttmoPRNu/m9bEtdPJBDfY cardno:16_933_242"
];
}; };
} }

View file

@ -1,4 +1,9 @@
{ pkgs, config, lib, ... }: {
pkgs,
config,
lib,
...
}:
let let
inherit (lib) mkIf mkEnableOption; inherit (lib) mkIf mkEnableOption;
cfg = config.bagel.sysadmin; cfg = config.bagel.sysadmin;

View file

@ -1,4 +1,10 @@
{ lib, pkgs, config, ... }: { {
lib,
pkgs,
config,
...
}:
{
users.defaultUserShell = pkgs.zsh; users.defaultUserShell = pkgs.zsh;
programs.zsh = { programs.zsh = {
enable = true; enable = true;

View file

@ -9,7 +9,11 @@
boot.specialFileSystems = lib.mkForce { boot.specialFileSystems = lib.mkForce {
"/run/wrappers" = { "/run/wrappers" = {
fsType = "tmpfs"; fsType = "tmpfs";
options = [ "nodev" "mode=755" "size=${config.security.wrapperDirSize}" ]; options = [
"nodev"
"mode=755"
"size=${config.security.wrapperDirSize}"
];
}; };
}; };
@ -24,13 +28,22 @@
nameservers = [ "2001:4860:4860::8844" ]; nameservers = [ "2001:4860:4860::8844" ];
interfaces.host0.ipv6.addresses = [ interfaces.host0.ipv6.addresses = [
{ address = "2001:bc8:38ee:100:100::1"; prefixLength = 64; } {
address = "2001:bc8:38ee:100:100::1";
prefixLength = 64;
}
]; ];
interfaces.host1.ipv4.addresses = [ interfaces.host1.ipv4.addresses = [
{ address = "172.16.100.2"; prefixLength = 24; } {
address = "172.16.100.2";
prefixLength = 24;
}
]; ];
defaultGateway = { address = "172.16.100.1"; interface = "host1"; }; defaultGateway = {
address = "172.16.100.1";
interface = "host1";
};
firewall.allowPing = true; firewall.allowPing = true;
}; };

View file

@ -32,9 +32,7 @@
bagel.services.gerrit = { bagel.services.gerrit = {
enable = true; enable = true;
domains = [ domains = [ "cl.forkos.org" ];
"cl.forkos.org"
];
canonicalDomain = "cl.forkos.org"; canonicalDomain = "cl.forkos.org";
data = "/gerrit-data"; data = "/gerrit-data";
}; };
@ -47,11 +45,23 @@
}; };
bagel.nixpkgs.one-way-sync = bagel.nixpkgs.one-way-sync =
let let
mkNixpkgsJob = { timer, fromRefspec, localRefspec ? fromRefspec }: { mkNixpkgsJob =
{
timer,
fromRefspec,
localRefspec ? fromRefspec,
}:
{
fromUri = "https://github.com/NixOS/nixpkgs"; fromUri = "https://github.com/NixOS/nixpkgs";
inherit fromRefspec localRefspec timer; inherit fromRefspec localRefspec timer;
}; };
mkLocalJob = { timer, fromRefspec, localRefspec }: { mkLocalJob =
{
timer,
fromRefspec,
localRefspec,
}:
{
fromUri = "https://cl.forkos.org/nixpkgs"; fromUri = "https://cl.forkos.org/nixpkgs";
inherit fromRefspec localRefspec timer; inherit fromRefspec localRefspec timer;
}; };

View file

@ -27,9 +27,7 @@ in
# Add one additional IPv6, so we can have both OpenSSH and # Add one additional IPv6, so we can have both OpenSSH and
# Forgejo's built-in server bind on port :22. # Forgejo's built-in server bind on port :22.
systemd.network.networks."10-wan".networkConfig.Address = [ "${ipv6.openssh}/64" ]; systemd.network.networks."10-wan".networkConfig.Address = [ "${ipv6.openssh}/64" ];
services.openssh.listenAddresses = [{ services.openssh.listenAddresses = [ { addr = "[${ipv6.openssh}]"; } ];
addr = "[${ipv6.openssh}]";
}];
# Defaults to network.target, but networkd may take a while to settle and set up # Defaults to network.target, but networkd may take a while to settle and set up
# the required (additional) IPv6 address, leading to sshd to not being able to # the required (additional) IPv6 address, leading to sshd to not being able to
# bind to the requested IP, crashing 5 times and running into the default # bind to the requested IP, crashing 5 times and running into the default

View file

@ -27,9 +27,7 @@
bagel.services.grapevine.enable = true; bagel.services.grapevine.enable = true;
bagel.services.hookshot = { bagel.services.hookshot = {
enable = true; enable = true;
admins = [ admins = [ "@k900:0upti.me" ];
"@k900:0upti.me"
];
}; };
i18n.defaultLocale = "fr_FR.UTF-8"; i18n.defaultLocale = "fr_FR.UTF-8";

View file

@ -1,23 +1,27 @@
{ pkgs, lib, ... }: { pkgs, lib, ... }:
{ {
imports = [ imports = [ ./netboot.nix ];
./netboot.nix
];
###### Hardware ###### ###### Hardware ######
boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "ehci_pci" "sd_mod" "sdhci_pci" ]; boot.initrd.availableKernelModules = [
"xhci_pci"
"ahci"
"ehci_pci"
"sd_mod"
"sdhci_pci"
];
boot.kernelModules = [ "kvm-amd" ]; boot.kernelModules = [ "kvm-amd" ];
boot.loader.grub.device = "/dev/sda"; boot.loader.grub.device = "/dev/sda";
fileSystems."/" = fileSystems."/" = {
{ device = "/dev/disk/by-uuid/58688a5c-e3ce-4868-804b-4e34d1370f36"; device = "/dev/disk/by-uuid/58688a5c-e3ce-4868-804b-4e34d1370f36";
fsType = "f2fs"; fsType = "f2fs";
}; };
fileSystems."/boot" = fileSystems."/boot" = {
{ device = "/dev/disk/by-uuid/38caa628-3b6d-4fb4-8767-beee09a196a6"; device = "/dev/disk/by-uuid/38caa628-3b6d-4fb4-8767-beee09a196a6";
fsType = "ext2"; fsType = "ext2";
}; };
@ -65,7 +69,8 @@
}; };
}; };
}; };
networks = { networks =
{
"40-enp1s0" = { "40-enp1s0" = {
name = "enp1s0"; name = "enp1s0";
bond = [ "uplink" ]; bond = [ "uplink" ];
@ -82,12 +87,18 @@
name = "enp4s0"; name = "enp4s0";
bond = [ "oob" ]; bond = [ "oob" ];
}; };
} // lib.listToAttrs (map (x: lib.nameValuePair "40-bmc${toString x}" { }
// lib.listToAttrs (
map (
x:
lib.nameValuePair "40-bmc${toString x}" {
name = "bmc${toString x}"; name = "bmc${toString x}";
address = [ "192.168.1.${toString (x * 4 + 1)}/30" ]; address = [ "192.168.1.${toString (x * 4 + 1)}/30" ];
#address = [ "192.168.${toString x}.1/24" ]; #address = [ "192.168.${toString x}.1/24" ];
networkConfig.DHCPServer = true; networkConfig.DHCPServer = true;
}) (lib.genList lib.id 12)); }
) (lib.genList lib.id 12)
);
}; };
networking.nftables.enable = true; networking.nftables.enable = true;
@ -95,10 +106,15 @@
iifname { "bmc*" } meta nfproto ipv4 udp dport 67 accept comment "DHCP server" iifname { "bmc*" } meta nfproto ipv4 udp dport 67 accept comment "DHCP server"
''; '';
networking.vlans = lib.listToAttrs (map (x: lib.nameValuePair "bmc${toString x}" { networking.vlans = lib.listToAttrs (
map (
x:
lib.nameValuePair "bmc${toString x}" {
interface = "oob"; interface = "oob";
id = 101 + x; id = 101 + x;
}) (lib.genList lib.id 12)); }
) (lib.genList lib.id 12)
);
networking.interfaces = { networking.interfaces = {
uplink = { uplink = {
@ -111,7 +127,10 @@
}; };
}; };
networking.defaultGateway6 = { interface = "uplink"; address = "2a01:584:11::1"; }; networking.defaultGateway6 = {
interface = "uplink";
address = "2a01:584:11::1";
};
networking.hostName = "vpn-gw"; networking.hostName = "vpn-gw";
networking.domain = "wob01.infra.forkos.org"; networking.domain = "wob01.infra.forkos.org";

View file

@ -1,4 +1,11 @@
{ config, lib, pkgs, nodes, modulesPath, ... }: {
config,
lib,
pkgs,
nodes,
modulesPath,
...
}:
# The way the connection is established is specific to the wob01 site and the Intel S2600KPR blades. # The way the connection is established is specific to the wob01 site and the Intel S2600KPR blades.
# Proper netboot is not possible, because while the blades and the APU board (which is the netboot # Proper netboot is not possible, because while the blades and the APU board (which is the netboot
@ -10,8 +17,11 @@
let let
netboot-server-ip = "2a01:584:11::2"; netboot-server-ip = "2a01:584:11::2";
netbootNodes = lib.filterAttrs (_: node: node.config.bagel.baremetal.builders.enable && node.config.bagel.baremetal.builders.netboot) nodes; netbootNodes = lib.filterAttrs (
in { _: node: node.config.bagel.baremetal.builders.enable && node.config.bagel.baremetal.builders.netboot
) nodes;
in
{
assertions = [ assertions = [
{ {
@ -23,10 +33,13 @@ in {
} }
]; ];
systemd.services = lib.mapAttrs' (nodename: node: let systemd.services = lib.mapAttrs' (
nodename: node:
let
bmcIp = "192.168.1.${toString (node.config.bagel.baremetal.builders.num * 4 + 2)}"; bmcIp = "192.168.1.${toString (node.config.bagel.baremetal.builders.num * 4 + 2)}";
notipxe = node.config.system.build.notipxe.config.system.build.usbImage; notipxe = node.config.system.build.notipxe.config.system.build.usbImage;
in lib.nameValuePair "iusb-spoof-${nodename}" { in
lib.nameValuePair "iusb-spoof-${nodename}" {
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
serviceConfig = { serviceConfig = {
Restart = "always"; Restart = "always";
@ -35,7 +48,8 @@ in {
AUTH_TOKEN=$(${pkgs.iusb-spoof}/bin/make-token ${bmcIp}) AUTH_TOKEN=$(${pkgs.iusb-spoof}/bin/make-token ${bmcIp})
exec ${pkgs.iusb-spoof}/bin/iusb-spoof -r ${bmcIp} 5123 $AUTH_TOKEN ${notipxe} exec ${pkgs.iusb-spoof}/bin/iusb-spoof -r ${bmcIp} 5123 $AUTH_TOKEN ${notipxe}
''; '';
}) netbootNodes; }
) netbootNodes;
# Since the builders are stateless, they can not store their ssh hostkeys # Since the builders are stateless, they can not store their ssh hostkeys
networking.firewall.allowedTCPPorts = [ 80 ]; # for ACME networking.firewall.allowedTCPPorts = [ 80 ]; # for ACME
@ -49,15 +63,19 @@ in {
virtualHosts."vpn-gw.wob01.infra.forkos.org" = { virtualHosts."vpn-gw.wob01.infra.forkos.org" = {
enableACME = true; enableACME = true;
forceSSL = true; forceSSL = true;
locations = lib.mapAttrs' (nodename: node: let locations = lib.mapAttrs' (
nodename: node:
let
ip = "2a01:584:11::1:${toString node.config.bagel.baremetal.builders.num}"; ip = "2a01:584:11::1:${toString node.config.bagel.baremetal.builders.num}";
in lib.nameValuePair "/${nodename}/" { in
lib.nameValuePair "/${nodename}/" {
root = "/var/www"; root = "/var/www";
extraConfig = '' extraConfig = ''
allow ${ip}; allow ${ip};
deny all; deny all;
''; '';
}) netbootNodes; }
) netbootNodes;
}; };
}; };
} }

View file

@ -1,10 +1,7 @@
# A wrapper for colmena that prevents accidentally deploying changes without # A wrapper for colmena that prevents accidentally deploying changes without
# having pulled. # having pulled.
{ colmena, runCommandNoCC }: { colmena, runCommandNoCC }:
runCommandNoCC "colmena-wrapper" runCommandNoCC "colmena-wrapper" { env.colmena = "${colmena}/bin/colmena"; } ''
{
env.colmena = "${colmena}/bin/colmena";
} ''
mkdir -p $out mkdir -p $out
ln -s ${colmena}/share $out/share ln -s ${colmena}/share $out/share
mkdir $out/bin mkdir $out/bin

View file

@ -1,4 +1,8 @@
{ rustPlatform, python3, makeWrapper }: {
rustPlatform,
python3,
makeWrapper,
}:
let let
pythonEnv = python3.withPackages (p: with p; [ requests ]); pythonEnv = python3.withPackages (p: with p; [ requests ]);
in in

View file

@ -11,9 +11,7 @@ buildGoModule rec {
hash = "sha256-8zA3pHf45MdUcq/MA/mf0KCTxB1viHieU/oigYwIPgo="; hash = "sha256-8zA3pHf45MdUcq/MA/mf0KCTxB1viHieU/oigYwIPgo=";
}; };
patches = [ patches = [ ./u-root-allow-https.patch ];
./u-root-allow-https.patch
];
vendorHash = null; vendorHash = null;
doCheck = false; doCheck = false;

View file

@ -12,7 +12,10 @@ let
mimir-webhook-url = [ machines.meta01 ]; mimir-webhook-url = [ machines.meta01 ];
grafana-oauth-secret = [ machines.meta01 ]; grafana-oauth-secret = [ machines.meta01 ];
loki-environment = [ machines.meta01 ]; loki-environment = [ machines.meta01 ];
gerrit-prometheus-bearer-token = [ machines.gerrit01 machines.meta01 ]; gerrit-prometheus-bearer-token = [
machines.gerrit01
machines.meta01
];
buildbot-worker-password = [ machines.buildbot ]; buildbot-worker-password = [ machines.buildbot ];
buildbot-oauth-secret = [ machines.buildbot ]; buildbot-oauth-secret = [ machines.buildbot ];

View file

@ -1,29 +1,61 @@
# This file contains information on which builder(s) are providing how many # This file contains information on which builder(s) are providing how many
# job slots and providing which nix features # job slots and providing which nix features
let let
genBuilders = { offset ? 0, count, f }: builtins.genList (x: rec { name = "builder-${toString (offset + x)}"; value = f name; }) count; genBuilders =
in builtins.listToAttrs ( {
offset ? 0,
count,
f,
}:
builtins.genList (x: rec {
name = "builder-${toString (offset + x)}";
value = f name;
}) count;
in
builtins.listToAttrs (
# The first 8 builders are general purpose hydra builders # The first 8 builders are general purpose hydra builders
genBuilders { count = 8; f = name: { genBuilders {
count = 8;
f = name: {
cores = 8; cores = 8;
max-jobs = 8; max-jobs = 8;
supported-features = [ "kvm" "nixos-test" ]; supported-features = [
"kvm"
"nixos-test"
];
required-features = [ ]; required-features = [ ];
}; } };
}
++ ++
# The last 2 builders are exclusively for big-parallel # The last 2 builders are exclusively for big-parallel
genBuilders { offset = 8; count = 2; f = name: { genBuilders {
offset = 8;
count = 2;
f = name: {
cores = 20; cores = 20;
max-jobs = 1; max-jobs = 1;
supported-features = [ "kvm" "nixos-test" "big-parallel" ]; supported-features = [
"kvm"
"nixos-test"
"big-parallel"
];
required-features = [ "big-parallel" ]; required-features = [ "big-parallel" ];
}; } };
}
++ ++
# These are not currently used for hydra # These are not currently used for hydra
genBuilders { offset = 10; count = 2; f = name: { genBuilders {
offset = 10;
count = 2;
f = name: {
cores = 8; cores = 8;
max-jobs = 8; max-jobs = 8;
supported-features = [ "kvm" "nixos-test" "big-parallel" ]; supported-features = [
"kvm"
"nixos-test"
"big-parallel"
];
required-features = [ ]; required-features = [ ];
}; } };
}
) )

View file

@ -1,4 +1,9 @@
{ pkgs, lib, config, ... }: {
pkgs,
lib,
config,
...
}:
let let
cfg = config.bagel.baremetal.builders; cfg = config.bagel.baremetal.builders;
in in
@ -10,14 +15,18 @@ in
bagel.baremetal.builders = { bagel.baremetal.builders = {
enable = lib.mkEnableOption "baremetal bagel oven"; enable = lib.mkEnableOption "baremetal bagel oven";
netboot = lib.mkEnableOption "netboot"; netboot = lib.mkEnableOption "netboot";
num = lib.mkOption { num = lib.mkOption { type = lib.types.int; };
type = lib.types.int;
};
}; };
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
boot.initrd.availableKernelModules = [ "ahci" "ehci_pci" "usb_storage" "usbhid" "sd_mod" ]; boot.initrd.availableKernelModules = [
"ahci"
"ehci_pci"
"usb_storage"
"usbhid"
"sd_mod"
];
boot.initrd.kernelModules = [ "dm-snapshot" ]; boot.initrd.kernelModules = [ "dm-snapshot" ];
users.users.builder = { users.users.builder = {
@ -44,7 +53,10 @@ in
]; ];
}; };
nix.settings = { nix.settings = {
trusted-users = [ "builder" "buildbot" ]; trusted-users = [
"builder"
"buildbot"
];
inherit ((import ./assignments.nix).${config.networking.hostName}) max-jobs cores; inherit ((import ./assignments.nix).${config.networking.hostName}) max-jobs cores;
}; };
@ -68,7 +80,10 @@ in
"/boot" = { "/boot" = {
device = "/dev/disk/by-label/BOOT"; device = "/dev/disk/by-label/BOOT";
fsType = "vfat"; fsType = "vfat";
options = [ "fmask=0022" "dmask=0022" ]; options = [
"fmask=0022"
"dmask=0022"
];
}; };
}) })
{ {
@ -132,9 +147,15 @@ in
}; };
}; };
networking.interfaces.uplink.ipv6.addresses = [ networking.interfaces.uplink.ipv6.addresses = [
{ address = "2a01:584:11::1:${toString cfg.num}"; prefixLength = 64; } {
address = "2a01:584:11::1:${toString cfg.num}";
prefixLength = 64;
}
]; ];
networking.defaultGateway6 = { interface = "uplink"; address = "2a01:584:11::1"; }; networking.defaultGateway6 = {
interface = "uplink";
address = "2a01:584:11::1";
};
deployment.targetHost = "2a01:584:11::1:${toString cfg.num}"; deployment.targetHost = "2a01:584:11::1:${toString cfg.num}";
deployment.tags = [ "builders" ]; deployment.tags = [ "builders" ];

View file

@ -1,4 +1,11 @@
{ modulesPath, pkgs, lib, config, extendModules, ... }@node: {
modulesPath,
pkgs,
lib,
config,
extendModules,
...
}@node:
let let
cfg = config.bagel.baremetal.builders; cfg = config.bagel.baremetal.builders;
in in
@ -32,8 +39,20 @@ in
{ {
system.stateVersion = "24.11"; system.stateVersion = "24.11";
boot.initrd.availableKernelModules = [ "ahci" "ehci_pci" "usb_storage" "usbhid" "sd_mod" "igb" "bonding" ]; boot.initrd.availableKernelModules = [
boot.kernelParams = [ "console=ttyS0,115200" "panic=1" "boot.panic_on_fail" ]; "ahci"
"ehci_pci"
"usb_storage"
"usbhid"
"sd_mod"
"igb"
"bonding"
];
boot.kernelParams = [
"console=ttyS0,115200"
"panic=1"
"boot.panic_on_fail"
];
#boot.initrd.systemd.emergencyAccess = true; #boot.initrd.systemd.emergencyAccess = true;
networking.hostName = "${node.config.networking.hostName}-boot"; networking.hostName = "${node.config.networking.hostName}-boot";
nixpkgs.overlays = import ../../overlays; nixpkgs.overlays = import ../../overlays;
@ -72,11 +91,32 @@ in
''; '';
# Provide a bootable USB drive image # Provide a bootable USB drive image
system.build.usbImage = pkgs.callPackage ({ stdenv, runCommand, dosfstools, e2fsprogs, mtools, libfaketime, util-linux, nukeReferences }: system.build.usbImage = pkgs.callPackage (
runCommand "boot-img-${node.config.networking.hostName}" { {
nativeBuildInputs = [ dosfstools e2fsprogs libfaketime mtools util-linux ]; stdenv,
outputs = [ "out" "firmware_part" ]; runCommand,
} '' dosfstools,
e2fsprogs,
mtools,
libfaketime,
util-linux,
nukeReferences,
}:
runCommand "boot-img-${node.config.networking.hostName}"
{
nativeBuildInputs = [
dosfstools
e2fsprogs
libfaketime
mtools
util-linux
];
outputs = [
"out"
"firmware_part"
];
}
''
export img=$out export img=$out
truncate -s 40M $img truncate -s 40M $img
@ -128,8 +168,7 @@ in
cp firmware_part.img $firmware_part cp firmware_part.img $firmware_part
'' ''
) { }; ) { };
} };
;
}; };
# This is the config which will actually be booted # This is the config which will actually be booted
@ -145,7 +184,8 @@ in
]; ];
}; };
# A derivation combining all the artifacts required for netbooting for the hydra job # A derivation combining all the artifacts required for netbooting for the hydra job
netbootDir = let netbootDir =
let
kernelTarget = pkgs.stdenv.hostPlatform.linux-kernel.target; kernelTarget = pkgs.stdenv.hostPlatform.linux-kernel.target;
build = config.system.build.netbootVariant.config.system.build; build = config.system.build.netbootVariant.config.system.build;
in in

View file

@ -9,24 +9,33 @@ let
cfg = config.bagel.services.buildbot; cfg = config.bagel.services.buildbot;
cfgGerrit = nodes.gerrit01.config.bagel.services.gerrit; cfgGerrit = nodes.gerrit01.config.bagel.services.gerrit;
ssh-keys = import ../../common/ssh-keys.nix; ssh-keys = import ../../common/ssh-keys.nix;
inherit (lib) mkEnableOption mkOption mkIf types; inherit (lib)
mkEnableOption
mkOption
mkIf
types
;
in in
{ {
options.bagel.services.buildbot = { options.bagel.services.buildbot = {
enable = mkEnableOption "Buildbot"; enable = mkEnableOption "Buildbot";
domain = mkOption { domain = mkOption { type = types.str; };
type = types.str;
};
builders = mkOption { builders = mkOption {
type = types.listOf types.str; type = types.listOf types.str;
description = "List of builders to configure for Buildbot"; description = "List of builders to configure for Buildbot";
example = [ "builder-2" "builder-3" ]; example = [
"builder-2"
"builder-3"
];
}; };
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
networking.firewall.allowedTCPPorts = [ 80 443 ]; networking.firewall.allowedTCPPorts = [
80
443
];
age.secrets.buildbot-worker-password.file = ../../secrets/buildbot-worker-password.age; age.secrets.buildbot-worker-password.file = ../../secrets/buildbot-worker-password.age;
age.secrets.buildbot-oauth-secret.file = ../../secrets/buildbot-oauth-secret.age; age.secrets.buildbot-oauth-secret.file = ../../secrets/buildbot-oauth-secret.age;
age.secrets.buildbot-workers.file = ../../secrets/buildbot-workers.age; age.secrets.buildbot-workers.file = ../../secrets/buildbot-workers.age;
@ -59,15 +68,14 @@ in
{ {
# nix-eval-jobs runs under a lock, error reports do not (but are cheap) # nix-eval-jobs runs under a lock, error reports do not (but are cheap)
other = 8; other = 8;
} // ( }
lib.filterAttrs // (lib.filterAttrs (n: v: lib.elem n config.services.buildbot-nix.coordinator.buildSystems) (
(n: v: lib.elem n config.services.buildbot-nix.coordinator.buildSystems) lib.zipAttrsWith (_: lib.foldl' lib.add 0) (
(lib.zipAttrsWith lib.concatMap (
(_: lib.foldl' lib.add 0) m: map (s: { ${s} = m.maxJobs; }) m.systems
(lib.concatMap ) config.services.buildbot-nix.coordinator.buildMachines
(m: map (s: { ${s} = m.maxJobs; }) m.systems) )
config.services.buildbot-nix.coordinator.buildMachines)) ));
);
}; };
services.buildbot-nix.coordinator = { services.buildbot-nix.coordinator = {
@ -90,14 +98,10 @@ in
# we can replace all of this with automatic localworker generation on buildbot-nix side. # we can replace all of this with automatic localworker generation on buildbot-nix side.
workersFile = config.age.secrets.buildbot-workers.path; workersFile = config.age.secrets.buildbot-workers.path;
allowedOrigins = [ allowedOrigins = [ "*.forkos.org" ];
"*.forkos.org"
];
# TODO(raito): is that really necessary when we can just collect buildMachines' systems? # TODO(raito): is that really necessary when we can just collect buildMachines' systems?
buildSystems = [ buildSystems = [ "x86_64-linux" ];
"x86_64-linux"
];
buildMachines = map (n: { buildMachines = map (n: {
hostName = nodes.${n}.config.networking.fqdn; hostName = nodes.${n}.config.networking.fqdn;
@ -110,8 +114,7 @@ in
supportedFeatures = nodes.${n}.config.nix.settings.system-features; supportedFeatures = nodes.${n}.config.nix.settings.system-features;
# Contrary to how Nix works, here we can specify non-base64 public host keys. # Contrary to how Nix works, here we can specify non-base64 public host keys.
publicHostKey = ssh-keys.machines.${n}; publicHostKey = ssh-keys.machines.${n};
} }) cfg.builders;
) cfg.builders;
gerrit = { gerrit = {
domain = cfgGerrit.canonicalDomain; domain = cfgGerrit.canonicalDomain;

View file

@ -1,18 +1,25 @@
{ pkgs, lib, config, ... }: {
pkgs,
lib,
config,
...
}:
let let
cfg = config.bagel.services.forgejo; cfg = config.bagel.services.forgejo;
inherit (lib) mkIf mkEnableOption mkOption types; inherit (lib)
mkIf
mkEnableOption
mkOption
types
;
domain = "git.forkos.org"; domain = "git.forkos.org";
in in
{ {
options.bagel.services.forgejo = { options.bagel.services.forgejo = {
enable = mkEnableOption "Forgejo"; enable = mkEnableOption "Forgejo";
sshBindAddr = mkOption { sshBindAddr = mkOption { type = types.str; };
type = types.str;
};
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
@ -116,8 +123,14 @@ in
# start Forgejo *after* sshd.service, so in case Forgejo tries to wildcard bind :22 due to # start Forgejo *after* sshd.service, so in case Forgejo tries to wildcard bind :22 due to
# a bug or whatever, we don't lose OpenSSH in a race. # a bug or whatever, we don't lose OpenSSH in a race.
wants = [ "sshd.service" "redis-forgejo.service" ]; wants = [
requires = [ "sshd.service" "redis-forgejo.service" ]; "sshd.service"
"redis-forgejo.service"
];
requires = [
"sshd.service"
"redis-forgejo.service"
];
}; };
services.redis.servers.forgejo = { services.redis.servers.forgejo = {

View file

@ -1,9 +1,20 @@
# Gerrit configuration for the Nixpkgs monorepo # Gerrit configuration for the Nixpkgs monorepo
# Inspired from TVL configuration. # Inspired from TVL configuration.
{ pkgs, config, lib, ... }: {
pkgs,
config,
lib,
...
}:
let let
inherit (lib) mkEnableOption mkIf mkOption types head; inherit (lib)
mkEnableOption
mkIf
mkOption
types
head
;
cfgGerrit = config.services.gerrit; cfgGerrit = config.services.gerrit;
cfg = config.bagel.services.gerrit; cfg = config.bagel.services.gerrit;
@ -74,7 +85,8 @@ in
oauth oauth
metrics-reporter-prometheus metrics-reporter-prometheus
# Buildbot checks plugin (writeText because services.gerrit.plugins expects packages) # Buildbot checks plugin (writeText because services.gerrit.plugins expects packages)
(pkgs.runCommand "checks.js" { (pkgs.runCommand "checks.js"
{
BASE_URI = builtins.toJSON "https://buildbot.forkos.org"; BASE_URI = builtins.toJSON "https://buildbot.forkos.org";
SUPPORTED_PROJECTS = builtins.toJSON [ SUPPORTED_PROJECTS = builtins.toJSON [
"infra" "infra"
@ -87,7 +99,8 @@ in
substitute ${./checks.js} $out \ substitute ${./checks.js} $out \
--replace-fail "@BASE_URI@" "$BASE_URI" \ --replace-fail "@BASE_URI@" "$BASE_URI" \
--replace-fail "@SUPPORTED_PROJECTS@" "$SUPPORTED_PROJECTS" --replace-fail "@SUPPORTED_PROJECTS@" "$SUPPORTED_PROJECTS"
'') ''
)
]; ];
package = pkgs.gerrit; package = pkgs.gerrit;

View file

@ -1,9 +1,23 @@
{ lib, config, pkgs, ... }: {
lib,
config,
pkgs,
...
}:
let let
cfg = config.bagel.nixpkgs.one-way-sync; cfg = config.bagel.nixpkgs.one-way-sync;
inherit (lib) mkIf mkOption mkEnableOption types mapAttrs'; inherit (lib)
mkIf
mkOption
mkEnableOption
types
mapAttrs'
;
mkSyncTimer = name: { timer, ... }: { mkSyncTimer =
name:
{ timer, ... }:
{
wantedBy = [ "timers.target" ]; wantedBy = [ "timers.target" ];
timerConfig = { timerConfig = {
@ -12,9 +26,22 @@ let
Unit = "ows-${name}.service"; Unit = "ows-${name}.service";
}; };
}; };
mkSyncService = name: { fromUri, fromRefspec, localRefspec, ... }: { mkSyncService =
path = [ pkgs.gitFull pkgs.openssh pkgs.lix ]; name:
script = '' {
fromUri,
fromRefspec,
localRefspec,
...
}:
{
path = [
pkgs.gitFull
pkgs.openssh
pkgs.lix
];
script =
''
set -xe set -xe
RUNTIME_DIRECTORY="/run/onewaysync-${name}" RUNTIME_DIRECTORY="/run/onewaysync-${name}"
trap "git worktree remove -f "$RUNTIME_DIRECTORY"/${name}" EXIT trap "git worktree remove -f "$RUNTIME_DIRECTORY"/${name}" EXIT
@ -34,15 +61,19 @@ let
git config user.name Fork-o-Tron git config user.name Fork-o-Tron
git config user.email noreply@forkos.org git config user.email noreply@forkos.org
git fetch ${fromUri} ${fromRefspec} git fetch ${fromUri} ${fromRefspec}
'' + lib.optionalString (!(lib.hasInfix "staging" localRefspec)) '' ''
+ lib.optionalString (!(lib.hasInfix "staging" localRefspec)) ''
OLD_STDENV=$(nix eval -f . stdenv.outPath --store "$RUNTIME_DIRECTORY") OLD_STDENV=$(nix eval -f . stdenv.outPath --store "$RUNTIME_DIRECTORY")
'' + '' ''
+ ''
git merge FETCH_HEAD git merge FETCH_HEAD
'' + lib.optionalString (!(lib.hasInfix "staging" localRefspec)) '' ''
+ lib.optionalString (!(lib.hasInfix "staging" localRefspec)) ''
NEW_STDENV=$(nix eval -f . stdenv.outPath --store "$RUNTIME_DIRECTORY") NEW_STDENV=$(nix eval -f . stdenv.outPath --store "$RUNTIME_DIRECTORY")
# Do not allow auto-merging a staging iteration # Do not allow auto-merging a staging iteration
test "$OLD_STDENV" = "$NEW_STDENV" test "$OLD_STDENV" = "$NEW_STDENV"
'' + '' ''
+ ''
GIT_SSH_COMMAND='ssh -i ${cfg.deployKeyPath}' git push ${cfg.pushUrl} HEAD:refs/heads/${localRefspec} GIT_SSH_COMMAND='ssh -i ${cfg.deployKeyPath}' git push ${cfg.pushUrl} HEAD:refs/heads/${localRefspec}
''; '';
serviceConfig = { serviceConfig = {
@ -84,7 +115,9 @@ in
}; };
branches = mkOption { branches = mkOption {
type = types.attrsOf (types.submodule ({ ... }: type = types.attrsOf (
types.submodule (
{ ... }:
{ {
options = { options = {
name = mkOption { name = mkOption {
@ -112,7 +145,9 @@ in
description = "Calendar format everytime we need to run the sync"; description = "Calendar format everytime we need to run the sync";
}; };
}; };
})); }
)
);
description = "Set of branches mapping from cl.forkos.org to other Git repositories"; description = "Set of branches mapping from cl.forkos.org to other Git repositories";
}; };

View file

@ -36,6 +36,9 @@ in
''; '';
}; };
networking.firewall.allowedTCPPorts = [ 443 80 ]; networking.firewall.allowedTCPPorts = [
443
80
];
}; };
} }

View file

@ -1,4 +1,10 @@
{ nodes, config, lib, pkgs, ... }: {
nodes,
config,
lib,
pkgs,
...
}:
let let
cfg = config.bagel.services.hydra; cfg = config.bagel.services.hydra;
@ -7,46 +13,66 @@ let
narCacheDir = "/var/cache/hydra/nar-cache"; narCacheDir = "/var/cache/hydra/nar-cache";
port = 3000; port = 3000;
mkCacheSettings = settings: builtins.concatStringsSep "&" ( mkCacheSettings =
lib.mapAttrsToList (k: v: "${k}=${v}") settings settings: builtins.concatStringsSep "&" (lib.mapAttrsToList (k: v: "${k}=${v}") settings);
);
# XXX: to support Nix's dumb public host key syntax (base64'd), this outputs # XXX: to support Nix's dumb public host key syntax (base64'd), this outputs
# a string with shell-style command interpolations: $(...). # a string with shell-style command interpolations: $(...).
mkBaremetalBuilder = { mkBaremetalBuilder =
{
parallelBuilds, parallelBuilds,
publicHostKey, publicHostKey,
host, host,
speedFactor ? 1, speedFactor ? 1,
user ? "builder", user ? "builder",
supportedSystems ? [ "i686-linux" "x86_64-linux" ], supportedSystems ? [
supportedFeatures ? [ "big-parallel" "kvm" "nixos-test" ], "i686-linux"
requiredFeatures ? [ ] "x86_64-linux"
],
supportedFeatures ? [
"big-parallel"
"kvm"
"nixos-test"
],
requiredFeatures ? [ ],
}: }:
let let
supportedFeatures_ = if (supportedFeatures != []) then lib.concatStringsSep "," supportedFeatures else "-"; supportedFeatures_ =
requiredFeatures_ = if (requiredFeatures != []) then lib.concatStringsSep "," requiredFeatures else "-"; if (supportedFeatures != [ ]) then lib.concatStringsSep "," supportedFeatures else "-";
requiredFeatures_ =
if (requiredFeatures != [ ]) then lib.concatStringsSep "," requiredFeatures else "-";
in in
"ssh://${user}@${host}?remote-store=/mnt ${lib.concatStringsSep "," supportedSystems} ${config.age.secrets.hydra-ssh-key-priv.path} ${toString parallelBuilds} ${toString speedFactor} ${supportedFeatures_} ${requiredFeatures_} $(echo -n '${publicHostKey}' | base64 -w0)"; "ssh://${user}@${host}?remote-store=/mnt ${lib.concatStringsSep "," supportedSystems} ${config.age.secrets.hydra-ssh-key-priv.path} ${toString parallelBuilds} ${toString speedFactor} ${supportedFeatures_} ${requiredFeatures_} $(echo -n '${publicHostKey}' | base64 -w0)";
# TODO: # TODO:
# - generalize to new architectures # - generalize to new architectures
# - generalize to new features # - generalize to new features
baremetalBuilders = lib.concatStringsSep "\n" baremetalBuilders = lib.concatStringsSep "\n" (
(map (n: let map (
assignments = (import ../baremetal-builder/assignments.nix).${n} or { n:
let
assignments =
(import ../baremetal-builder/assignments.nix).${n} or {
inherit (nodes.${n}.config.nix.settings) max-jobs; inherit (nodes.${n}.config.nix.settings) max-jobs;
supported-features = [ "big-parallel" "kvm" "nixos-test" ]; supported-features = [
"big-parallel"
"kvm"
"nixos-test"
];
required-features = [ ]; required-features = [ ];
}; };
in mkBaremetalBuilder { in
mkBaremetalBuilder {
parallelBuilds = assignments.max-jobs; parallelBuilds = assignments.max-jobs;
supportedFeatures = assignments.supported-features; supportedFeatures = assignments.supported-features;
requiredFeatures = assignments.required-features; requiredFeatures = assignments.required-features;
publicHostKey = ssh-keys.machines.${n}; publicHostKey = ssh-keys.machines.${n};
host = nodes.${n}.config.networking.fqdn; host = nodes.${n}.config.networking.fqdn;
}) cfg.builders); }
in { ) cfg.builders
);
in
{
options.bagel.services.hydra = with lib; { options.bagel.services.hydra = with lib; {
enable = mkEnableOption "Hydra coordinator"; enable = mkEnableOption "Hydra coordinator";
@ -58,7 +84,10 @@ in {
builders = mkOption { builders = mkOption {
type = types.listOf types.str; type = types.listOf types.str;
description = "List of builders to configure for Hydra"; description = "List of builders to configure for Hydra";
example = [ "builder-0" "builder-1" ]; example = [
"builder-0"
"builder-1"
];
}; };
}; };
@ -83,7 +112,12 @@ in {
# XXX: Otherwise services.hydra-dev overwrites it to only hydra-queue-runner... # XXX: Otherwise services.hydra-dev overwrites it to only hydra-queue-runner...
# #
# Can be removed once this is added to some common config template. # Can be removed once this is added to some common config template.
nix.settings.trusted-users = [ "root" "hydra" "hydra-www" "@wheel" ]; nix.settings.trusted-users = [
"root"
"hydra"
"hydra-www"
"@wheel"
];
# Because Hydra can't fetch flake inputs otherwise... also yes, this # Because Hydra can't fetch flake inputs otherwise... also yes, this
# prefix-based matching is absurdly bad. # prefix-based matching is absurdly bad.
@ -119,7 +153,8 @@ in {
]; ];
extraConfig = '' extraConfig = ''
store_uri = s3://bagel-cache?${mkCacheSettings { store_uri = s3://bagel-cache?${
mkCacheSettings {
endpoint = "s3.delroth.net"; endpoint = "s3.delroth.net";
region = "garage"; region = "garage";
@ -130,7 +165,8 @@ in {
ls-compression = "br"; ls-compression = "br";
write-nar-listing = "1"; write-nar-listing = "1";
}} }
}
server_store_uri = https://bagel-cache.s3-web.delroth.net?local-nar-cache=${narCacheDir} server_store_uri = https://bagel-cache.s3-web.delroth.net?local-nar-cache=${narCacheDir}
binary_cache_public_url = https://bagel-cache.s3-web.delroth.net binary_cache_public_url = https://bagel-cache.s3-web.delroth.net
@ -186,6 +222,9 @@ in {
}; };
}; };
networking.firewall.allowedTCPPorts = [ 80 443 ]; networking.firewall.allowedTCPPorts = [
80
443
];
}; };
} }

View file

@ -6,7 +6,12 @@
}: }:
let let
cfg = config.bagel.services.hookshot; cfg = config.bagel.services.hookshot;
inherit (lib) mkEnableOption mkIf mkOption types; inherit (lib)
mkEnableOption
mkIf
mkOption
types
;
keyPath = "/var/lib/matrix-hookshot/key.pem"; keyPath = "/var/lib/matrix-hookshot/key.pem";
in in
{ {
@ -50,21 +55,25 @@ in
bindAddress = "127.0.0.1"; bindAddress = "127.0.0.1";
}; };
passFile = keyPath; passFile = keyPath;
listeners = [{ listeners = [
{
port = 9994; port = 9994;
bindAddress = "127.0.0.1"; bindAddress = "127.0.0.1";
resources = [ "webhooks" ]; resources = [ "webhooks" ];
}]; }
];
generic = { generic = {
enabled = true; enabled = true;
urlPrefix = "https://alerts.forkos.org/webhook"; urlPrefix = "https://alerts.forkos.org/webhook";
}; };
permissions = map (mxid: { permissions = map (mxid: {
actor = mxid; actor = mxid;
services = [{ services = [
{
service = "*"; service = "*";
level = "admin"; level = "admin";
}]; }
];
}) cfg.admins; }) cfg.admins;
}; };

View file

@ -1,16 +1,19 @@
{ { config, lib, ... }:
config,
lib,
...
}:
let let
cfg = config.bagel.monitoring.grafana-agent; cfg = config.bagel.monitoring.grafana-agent;
inherit (lib) mkEnableOption mkOption mkIf types; inherit (lib)
mkEnableOption
mkOption
mkIf
types
;
passwordAsCredential = "\${CREDENTIALS_DIRECTORY}/password"; passwordAsCredential = "\${CREDENTIALS_DIRECTORY}/password";
in in
{ {
options.bagel.monitoring.grafana-agent = { options.bagel.monitoring.grafana-agent = {
enable = (mkEnableOption "Grafana Agent") // { default = true; }; enable = (mkEnableOption "Grafana Agent") // {
default = true;
};
exporters = mkOption { exporters = mkOption {
description = '' description = ''
@ -20,7 +23,10 @@ in
internally, which ends up exported as `job` label internally, which ends up exported as `job` label
on all metrics of that exporter. on all metrics of that exporter.
''; '';
type = types.attrsOf (types.submodule ({ config, name, ... }: { type = types.attrsOf (
types.submodule (
{ config, name, ... }:
{
options.port = mkOption { options.port = mkOption {
description = "Exporter port"; description = "Exporter port";
type = types.int; type = types.int;
@ -35,14 +41,15 @@ in
description = "Prometheus scrape config"; description = "Prometheus scrape config";
type = types.attrs; type = types.attrs;
}; };
config.scrapeConfig = lib.mkMerge [{ config.scrapeConfig = lib.mkMerge [
{
job_name = name; job_name = name;
static_configs = [ static_configs = [ { targets = [ "localhost:${toString config.port}" ]; } ];
{ targets = [ "localhost:${toString config.port}" ]; } }
]; (lib.mkIf (config.bearerTokenFile != null) {
} (lib.mkIf (config.bearerTokenFile != null) {
authorization.credentials_file = "\${CREDENTIALS_DIRECTORY}/${name}-bearer-token"; authorization.credentials_file = "\${CREDENTIALS_DIRECTORY}/${name}-bearer-token";
})]; })
];
options.secrets = mkOption { options.secrets = mkOption {
description = "Secrets required for scrape config"; description = "Secrets required for scrape config";
@ -53,7 +60,9 @@ in
config.secrets = lib.mkIf (config.bearerTokenFile != null) { config.secrets = lib.mkIf (config.bearerTokenFile != null) {
"${name}-bearer-token" = config.bearerTokenFile; "${name}-bearer-token" = config.bearerTokenFile;
}; };
})); }
)
);
default = { }; default = { };
}; };
}; };
@ -63,8 +72,10 @@ in
services.grafana-agent = { services.grafana-agent = {
enable = true; enable = true;
credentials = lib.mkMerge ([{ password = config.age.secrets.grafana-agent-password.path; }] ++ credentials = lib.mkMerge (
lib.mapAttrsToList (name: value: value.secrets) config.bagel.monitoring.grafana-agent.exporters); [ { password = config.age.secrets.grafana-agent-password.path; } ]
++ lib.mapAttrsToList (name: value: value.secrets) config.bagel.monitoring.grafana-agent.exporters
);
settings = { settings = {
metrics = { metrics = {
global.remote_write = [ global.remote_write = [
@ -80,7 +91,9 @@ in
configs = [ configs = [
{ {
name = config.networking.hostName; name = config.networking.hostName;
scrape_configs = lib.mapAttrsToList (name: value: value.scrapeConfig) config.bagel.monitoring.grafana-agent.exporters; scrape_configs = lib.mapAttrsToList (
name: value: value.scrapeConfig
) config.bagel.monitoring.grafana-agent.exporters;
} }
]; ];
}; };

View file

@ -1,14 +1,12 @@
{ { config, lib, ... }:
config,
lib,
...
}:
let let
cfg = config.bagel.monitoring.exporters.cadvisor; cfg = config.bagel.monitoring.exporters.cadvisor;
inherit (lib) mkEnableOption mkIf; inherit (lib) mkEnableOption mkIf;
in in
{ {
options.bagel.monitoring.exporters.cadvisor.enable = (mkEnableOption "Standard cAdvisor") // { default = !config.boot.isContainer; }; options.bagel.monitoring.exporters.cadvisor.enable = (mkEnableOption "Standard cAdvisor") // {
default = !config.boot.isContainer;
};
config = mkIf cfg.enable { config = mkIf cfg.enable {
services.cadvisor = { services.cadvisor = {

View file

@ -1,15 +1,13 @@
{ { config, lib, ... }:
config,
lib,
...
}:
let let
cfg = config.bagel.monitoring.exporters.nginx; cfg = config.bagel.monitoring.exporters.nginx;
inherit (lib) mkEnableOption mkIf; inherit (lib) mkEnableOption mkIf;
logFormat = ''$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" rt=$request_time uct="$upstream_connect_time" uht="$upstream_header_time" urt="$upstream_response_time"''; logFormat = ''$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" rt=$request_time uct="$upstream_connect_time" uht="$upstream_header_time" urt="$upstream_response_time"'';
in in
{ {
options.bagel.monitoring.exporters.nginx.enable = (mkEnableOption "Nginx access.log exporter") // { default = config.services.nginx.enable; }; options.bagel.monitoring.exporters.nginx.enable = (mkEnableOption "Nginx access.log exporter") // {
default = config.services.nginx.enable;
};
config = mkIf cfg.enable { config = mkIf cfg.enable {
services.nginx.appendHttpConfig = '' services.nginx.appendHttpConfig = ''

View file

@ -1,14 +1,12 @@
{ { config, lib, ... }:
config,
lib,
...
}:
let let
cfg = config.bagel.monitoring.exporters.postgres; cfg = config.bagel.monitoring.exporters.postgres;
inherit (lib) mkEnableOption mkIf; inherit (lib) mkEnableOption mkIf;
in in
{ {
options.bagel.monitoring.exporters.postgres.enable = (mkEnableOption "Postgres exporter") // { default = config.services.postgresql.enable; }; options.bagel.monitoring.exporters.postgres.enable = (mkEnableOption "Postgres exporter") // {
default = config.services.postgresql.enable;
};
config = mkIf cfg.enable { config = mkIf cfg.enable {
services.prometheus.exporters.postgres = { services.prometheus.exporters.postgres = {

View file

@ -1,8 +1,4 @@
{ { config, lib, ... }:
config,
lib,
...
}:
let let
cfg = config.bagel.services.grafana; cfg = config.bagel.services.grafana;
inherit (lib) mkEnableOption mkIf; inherit (lib) mkEnableOption mkIf;
@ -133,9 +129,11 @@ in
]; ];
}; };
nginx = let nginx =
let
scfg = config.services.grafana.settings.server; scfg = config.services.grafana.settings.server;
in { in
{
enable = true; enable = true;
virtualHosts."${scfg.domain}" = { virtualHosts."${scfg.domain}" = {
enableACME = true; enableACME = true;

View file

@ -1,8 +1,4 @@
{ { config, lib, ... }:
config,
lib,
...
}:
let let
cfg = config.bagel.services.loki; cfg = config.bagel.services.loki;
inherit (lib) mkEnableOption mkIf; inherit (lib) mkEnableOption mkIf;

View file

@ -76,11 +76,13 @@ in
receivers = [ receivers = [
{ {
name = "matrix"; name = "matrix";
webhook_configs = [{ webhook_configs = [
{
# Mimir can't expand environment variables in external config files, # Mimir can't expand environment variables in external config files,
# so work around it. # so work around it.
url_file = "/run/credentials/mimir.service/webhook-url"; url_file = "/run/credentials/mimir.service/webhook-url";
}]; }
];
} }
]; ];
}; };

View file

@ -8,15 +8,18 @@
let let
EnvironmentFile = [ config.age.secrets.netbox-environment.path ]; EnvironmentFile = [ config.age.secrets.netbox-environment.path ];
cfg = config.bagel.services.netbox; cfg = config.bagel.services.netbox;
inherit (lib) mkEnableOption mkOption mkIf types; inherit (lib)
mkEnableOption
mkOption
mkIf
types
;
in in
{ {
options.bagel.services.netbox = { options.bagel.services.netbox = {
enable = mkEnableOption "Netbox"; enable = mkEnableOption "Netbox";
domain = mkOption { domain = mkOption { type = types.str; };
type = types.str;
};
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {

View file

@ -5,7 +5,8 @@ let
amqpHost = "amqp.forkos.org"; amqpHost = "amqp.forkos.org";
amqpPort = 5671; amqpPort = 5671;
in { in
{
options.bagel.services.ofborg = with lib; { options.bagel.services.ofborg = with lib; {
enable = mkEnableOption "ofborg coordinator"; enable = mkEnableOption "ofborg coordinator";
}; };
@ -26,8 +27,7 @@ in {
webroot = "/var/lib/acme/.challenges"; webroot = "/var/lib/acme/.challenges";
group = "rabbitmq"; group = "rabbitmq";
}; };
services.nginx.virtualHosts.${amqpHost}.locations."/.well-known/acme-challenge".root = services.nginx.virtualHosts.${amqpHost}.locations."/.well-known/acme-challenge".root = "/var/lib/acme/.challenges";
"/var/lib/acme/.challenges";
systemd.services.rabbitmq.requires = [ "acme-finished-${amqpHost}.target" ]; systemd.services.rabbitmq.requires = [ "acme-finished-${amqpHost}.target" ];
networking.firewall.allowedTCPPorts = [ amqpPort ]; networking.firewall.allowedTCPPorts = [ amqpPort ];

View file

@ -1,10 +1,16 @@
{ config, lib, pkgs, ... }: {
config,
lib,
pkgs,
...
}:
let let
cfg = config.bagel.services.postgres; cfg = config.bagel.services.postgres;
dataDir = "/var/db/postgresql/16"; dataDir = "/var/db/postgresql/16";
in { in
{
options.bagel.services.postgres = with lib; { options.bagel.services.postgres = with lib; {
enable = mkEnableOption "PostgreSQL server"; enable = mkEnableOption "PostgreSQL server";
}; };

View file

@ -1,6 +1,11 @@
{ lib, config, ... }: { lib, config, ... }:
let let
inherit (lib) mkEnableOption mkIf tf genList; inherit (lib)
mkEnableOption
mkIf
tf
genList
;
cfg = config.bagel.gandi; cfg = config.bagel.gandi;
in in
{ {
@ -24,9 +29,15 @@ in
name = "forkos.org"; name = "forkos.org";
}; };
resource.gandi_livedns_record = let resource.gandi_livedns_record =
let
record = name: ttl: type: values: { record = name: ttl: type: values: {
inherit name ttl type values; inherit
name
ttl
type
values
;
}; };
proxyRecords = name: ttl: type: values: [ proxyRecords = name: ttl: type: values: [
@ -36,26 +47,45 @@ in
]; ];
# Creates a extra *.p record pointing to the sniproxy # Creates a extra *.p record pointing to the sniproxy
dualProxyRecords = name: ttl: type: values: lib.flatten [ dualProxyRecords =
name: ttl: type: values:
lib.flatten [
(record name ttl type values) (record name ttl type values)
(proxyRecords "${name}.p" ttl type values) (proxyRecords "${name}.p" ttl type values)
]; ];
# TODO: make less fragile and have actual unique and stable names # TODO: make less fragile and have actual unique and stable names
canonicalName = record: let canonicalName =
name = builtins.replaceStrings ["." "@"] ["_" "_root_"] record.name; record:
let
name =
builtins.replaceStrings
[
"."
"@"
]
[
"_"
"_root_"
]
record.name;
in in
"forkos_org_${record.type}_${name}"; "forkos_org_${record.type}_${name}";
forkosRecords = records: forkosRecords =
builtins.listToAttrs (map (record: { records:
builtins.listToAttrs (
map (record: {
name = canonicalName record; name = canonicalName record;
value = record // { value = record // {
zone = tf.ref "resource.gandi_livedns_domain.forkos_org.id"; zone = tf.ref "resource.gandi_livedns_domain.forkos_org.id";
}; };
}) (lib.flatten records)); }) (lib.flatten records)
);
in forkosRecords ([ in
forkosRecords (
[
# (record "@" 3600 "A" ["163.172.69.160"]) # (record "@" 3600 "A" ["163.172.69.160"])
(record "@" 3600 "AAAA" [ "2001:bc8:38ee:100:1000::20" ]) (record "@" 3600 "AAAA" [ "2001:bc8:38ee:100:1000::20" ])
@ -90,6 +120,11 @@ in
(record "vpn-gw.wob01.infra" 3600 "AAAA" [ "2a01:584:11::2" ]) (record "vpn-gw.wob01.infra" 3600 "AAAA" [ "2a01:584:11::2" ])
# TODO: do not hardcode, just reuse the Colmena hive module outputs to generate all the required details. # TODO: do not hardcode, just reuse the Colmena hive module outputs to generate all the required details.
] ++ map (index: record "builder-${toString index}.wob01.infra" 3600 "AAAA" [ "2a01:584:11::1:${toString index}" ]) (genList lib.id 12)); ]
++ map (
index:
record "builder-${toString index}.wob01.infra" 3600 "AAAA" [ "2a01:584:11::1:${toString index}" ]
) (genList lib.id 12)
);
}; };
} }

View file

@ -1,6 +1,12 @@
{ lib, config, ... }: { lib, config, ... }:
let let
inherit (lib) mkEnableOption mkIf types mkOption tf; inherit (lib)
mkEnableOption
mkIf
types
mkOption
tf
;
cfg = config.bagel.hydra; cfg = config.bagel.hydra;
in in
{ {