refactor(*): drive host config from kore.json registry
5 files changed, -33/+43
flake.nix
@@ -18,9 +18,10 @@ let inherit (self) outputs; lib = nixpkgs.lib // home-manager.lib;+ kore = builtins.fromJSON (builtins.readFile ./kore.json); in {- nixosConfigurations = import ./nixos/hosts { inherit inputs outputs lib; };- homeConfigurations = import ./home/profiles;+ nixosConfigurations = import ./nixos/hosts { inherit inputs outputs lib kore; };+ homeConfigurations = import ./home/profiles { inherit kore; }; overlays = import ./overlays { inherit inputs outputs; }; };
home/profiles/default.nix
@@ -1,3 +1,5 @@+{ kore }:+ let mkProfile = hostname: {...}: { imports = [@@ -6,7 +8,4 @@ let (./. + "/${hostname}.nix") ]; };-in {- sunflower = mkProfile "sunflower";- gomphrena = mkProfile "gomphrena";-}+in builtins.mapAttrs (hostname: _: mkProfile hostname) kore.hosts
kore.json
@@ -0,0 +1,14 @@+{+ "hosts": {+ "sunflower": {+ "system": "x86_64-linux",+ "roles": ["home", "desktop"],+ "ipv4": "0.0.0.0"+ },+ "gomphrena": {+ "system": "x86_64-linux",+ "roles": ["home"],+ "ipv4": "0.0.0.0"+ }+ }+}
nixos/features/kore.nix
@@ -1,44 +1,43 @@-{ config, lib, ... }:+{ config, lib, kore, ... }: let hostOptions = with lib; {- ipv4 = mkOption {+ system = mkOption { type = types.str;+ };+ ipv4 = mkOption {+ type = types.nullOr types.str; default = null; }; roles = mkOption {- type = types.nullOr (types.listOf types.str);- default = null;+ type = types.listOf types.str;+ default = []; }; }; in { options.kore = with lib; { hosts = mkOption { type = types.attrsOf (types.submodule [{ options = hostOptions; }]);- default = null;+ default = {}; }; currentHost = mkOption { type = types.submodule [{ options = hostOptions; }];- default = null; }; }; config = {- warnings = lib.optional (!(config.kore.hosts ? ${config.networking.hostName}))+ warnings = lib.optional (!(kore.hosts ? ${config.networking.hostName})) "no configuration for ${config.networking.hostName} found"; - # TMP kore = {- hosts = {- sunflower = {- ipv4 = "0.0.0.0";- roles = [ "home" "workstation" ];- };- gomphrena = {- ipv4 = "0.0.0.0";- roles = [ "home" ];- };- };- currentHost = config.kore.hosts.${config.networking.hostName};+ hosts = kore.hosts;+ currentHost = kore.hosts.${config.networking.hostName}; };++ # /etc/hosts so machines resolve each other by name; placeholder+ # 0.0.0.0 addresses are skipped.+ networking.hosts = lib.mkMerge (lib.mapAttrsToList (name: host:+ lib.optionalAttrs (host.ipv4 != null && host.ipv4 != "0.0.0.0") {+ "${host.ipv4}" = [ "${name}.${config.networking.domain}" name ];+ }) kore.hosts); }; }
nixos/hosts/default.nix
@@ -1,9 +1,9 @@-{ inputs, outputs, lib, ... }:+{ inputs, outputs, lib, kore, ... }: let- mkSystem = system: hostname: lib.nixosSystem {- system = system;- specialArgs = { inherit inputs outputs; };+ mkSystem = hostname: host: lib.nixosSystem {+ system = host.system;+ specialArgs = { inherit inputs outputs kore; }; modules = [ ../features/global.nix ../features/kore.nix@@ -16,7 +16,4 @@ let { system.stateVersion = "25.11"; } ]; };-in {- sunflower = mkSystem "x86_64-linux" "sunflower";- gomphrena = mkSystem "x86_64-linux" "gomphrena";-}+in lib.mapAttrs mkSystem kore.hosts