diff --git a/nix/configurations.nix b/nix/configurations.nix index 93fa7e4..9e20042 100644 --- a/nix/configurations.nix +++ b/nix/configurations.nix @@ -1,9 +1,31 @@ -{ config, ... }: +{ + config, + lib, + inputs, + ... +}: let - inherit (cfg.lib) extractConfigurations; + inherit (lib) nixosSystem; + inherit (cfg.lib) flattenAttrs; + inherit (lib.attrsets) mapAttrs; cfg = config.flake; hosts = cfg.manifest.hosts or { }; + mkConfigurations = + class: hosts: + mapAttrs ( + _: value: + if class == "nixos" then + nixosSystem { + specialArgs = { inherit inputs; }; + modules = [ + (flattenAttrs cfg.modules.nixos) + (value.extraCfg or { }) + ]; + } + else + { } + ) hosts; in { - flake.nixosConfigurations = extractConfigurations "nixos/" hosts; + flake.nixosConfigurations = mkConfigurations "nixos" hosts.nixos; } diff --git a/nix/lib/default.nix b/nix/lib/default.nix index 29a3ae5..710a658 100644 --- a/nix/lib/default.nix +++ b/nix/lib/default.nix @@ -1,59 +1,9 @@ -{ - lib, - config, - inputs, - ... -}: +{ lib, ... }: let - cfg = config.flake; - inherit (lib.trivial) pipe; - inherit (lib.strings) removePrefix hasPrefix; - inherit (lib.attrsets) - concatMapAttrs - mapAttrs' - filterAttrs - mergeAttrsList - ; + inherit (lib.attrsets) concatMapAttrs; in { - flake.lib = rec { + flake.lib = { flattenAttrs = attrset: concatMapAttrs (_: v: v) attrset; - mkSystem = - prefix: name: value: - let - hostName = removePrefix prefix name; - hostConfig = value; - flakeConfig = config; - mkProfileCfg = - profileList: # List of attrsets of nixos configs - pipe profileList [ - (map flattenAttrs) # List of nixos configs - mergeAttrsList - ]; - in - { - name = hostName; - value = lib.nixosSystem { - specialArgs = { - inherit - inputs - hostName - hostConfig - flakeConfig - ; - }; - modules = [ - (flattenAttrs cfg.modules.nixos) - (mkProfileCfg (value.profiles or [ ])) - (value.extraCfg or { }) - ]; - }; - }; - extractConfigurations = - prefix: hosts: - pipe hosts [ - (filterAttrs (name: _: hasPrefix prefix name)) - (mapAttrs' (mkSystem prefix)) - ]; }; } diff --git a/nix/manifest.nix b/nix/manifest.nix index b6e0648..39e05fd 100644 --- a/nix/manifest.nix +++ b/nix/manifest.nix @@ -1,3 +1,4 @@ + let testCfg = { hostName, ... }: @@ -21,8 +22,8 @@ in shell = "fish"; pubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILdsZyY3gu8IGB8MzMnLdh+ClDxQQ2RYG9rkeetIKq8n rafiq"; }; - hosts = { - "nixos/nemesis" = { + hosts.nixos = { + nemesis = { machine = { platform = "amd"; gpu = "nvidia"; @@ -38,7 +39,7 @@ in }; extraCfg = testCfg; }; - "nixos/apollo" = { + apollo = { machine = { platform = "intel"; root.drive = "/dev/disk/by-id/nvme-eui.002538d221b47b01";