2024-06-23 04:41:53 +00:00
|
|
|
{
|
|
|
|
description = "Bagel cooking infrastructure";
|
|
|
|
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
2024-08-12 22:38:51 +00:00
|
|
|
|
2024-07-02 09:08:19 +00:00
|
|
|
terranix.url = "github:terranix/terranix";
|
2024-08-12 22:38:51 +00:00
|
|
|
terranix.inputs.nixpkgs.follows = "nixpkgs";
|
2024-06-23 04:41:53 +00:00
|
|
|
|
2024-06-24 16:03:07 +00:00
|
|
|
agenix.url = "github:ryantm/agenix";
|
|
|
|
agenix.inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
|
2024-06-23 04:41:53 +00:00
|
|
|
colmena.url = "github:zhaofengli/colmena";
|
|
|
|
colmena.inputs.nixpkgs.follows = "nixpkgs";
|
2024-06-24 14:45:59 +00:00
|
|
|
|
2024-08-12 23:10:52 +00:00
|
|
|
hydra.url = "git+https://git.lix.systems/lix-project/hydra.git";
|
2024-06-24 14:45:59 +00:00
|
|
|
hydra.inputs.nixpkgs.follows = "nixpkgs";
|
2024-06-24 18:59:37 +00:00
|
|
|
|
2024-07-08 20:30:08 +00:00
|
|
|
nix-gerrit.url = "git+https://git.lix.systems/the-distro/nix-gerrit.git";
|
|
|
|
nix-gerrit.inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
|
2024-08-24 08:59:47 +00:00
|
|
|
gerrit-dashboard.url = "git+https://git.lix.systems/the-distro/gerrit-monitoring.git";
|
|
|
|
gerrit-dashboard.flake = false;
|
|
|
|
|
2024-10-27 18:39:18 +00:00
|
|
|
buildbot-nix.url = "git+https://git.lix.systems/lix-project/buildbot-nix.git?ref=refs/heads/faster-depinfo";
|
2024-07-17 12:47:38 +00:00
|
|
|
buildbot-nix.inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
|
2024-08-01 22:33:42 +00:00
|
|
|
channel-scripts.url = "git+https://git.lix.systems/the-distro/channel-scripts.git";
|
|
|
|
channel-scripts.inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
|
2024-09-26 22:09:12 +00:00
|
|
|
stateless-uptime-kuma.url = "git+https://git.dgnum.eu/DGNum/stateless-uptime-kuma.git";
|
|
|
|
stateless-uptime-kuma.flake = false;
|
|
|
|
|
2024-07-17 11:10:53 +00:00
|
|
|
lix.follows = "hydra/lix";
|
2024-08-15 14:22:22 +00:00
|
|
|
|
|
|
|
grapevine = {
|
|
|
|
type = "gitlab";
|
|
|
|
host = "gitlab.computer.surgery";
|
|
|
|
owner = "matrix";
|
|
|
|
repo = "grapevine-fork";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2024-06-23 04:41:53 +00:00
|
|
|
};
|
|
|
|
|
2024-07-09 08:49:29 +00:00
|
|
|
outputs = { self, nixpkgs, terranix, colmena, ... } @ inputs:
|
2024-07-02 09:08:19 +00:00
|
|
|
let
|
2024-07-21 15:03:29 +00:00
|
|
|
supportedSystems = [ "x86_64-linux" "aarch64-linux" ];
|
|
|
|
forEachSystem = f: builtins.listToAttrs (map (system: {
|
|
|
|
name = system;
|
|
|
|
value = f system;
|
|
|
|
}) supportedSystems);
|
|
|
|
systemBits = forEachSystem (system: rec {
|
2024-07-02 09:08:19 +00:00
|
|
|
inherit system;
|
2024-07-21 15:03:29 +00:00
|
|
|
pkgs = import nixpkgs {
|
|
|
|
localSystem = system;
|
|
|
|
overlays = [
|
|
|
|
inputs.hydra.overlays.default
|
|
|
|
inputs.lix.overlays.default
|
|
|
|
inputs.nix-gerrit.overlays.default
|
2024-08-01 22:33:42 +00:00
|
|
|
inputs.channel-scripts.overlays.default
|
2024-09-26 22:09:12 +00:00
|
|
|
(import "${inputs.stateless-uptime-kuma}/overlay.nix")
|
2024-07-21 15:03:29 +00:00
|
|
|
];
|
|
|
|
};
|
|
|
|
terraform = pkgs.opentofu;
|
|
|
|
terraformCfg = terranix.lib.terranixConfiguration {
|
|
|
|
inherit system;
|
2024-10-27 20:32:28 +00:00
|
|
|
extraArgs = {
|
|
|
|
inherit (self) nixosConfigurations;
|
|
|
|
};
|
2024-07-21 15:03:29 +00:00
|
|
|
modules = [
|
|
|
|
./terraform
|
|
|
|
{
|
2024-09-23 17:24:30 +00:00
|
|
|
bagel.dnsimple.enable = true;
|
2024-07-21 15:03:29 +00:00
|
|
|
bagel.hydra.enable = true;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
});
|
|
|
|
forEachSystem' = f: forEachSystem (system: (f systemBits.${system}));
|
|
|
|
inherit (nixpkgs) lib;
|
2024-07-02 09:08:19 +00:00
|
|
|
in
|
|
|
|
{
|
2024-07-21 15:03:29 +00:00
|
|
|
apps = forEachSystem' ({ system, pkgs, terraformCfg, terraform, ... }: {
|
2024-07-07 17:17:11 +00:00
|
|
|
tf = {
|
2024-07-02 09:08:19 +00:00
|
|
|
type = "app";
|
2024-07-07 17:17:11 +00:00
|
|
|
program = toString (pkgs.writers.writeBash "tf" ''
|
2024-07-02 09:08:19 +00:00
|
|
|
set -eo pipefail
|
2024-07-07 17:17:11 +00:00
|
|
|
ln -snf ${terraformCfg} config.tf.json
|
|
|
|
exec ${lib.getExe terraform} "$@"
|
2024-07-02 09:08:19 +00:00
|
|
|
'');
|
2024-07-07 17:17:11 +00:00
|
|
|
};
|
2024-07-07 16:02:55 +00:00
|
|
|
|
2024-07-07 17:17:11 +00:00
|
|
|
default = self.apps.${system}.tf;
|
2024-07-21 15:03:29 +00:00
|
|
|
});
|
2024-07-05 09:43:53 +00:00
|
|
|
|
2024-07-21 15:03:29 +00:00
|
|
|
devShells = forEachSystem' ({ system, pkgs, ... }: {
|
|
|
|
default = pkgs.mkShell {
|
|
|
|
packages = [
|
|
|
|
inputs.agenix.packages.${system}.agenix
|
2024-07-04 11:54:50 +00:00
|
|
|
|
2024-07-21 15:03:29 +00:00
|
|
|
pkgs.opentofu
|
2024-07-23 22:21:00 +00:00
|
|
|
|
2024-07-21 15:03:29 +00:00
|
|
|
(pkgs.callPackage ./lib/colmena-wrapper.nix { })
|
|
|
|
];
|
|
|
|
};
|
|
|
|
});
|
2024-07-05 09:43:53 +00:00
|
|
|
|
2024-07-09 08:49:29 +00:00
|
|
|
nixosConfigurations = (colmena.lib.makeHive self.outputs.colmena).nodes;
|
|
|
|
|
2024-07-10 12:24:47 +00:00
|
|
|
colmena = let
|
|
|
|
commonModules = [
|
|
|
|
inputs.agenix.nixosModules.default
|
|
|
|
inputs.hydra.nixosModules.hydra
|
2024-07-17 12:47:38 +00:00
|
|
|
inputs.buildbot-nix.nixosModules.buildbot-coordinator
|
|
|
|
inputs.buildbot-nix.nixosModules.buildbot-worker
|
2024-07-10 12:24:47 +00:00
|
|
|
|
|
|
|
./services
|
|
|
|
./common
|
2024-10-05 16:04:51 +00:00
|
|
|
];
|
2024-10-05 14:29:14 +00:00
|
|
|
|
2024-10-05 16:04:51 +00:00
|
|
|
floralInfraModules = commonModules ++ [
|
2024-10-05 14:29:14 +00:00
|
|
|
({ config, lib, ... }: {
|
2024-08-01 21:41:05 +00:00
|
|
|
# This means that anyone with @floral-infra permissions
|
|
|
|
# can ssh on root of every machines handled here.
|
|
|
|
bagel.admins.allowedGroups = [
|
|
|
|
"floral-infra"
|
|
|
|
];
|
2024-10-05 14:29:14 +00:00
|
|
|
|
2024-10-05 16:04:51 +00:00
|
|
|
# Tag all machines which have local boot as local bootables.
|
2024-10-06 09:19:16 +00:00
|
|
|
deployment.tags = lib.mkMerge [
|
|
|
|
[ "floral" ]
|
2024-10-27 19:22:49 +00:00
|
|
|
# All nodes that can be local booted, including baremetal nodes.
|
|
|
|
(lib.mkIf (config.bagel.baremetal.enable -> !config.bagel.baremetal.netboot)
|
2024-10-06 09:19:16 +00:00
|
|
|
[ "localboot" ]
|
|
|
|
)
|
2024-10-27 19:22:49 +00:00
|
|
|
# Only baremetal nodes that can be local booted.
|
|
|
|
(lib.mkIf (config.bagel.baremetal.enable && !config.bagel.baremetal.netboot)
|
|
|
|
[ "bm-localboot" ]
|
|
|
|
)
|
2024-10-06 09:19:16 +00:00
|
|
|
];
|
2024-10-05 16:04:51 +00:00
|
|
|
|
2024-10-06 09:03:53 +00:00
|
|
|
bagel.monitoring.grafana-agent.tenant = "floral";
|
2024-10-05 16:04:51 +00:00
|
|
|
bagel.secrets.tenant = "floral";
|
|
|
|
bagel.builders.extra-build-capacity.provider.tenant = "floral";
|
2024-10-05 16:14:39 +00:00
|
|
|
bagel.services.buildbot.tenant = "floral";
|
2024-10-05 14:29:14 +00:00
|
|
|
})
|
2024-07-10 12:24:47 +00:00
|
|
|
];
|
|
|
|
|
2024-10-05 16:04:51 +00:00
|
|
|
# These are Floral baremetal builders.
|
2024-10-27 19:22:49 +00:00
|
|
|
makeColoBaremetal = i:
|
2024-10-05 14:29:14 +00:00
|
|
|
let
|
|
|
|
enableNetboot = i >= 6;
|
|
|
|
in
|
2024-10-27 19:22:49 +00:00
|
|
|
# bm for baremetal.
|
|
|
|
lib.nameValuePair "bm-${toString i}" {
|
2024-10-05 16:04:51 +00:00
|
|
|
imports = floralInfraModules;
|
2024-10-27 19:22:49 +00:00
|
|
|
bagel.baremetal = { enable = true; num = i; netboot = enableNetboot; };
|
|
|
|
};
|
|
|
|
|
|
|
|
setFlavorForNode = flavor: i: node: {
|
|
|
|
imports = [
|
|
|
|
node
|
|
|
|
];
|
|
|
|
|
|
|
|
bagel.baremetal.${flavor} = {
|
|
|
|
enable = true;
|
|
|
|
num = i;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
setFlavorForNodes = flavor: { ranges }: nodes:
|
|
|
|
let
|
|
|
|
setFlavor = setFlavorForNode flavor;
|
|
|
|
# Test if i is in [range.start, range.end[.
|
|
|
|
inRange = i: range: i >= range.start && i < range.end;
|
|
|
|
# Perform an enumeration from values to indexes.
|
|
|
|
reverseEnumerate = list: lib.listToAttrs (lib.zipListsWith (i: x: lib.nameValuePair x i) (lib.range 0 (lib.length list - 1)) list);
|
|
|
|
# Filter all nodes by the range data for this flavor.
|
|
|
|
filteredNodes = lib.filterAttrs (name: node: lib.any (r: inRange node.bagel.baremetal.num r) ranges) nodes;
|
|
|
|
# The enumeration from baremetal numbers to flavor-specific numbers.
|
2024-10-27 20:32:28 +00:00
|
|
|
indexes = reverseEnumerate (map (n: toString n.bagel.baremetal.num) (builtins.attrValues filteredNodes));
|
2024-10-27 19:22:49 +00:00
|
|
|
in
|
|
|
|
# Build a new attrset with a new second-level index for the specific flavor.
|
|
|
|
lib.mapAttrs (name: node: setFlavor indexes.${toString node.bagel.baremetal.num} node) filteredNodes;
|
|
|
|
|
|
|
|
closedOpenInterval = a: b: { start = a; end = b; };
|
|
|
|
interval = a: b: closedOpenInterval a b;
|
|
|
|
setStorage = setFlavorForNodes "storage" {
|
|
|
|
# List the indexes for the baremetal nodes which are supposed to be storage nodes.
|
|
|
|
ranges = [ (interval 5 6) ];
|
|
|
|
};
|
|
|
|
setBuilders = setFlavorForNodes "builders" {
|
|
|
|
# List the indexes for the baremetal nodes which are supposed to be builders nodes.
|
|
|
|
ranges = [ (interval 0 5) (interval 6 10) ];
|
2024-07-10 12:24:47 +00:00
|
|
|
};
|
|
|
|
|
2024-10-05 16:04:51 +00:00
|
|
|
lixInfraModules = commonModules ++ [
|
|
|
|
{
|
|
|
|
# This means that anyone with @lix-infra permissions
|
|
|
|
# can ssh on root of every machines handled here.
|
|
|
|
bagel.admins.allowedGroups = [
|
|
|
|
"lix-infra"
|
|
|
|
];
|
|
|
|
|
|
|
|
# Tag all machines which have local boot as local bootables.
|
|
|
|
# Lix has no netbootable machine.
|
2024-10-06 09:19:16 +00:00
|
|
|
deployment.tags = [ "localboot" "lix" ];
|
2024-10-05 16:04:51 +00:00
|
|
|
|
2024-10-06 09:03:53 +00:00
|
|
|
bagel.monitoring.grafana-agent.tenant = "lix";
|
2024-10-05 16:04:51 +00:00
|
|
|
bagel.secrets.tenant = "lix";
|
2024-10-06 09:18:18 +00:00
|
|
|
bagel.builders.extra-build-capacity.provider = {
|
|
|
|
tenant = "lix";
|
|
|
|
buildfarmPublicKeys = [
|
|
|
|
# buildbot.lix.systems SSH key
|
|
|
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDu4cEqZzAI/1vZjSQkTJ4ijIg9nuloOuSKUrnkJIOFn"
|
|
|
|
];
|
|
|
|
};
|
2024-10-05 16:14:39 +00:00
|
|
|
bagel.services.buildbot.tenant = "lix";
|
2024-10-05 16:04:51 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2024-10-27 19:22:49 +00:00
|
|
|
checkForNonReuse = setOfNodes:
|
|
|
|
let
|
|
|
|
setOfNodesNames = lib.mapAttrs (name: nodes: builtins.attrNames nodes) setOfNodes;
|
|
|
|
in
|
|
|
|
lib.all (set:
|
|
|
|
lib.all (anotherSet: set != anotherSet -> lib.intersectLists setOfNodesNames.${set} setOfNodesNames.${anotherSet} == []) (builtins.attrNames setOfNodes)
|
|
|
|
) (builtins.attrNames setOfNodes);
|
|
|
|
|
|
|
|
baremetalNodes =
|
|
|
|
let
|
|
|
|
allNodes = lib.listToAttrs (lib.genList makeColoBaremetal 11);
|
|
|
|
perRoles = {
|
|
|
|
storageNodes = setStorage allNodes;
|
|
|
|
builderNodes = setBuilders allNodes;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
assert (lib.assertMsg (checkForNonReuse perRoles) "A baremetal node is simultaneously storage and builder, please review the ranges.");
|
|
|
|
lib.foldl (a: b: a // b) { } (builtins.attrValues perRoles);
|
|
|
|
|
2024-07-10 12:24:47 +00:00
|
|
|
in {
|
2024-07-21 15:03:29 +00:00
|
|
|
meta.nixpkgs = systemBits.x86_64-linux.pkgs;
|
2024-10-05 16:04:51 +00:00
|
|
|
# Add any non-x86_64 native systems here.
|
|
|
|
# Cross compilation is not supported yet.
|
|
|
|
meta.nodeNixpkgs =
|
|
|
|
let
|
|
|
|
aarch64-systems = systems: lib.genAttrs systems (system: systemBits.aarch64-linux.pkgs);
|
|
|
|
in
|
|
|
|
aarch64-systems [
|
2024-10-05 16:05:48 +00:00
|
|
|
"build01-aarch64-lix"
|
2024-10-05 16:04:51 +00:00
|
|
|
];
|
2024-06-24 14:45:59 +00:00
|
|
|
meta.specialArgs.inputs = inputs;
|
|
|
|
|
2024-10-05 16:04:51 +00:00
|
|
|
bagel-box.imports = floralInfraModules ++ [ ./hosts/bagel-box ];
|
|
|
|
meta01.imports = floralInfraModules ++ [ ./hosts/meta01 ];
|
|
|
|
gerrit01.imports = floralInfraModules ++ [ ./hosts/gerrit01 ];
|
|
|
|
fodwatch.imports = floralInfraModules ++ [ ./hosts/fodwatch ];
|
|
|
|
git.imports = floralInfraModules ++ [ ./hosts/git ];
|
|
|
|
wob-vpn-gw.imports = floralInfraModules ++ [ ./hosts/wob-vpn-gw ];
|
|
|
|
buildbot.imports = floralInfraModules ++ [ ./hosts/buildbot ];
|
|
|
|
public01.imports = floralInfraModules ++ [ ./hosts/public01 ];
|
|
|
|
build-coord.imports = floralInfraModules ++ [ ./hosts/build-coord ];
|
2024-10-05 16:05:48 +00:00
|
|
|
|
|
|
|
build01-aarch64-lix.imports = lixInfraModules ++ [ ./hosts/build01-aarch64-lix ];
|
2024-10-05 16:18:12 +00:00
|
|
|
buildbot-lix.imports = lixInfraModules ++ [ ./hosts/buildbot-lix ];
|
2024-10-27 19:22:49 +00:00
|
|
|
} // baremetalNodes;
|
2024-07-10 16:40:59 +00:00
|
|
|
|
2024-08-01 20:47:25 +00:00
|
|
|
hydraJobs = builtins.mapAttrs (n: v: v.config.system.build.netbootDir or v.config.system.build.toplevel) self.nixosConfigurations;
|
2024-07-18 10:18:12 +00:00
|
|
|
buildbotJobs = builtins.mapAttrs (_: v: v.config.system.build.toplevel) self.nixosConfigurations;
|
2024-06-23 04:41:53 +00:00
|
|
|
};
|
|
|
|
}
|