Files
Floweynt cbfdc8c4f2
diff-tag / dix (push) Successful in 6m11s
flake-check / flake-check (push) Successful in 52s
lint / lint (push) Successful in 1m49s
fix CI runs
2026-09-10 18:30:14 -05:00

154 lines
4.1 KiB
Nix

{
description = "Server infrastructure";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
mtce.url = "github:Floweynt/monumenta-charm-eval/master";
mtce.inputs.nixpkgs.follows = "nixpkgs";
microvm.url = "github:microvm-nix/microvm.nix";
microvm.inputs.nixpkgs.follows = "nixpkgs";
};
outputs =
{
nixpkgs,
mtce,
microvm,
...
}:
let
system = "x86_64-linux";
inherit (nixpkgs) lib;
pkgs = import nixpkgs { inherit system; };
customPkgs = {
hopper-rs = pkgs.callPackage ./packages/hopper-rs.nix { };
sshpiper = pkgs.callPackage ./packages/sshpiper.nix { };
kitty-terminfo = pkgs.callPackage ./packages/kitty-terminfo.nix { };
ct = pkgs.callPackage ./packages/ct.nix { };
server-rebuild = pkgs.callPackage ./packages/server-rebuild.nix { };
server-status = pkgs.callPackage ./packages/server-status.nix { };
server-kexec = pkgs.callPackage ./packages/server-kexec.nix { };
};
ci = import ./ci.nix { inherit lib pkgs; };
inputs = { inherit mtce microvm; };
dsl = import ./dsl.nix { inherit lib microvm; };
introspect = import ./introspect.nix { inherit lib dsl; };
hostInfoFor = hostName: {
hostname = hostName;
mainGateway = "10.0.0.1";
isVm = false;
paths = {
server = "/persist/@containers";
data = "/persist/@containers/data";
secrets = "/persist/@secrets/";
};
};
specialArgsFor = hostName: {
hostInfo = hostInfoFor hostName;
inherit inputs customPkgs;
};
hostDefFor =
hostName:
import (./hosts + "/${hostName}.nix") {
inherit lib;
hostInfo = hostInfoFor hostName;
};
commonModule = import ./configuration.nix;
prepareHost =
hostName:
let
hostDef = hostDefFor hostName;
containerDirs = [
./containers/common
(./containers + "/${hostName}")
];
specialArgs = specialArgsFor hostName;
ctx = specialArgs // {
inherit pkgs lib;
};
containers = dsl.loadContainers {
inherit
hostName
containerDirs
ctx
;
};
self = {
inherit
hostName
hostDef
containerDirs
specialArgs
ctx
containers
;
};
hostCfg = lib.nixosSystem {
inherit system specialArgs;
modules = [
commonModule
microvm.nixosModules.host
hostDef.module
(dsl.mkHostFromContainers { inherit containers ctx; })
];
};
testDir = ./tests + "/${hostName}";
tests =
if builtins.pathExists testDir then
lib.mapAttrs' (testName: testCfg: lib.nameValuePair "${testName}-${hostName}" testCfg) (
dsl.listMap testDir (
_name: path:
pkgs.testers.nixosTest (
import path {
inherit lib dsl commonModule;
host = self;
}
)
)
)
else
{ };
in
self // { inherit hostCfg tests; };
allHosts = lib.genAttrs (lib.attrNames (dsl.listMap ./hosts (hostName: _: hostName))) prepareHost;
in
{
nixosConfigurations = lib.mapAttrs (_: host: host.hostCfg) allHosts;
inspect = lib.mapAttrs (
name: host:
pkgs.writeText "inspect-${name}.json" (builtins.toJSON (introspect.hostReport { inherit host; }))
) allHosts;
packages.${system} = customPkgs // {
inherit ci;
};
formatter.${system} = pkgs.nixfmt;
checks.${system} = lib.foldl' (acc: host: acc // host.tests) { } (lib.attrValues allHosts) // {
inherit ci;
inherit (customPkgs)
ct
server-rebuild
server-status
server-kexec
;
};
};
}