diff --git a/flake.nix b/flake.nix index b6138bf..a320136 100644 --- a/flake.nix +++ b/flake.nix @@ -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; }; }; } diff --git a/machines/workstation/configuration.nix b/hosts/workstation/default.nix similarity index 100% rename from machines/workstation/configuration.nix rename to hosts/workstation/default.nix diff --git a/machines/workstation/hardware-configuration.nix b/hosts/workstation/hardware-configuration.nix similarity index 100% rename from machines/workstation/hardware-configuration.nix rename to hosts/workstation/hardware-configuration.nix diff --git a/machines/workstation/persist.nix b/hosts/workstation/persist.nix similarity index 100% rename from machines/workstation/persist.nix rename to hosts/workstation/persist.nix diff --git a/lib/default.nix b/lib/default.nix new file mode 100644 index 0000000..c62cc11 --- /dev/null +++ b/lib/default.nix @@ -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 + diff --git a/lib/fs.nix b/lib/fs.nix new file mode 100644 index 0000000..cb8d639 --- /dev/null +++ b/lib/fs.nix @@ -0,0 +1,10 @@ +{ lib }: + +{ + getDirsInDir = + path: let + dirs = builtins.readDir path; + in + builtins.filter (name: dirs.${name} == "directory") (builtins.attrNames dirs); +} + diff --git a/lib/hosts.nix b/lib/hosts.nix new file mode 100644 index 0000000..4460eb9 --- /dev/null +++ b/lib/hosts.nix @@ -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); +}