From 418db9db0c68787211a41732bf00e310c1cab745 Mon Sep 17 00:00:00 2001 From: oddlama Date: Sat, 4 Feb 2023 02:27:39 +0100 Subject: [PATCH] chore: clean up the inherited clutter --- flake.nix | 2 +- hosts/nom/meta.nix | 4 ++++ hosts/ward/meta.nix | 4 ++++ nix/colmena.nix | 7 +++--- nix/home-manager.nix | 14 ++++++------ nix/hosts.nix | 54 ++++---------------------------------------- 6 files changed, 25 insertions(+), 60 deletions(-) create mode 100644 hosts/nom/meta.nix create mode 100644 hosts/ward/meta.nix diff --git a/flake.nix b/flake.nix index ed5310d..f8e031c 100644 --- a/flake.nix +++ b/flake.nix @@ -44,7 +44,7 @@ ... } @ inputs: { - hosts = import ./nix/hosts.nix; + hosts = import ./nix/hosts.nix inputs; colmena = import ./nix/colmena.nix inputs; overlays = import ./nix/overlay.nix inputs; homeConfigurations = import ./nix/home-manager.nix inputs; diff --git a/hosts/nom/meta.nix b/hosts/nom/meta.nix new file mode 100644 index 0000000..df2fdb0 --- /dev/null +++ b/hosts/nom/meta.nix @@ -0,0 +1,4 @@ +{ + type = "nixos"; + system = "x86_64-linux"; +} diff --git a/hosts/ward/meta.nix b/hosts/ward/meta.nix new file mode 100644 index 0000000..df2fdb0 --- /dev/null +++ b/hosts/ward/meta.nix @@ -0,0 +1,4 @@ +{ + type = "nixos"; + system = "x86_64-linux"; +} diff --git a/nix/colmena.nix b/nix/colmena.nix index 3343829..92402f3 100644 --- a/nix/colmena.nix +++ b/nix/colmena.nix @@ -11,6 +11,7 @@ ... }: with nixpkgs.lib; let + nixosHosts = filterAttrs (_: x: x.type == "nixos") self.hosts; generateColmenaNode = hostName: _: { imports = [ { @@ -37,8 +38,8 @@ in description = "oddlama's colmena configuration"; # Just a required dummy for colmena, overwritten on a per-node basis by nodeNixpkgs below. nixpkgs = self.pkgs.x86_64-linux; - nodeNixpkgs = mapAttrs (hostName: {system, ...}: self.pkgs.${system}) (self.hosts.nixos or {}); - #nodeSpecialArgs = mapAttrs (hostName: { system, ... }: {}) (self.hosts.nixos or {}); + nodeNixpkgs = mapAttrs (hostName: {system, ...}: self.pkgs.${system}) nixosHosts; + #nodeSpecialArgs = mapAttrs (hostName: { system, ... }: {}) nixosHosts; specialArgs = { inherit (nixpkgs) lib; nixos-hardware = nixos-hardware.nixosModules; @@ -46,4 +47,4 @@ in }; }; } - // mapAttrs generateColmenaNode (self.hosts.nixos or {}) + // mapAttrs generateColmenaNode nixosHosts diff --git a/nix/home-manager.nix b/nix/home-manager.nix index 77d76e0..e15c396 100644 --- a/nix/home-manager.nix +++ b/nix/home-manager.nix @@ -4,10 +4,10 @@ nixpkgs, templates, ... -}: let - inherit (nixpkgs) lib; - - genModules = hostName: {homeDirectory, ...}: { +}: +with nixpkgs.lib; let + homeManagerHosts = filterAttrs (_: x: x.type == "homeManager") self.hosts; + moduleForHost = hostName: {homeDirectory, ...}: { config, pkgs, ... @@ -22,7 +22,7 @@ home = { inherit homeDirectory; - sessionVariables.NIX_PATH = lib.concatStringsSep ":" [ + sessionVariables.NIX_PATH = concatStringsSep ":" [ "nixpkgs=${config.xdg.dataHome}/nixpkgs" "nixpkgs-overlays=${config.xdg.dataHome}/overlays" ]; @@ -42,7 +42,7 @@ genConfiguration = hostName: {system, ...} @ attrs: home-manager.lib.homeManagerConfiguration { pkgs = self.pkgs.${system}; - modules = [(genModules hostName attrs)]; + modules = [(moduleForHost hostName attrs)]; }; in - lib.mapAttrs genConfiguration (self.hosts.homeManager or {}) + mapAttrs genConfiguration hostManagerHosts diff --git a/nix/hosts.nix b/nix/hosts.nix index c193400..ec0822f 100644 --- a/nix/hosts.nix +++ b/nix/hosts.nix @@ -1,49 +1,5 @@ -with builtins; let - hosts = { - nom = { - type = "nixos"; - system = "x86_64-linux"; - }; - ward = { - type = "nixos"; - system = "x86_64-linux"; - }; - }; - - filterAttrs = pred: set: - listToAttrs (concatMap (name: let - value = set.${name}; - in - if pred name value - then [{inherit name value;}] - else []) (attrNames set)); - - removeEmptyAttrs = filterAttrs (_: v: v != {}); - - # TODO: so much strange shit - genSystemGroups = hosts: let - systems = ["aarch64-linux" "x86_64-linux"]; - systemHostGroup = name: { - inherit name; - value = filterAttrs (_: host: host.system == name) hosts; - }; - in - removeEmptyAttrs (listToAttrs (map systemHostGroup systems)); - - genTypeGroups = hosts: let - types = ["homeManager" "nixos"]; - typeHostGroup = name: { - inherit name; - value = filterAttrs (_: host: host.type == name) hosts; - }; - in - removeEmptyAttrs (listToAttrs (map typeHostGroup types)); - - genHostGroups = hosts: let - all = hosts; - systemGroups = genSystemGroups all; - typeGroups = genTypeGroups all; - in - all // systemGroups // typeGroups // {inherit all;}; -in - genHostGroups hosts +{nixpkgs, ...}: +nixpkgs.lib.concatMapAttrs (hostName: fileType: + if fileType == "directory" + then {${hostName} = import (../hosts + "/${hostName}/meta.nix");} + else {}) (builtins.readDir ../hosts)