{ 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"; deploy-label.url = "path:./misc/deploy-label"; deploy-label.flake = false; }; outputs = { self, nixpkgs, mtce, microvm, deploy-label, ... }: let system = "x86_64-linux"; inherit (nixpkgs) lib; pkgs = import nixpkgs { inherit system; }; flakeRev = self.shortRev or self.dirtyShortRev or "unknown"; deployLabel = let labelFile = "${deploy-label}/label"; raw = lib.removeSuffix "\n" (builtins.readFile labelFile); in if raw != "" then raw else null; 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/"; config = "/persist/@config/"; }; }; specialArgsFor = hostName: { hostInfo = hostInfoFor hostName; inherit inputs customPkgs flakeRev deployLabel; }; 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 ; }; }; }