chore: clean up the inherited clutter

This commit is contained in:
oddlama 2023-02-04 02:27:39 +01:00
parent 4da937bcd0
commit 418db9db0c
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A
6 changed files with 25 additions and 60 deletions

View file

@ -44,7 +44,7 @@
... ...
} @ inputs: } @ inputs:
{ {
hosts = import ./nix/hosts.nix; hosts = import ./nix/hosts.nix inputs;
colmena = import ./nix/colmena.nix inputs; colmena = import ./nix/colmena.nix inputs;
overlays = import ./nix/overlay.nix inputs; overlays = import ./nix/overlay.nix inputs;
homeConfigurations = import ./nix/home-manager.nix inputs; homeConfigurations = import ./nix/home-manager.nix inputs;

4
hosts/nom/meta.nix Normal file
View file

@ -0,0 +1,4 @@
{
type = "nixos";
system = "x86_64-linux";
}

4
hosts/ward/meta.nix Normal file
View file

@ -0,0 +1,4 @@
{
type = "nixos";
system = "x86_64-linux";
}

View file

@ -11,6 +11,7 @@
... ...
}: }:
with nixpkgs.lib; let with nixpkgs.lib; let
nixosHosts = filterAttrs (_: x: x.type == "nixos") self.hosts;
generateColmenaNode = hostName: _: { generateColmenaNode = hostName: _: {
imports = [ imports = [
{ {
@ -37,8 +38,8 @@ in
description = "oddlama's colmena configuration"; description = "oddlama's colmena configuration";
# Just a required dummy for colmena, overwritten on a per-node basis by nodeNixpkgs below. # Just a required dummy for colmena, overwritten on a per-node basis by nodeNixpkgs below.
nixpkgs = self.pkgs.x86_64-linux; nixpkgs = self.pkgs.x86_64-linux;
nodeNixpkgs = mapAttrs (hostName: {system, ...}: self.pkgs.${system}) (self.hosts.nixos or {}); nodeNixpkgs = mapAttrs (hostName: {system, ...}: self.pkgs.${system}) nixosHosts;
#nodeSpecialArgs = mapAttrs (hostName: { system, ... }: {}) (self.hosts.nixos or {}); #nodeSpecialArgs = mapAttrs (hostName: { system, ... }: {}) nixosHosts;
specialArgs = { specialArgs = {
inherit (nixpkgs) lib; inherit (nixpkgs) lib;
nixos-hardware = nixos-hardware.nixosModules; nixos-hardware = nixos-hardware.nixosModules;
@ -46,4 +47,4 @@ in
}; };
}; };
} }
// mapAttrs generateColmenaNode (self.hosts.nixos or {}) // mapAttrs generateColmenaNode nixosHosts

View file

@ -4,10 +4,10 @@
nixpkgs, nixpkgs,
templates, templates,
... ...
}: let }:
inherit (nixpkgs) lib; with nixpkgs.lib; let
homeManagerHosts = filterAttrs (_: x: x.type == "homeManager") self.hosts;
genModules = hostName: {homeDirectory, ...}: { moduleForHost = hostName: {homeDirectory, ...}: {
config, config,
pkgs, pkgs,
... ...
@ -22,7 +22,7 @@
home = { home = {
inherit homeDirectory; inherit homeDirectory;
sessionVariables.NIX_PATH = lib.concatStringsSep ":" [ sessionVariables.NIX_PATH = concatStringsSep ":" [
"nixpkgs=${config.xdg.dataHome}/nixpkgs" "nixpkgs=${config.xdg.dataHome}/nixpkgs"
"nixpkgs-overlays=${config.xdg.dataHome}/overlays" "nixpkgs-overlays=${config.xdg.dataHome}/overlays"
]; ];
@ -42,7 +42,7 @@
genConfiguration = hostName: {system, ...} @ attrs: genConfiguration = hostName: {system, ...} @ attrs:
home-manager.lib.homeManagerConfiguration { home-manager.lib.homeManagerConfiguration {
pkgs = self.pkgs.${system}; pkgs = self.pkgs.${system};
modules = [(genModules hostName attrs)]; modules = [(moduleForHost hostName attrs)];
}; };
in in
lib.mapAttrs genConfiguration (self.hosts.homeManager or {}) mapAttrs genConfiguration hostManagerHosts

View file

@ -1,49 +1,5 @@
with builtins; let {nixpkgs, ...}:
hosts = { nixpkgs.lib.concatMapAttrs (hostName: fileType:
nom = { if fileType == "directory"
type = "nixos"; then {${hostName} = import (../hosts + "/${hostName}/meta.nix");}
system = "x86_64-linux"; else {}) (builtins.readDir ../hosts)
};
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