NixOS system configurations + dotfiles via home-manager
1{ inputs, config, ... }:
2let
3 inherit (inputs.nixpkgs) lib;
4 inherit (inputs.self.modules.nixos) container hostContainer;
5 cfg = config.local;
6 mkHostname =
7 containerName:
8 let
9 parts = lib.splitString "." containerName;
10 host = config.flake.nixosConfigurations.${lib.last parts};
11 in
12 {
13 networking.hostName = lib.head parts;
14 networking.domain = host.config.networking.fqdn;
15 };
16 mkHost = sharedModule: name: hostModule: {
17 imports = [
18 hostModule
19 sharedModule
20 (mkHostname name)
21 ];
22 };
23 mkHosts = sharedModule: builtins.mapAttrs (mkHost sharedModule);
24 hostContainers = mkHosts hostContainer (
25 lib.mapAttrs' (name: lib.nameValuePair "${name}.grancel") cfg.hosts
26 );
27in
28{
29 options.local = {
30 containers = lib.mkOption {
31 type = lib.types.attrsOf lib.types.deferredModule;
32 default = { };
33 };
34 resolvedContainers = lib.mkOption {
35 readOnly = true;
36 default = mkHosts container cfg.containers;
37 };
38 };
39
40 config.flake.nixosConfigurations = builtins.mapAttrs (
41 _: module: lib.nixosSystem { modules = [ module ]; }
42 ) (cfg.resolvedContainers // hostContainers);
43}