1
1
Fork 1
mirror of https://github.com/oddlama/nix-config.git synced 2025-10-11 07:10:39 +02:00

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:
{
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;

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
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

View file

@ -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

View file

@ -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)