1
Fork 0

Refactor: Initial step

- Added library for common functions
- Moved machines/ to hosts/
- Automise adding new hosts to the flake
This commit is contained in:
caem 2024-07-25 21:24:28 +02:00
parent 95b9318585
commit 1ea937f884
Signed by: caem
GPG key ID: 69A830D03203405F
7 changed files with 54 additions and 5 deletions

View file

@ -22,10 +22,13 @@
};
outputs = { nixpkgs, impermanence, home-manager, aagl, nur, ... } @ inputs:
let
lib = nixpkgs.lib.extend (final: prev:
import ./lib { lib = final; }
);
in
{
nixosConfigurations.workstation = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = { inherit inputs; } ;
nixosConfigurations = lib.mkHosts {
modules = [
home-manager.nixosModules.home-manager {
home-manager.sharedModules = [
@ -35,9 +38,9 @@
impermanence.nixosModules.impermanence
nur.nixosModules.nur
aagl.nixosModules.default
./machines/workstation/configuration.nix
];
nixpkgs = nixpkgs;
inputs = inputs;
};
};
}

10
lib/default.nix Normal file
View file

@ -0,0 +1,10 @@
{ lib }:
# todo: Write a function to import all of these automatically
let
fs = import ./fs.nix { inherit lib; };
hosts = import ./hosts.nix { inherit lib; };
in
fs // hosts

10
lib/fs.nix Normal file
View file

@ -0,0 +1,10 @@
{ lib }:
{
getDirsInDir =
path: let
dirs = builtins.readDir path;
in
builtins.filter (name: dirs.${name} == "directory") (builtins.attrNames dirs);
}

26
lib/hosts.nix Normal file
View file

@ -0,0 +1,26 @@
{ lib }:
{
mkHosts = {
modules,
nixpkgs,
inputs,
path ? (builtins.toString ../hosts),
}: let
hosts = lib.getDirsInDir path;
common = {
system = "x86_64-linux";
modules = modules;
};
in
builtins.trace "Hosts found: ${builtins.toString hosts}"
builtins.trace "Path being used: ${path}"
builtins.listToAttrs (builtins.map (host: {
name = host;
value = nixpkgs.lib.nixosSystem {
system = common.system;
modules = common.modules ++ [ ../hosts/${host} ];
specialArgs = { inherit inputs; };
};
}) hosts);
}