159 lines
4.3 KiB
Nix
159 lines
4.3 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 =
|
|
{
|
|
self,
|
|
nixpkgs,
|
|
mtce,
|
|
microvm,
|
|
...
|
|
}:
|
|
let
|
|
system = "x86_64-linux";
|
|
inherit (nixpkgs) lib;
|
|
pkgs = import nixpkgs { inherit system; };
|
|
|
|
flakeRev = self.shortRev or self.dirtyShortRev or "unknown";
|
|
|
|
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 { };
|
|
server-autodeploy = pkgs.callPackage ./packages/server-autodeploy.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 flakeRev;
|
|
};
|
|
|
|
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
|
|
server-autodeploy
|
|
;
|
|
};
|
|
};
|
|
}
|