aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorCollin Williams <96917990+bluedragon1221@users.noreply.github.com>2025-09-19 17:32:27 -0500
committerCollin Williams <96917990+bluedragon1221@users.noreply.github.com>2025-09-19 17:32:27 -0500
commite63f4bda23477436bee8b30db73cf8deba4a8a5f (patch)
tree5897ba5e2e24c633d3c96b8d43213138118c6737 /lib
parent6291fefa5741f201f29e2916ca29b93bcc6b7fc8 (diff)
parent5d0d346f838a7711fa79eb6edab828107b95a499 (diff)
merge changes from main
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.nix2
-rw-r--r--lib/nix-furnace/default.nix102
-rw-r--r--lib/nix-furnace/mkSystem.nix119
3 files changed, 121 insertions, 102 deletions
diff --git a/lib/lib.nix b/lib/lib.nix
index 5310a6d..640f0ca 100644
--- a/lib/lib.nix
+++ b/lib/lib.nix
@@ -49,4 +49,6 @@ let
in {
inherit globimport;
inherit options;
+
+ flatten = builtins.foldl' (a: b: a ++ b) [];
}
diff --git a/lib/nix-furnace/default.nix b/lib/nix-furnace/default.nix
deleted file mode 100644
index 303730e..0000000
--- a/lib/nix-furnace/default.nix
+++ /dev/null
@@ -1,102 +0,0 @@
-let
- my-lib = import ../lib.nix;
- inherit (my-lib.globimport) lazyImport getSubdirs getSubfiles;
-
- mkHomeImports = modName: [
- (lazyImport ../../modules/${modName}/options.nix)
- (lazyImport ../../modules/${modName}/home/default.nix)
- ];
- mkSystemImports = modName: [
- (lazyImport ../../modules/${modName}/options.nix)
- (lazyImport ../../modules/${modName}/system/default.nix)
- ];
-
- mkModules = mapFn: {
- imports =
- [../../modules/options.nix]
- ++ (builtins.foldl' (a: b: a ++ b) [] (builtins.map mapFn (getSubdirs ../../modules)));
- };
-
- mkHomeModules = mkModules mkHomeImports;
- mkSystemModules = mkModules mkSystemImports;
-
- mkHost = {
- hostname,
- namespace,
- inputs,
- ...
- }: let
- preloadedConfig = import ../../hosts/${hostname}/config.nix {inherit inputs;};
- username = preloadedConfig."${namespace}".user.name;
-
- furnaceOptions = {lib, ...}: let
- inherit (lib) mkOption types;
- in {
- options.nix-furnace = {
- extraHomeModules = mkOption {
- type = with types; listOf path;
- default = [];
- };
-
- extraSystemModules = mkOption {
- type = with types; listOf path;
- default = [];
- };
- };
- };
-
- specialArgs = {inherit inputs my-lib;};
- in
- inputs.nixpkgs.lib.nixosSystem {
- inherit specialArgs;
- modules =
- [
- {networking.hostName = hostname;}
-
- ../../hosts/${hostname}/config.nix
-
- mkSystemModules
-
- furnaceOptions
-
- # Home-manager
- inputs.home-manager.nixosModules.home-manager
- {
- home-manager = {
- backupFileExtension = "bak";
- useGlobalPkgs = true;
- useUserPackages = true;
- extraSpecialArgs = specialArgs;
- users."${username}" = {
- imports =
- [
- mkHomeModules
-
- furnaceOptions
-
- ../../hosts/${hostname}/config.nix
- ]
- ++ preloadedConfig.nix-furnace.extraHomeModules;
- };
- };
- }
- ]
- ++ preloadedConfig.nix-furnace.extraSystemModules;
- };
-
- mkFlake = {
- namespace,
- inputs,
- ...
- }: {
- nixosConfigurations =
- builtins.listToAttrs
- (builtins.map (hostname: {
- name = hostname;
- value = mkHost {inherit inputs hostname namespace;};
- })
- (getSubdirs ../../hosts));
- };
-in {
- inherit mkFlake;
-}
diff --git a/lib/nix-furnace/mkSystem.nix b/lib/nix-furnace/mkSystem.nix
new file mode 100644
index 0000000..cf14f4a
--- /dev/null
+++ b/lib/nix-furnace/mkSystem.nix
@@ -0,0 +1,119 @@
+let
+ my-lib = import ../lib.nix;
+ inherit (my-lib.globimport) getSubdirs lazyImport;
+
+ listModules = getSubdirs ../../modules;
+
+ mkNixosSystem = {
+ inputs,
+ hostname,
+ username,
+ module_types,
+ }:
+ inputs.nixpkgs.lib.nixosSystem {
+ specialArgs = {inherit inputs my-lib;};
+ modules = [
+ {networking.hostName = hostname;}
+
+ ../../hosts/${hostname}/config.nix
+
+ # Nixos-sided modules
+ {
+ imports =
+ [
+ ../../modules/options.nix
+ ../../hosts/${hostname}/config.nix
+ (lazyImport ../../hosts/${hostname}/nixos.nix)
+ ]
+ ++ (listModules
+ |> (builtins.map (modName: [
+ (lazyImport ../../modules/${modName}/options.nix)
+ (lazyImport ../../modules/${modName}/nixos/default.nix)
+ ]))
+ |> my-lib.flatten);
+ }
+
+ # Home-sided modules
+ (
+ if (builtins.elem "home" module_types)
+ then {
+ imports = [
+ inputs.home-manager.nixosModules.home-manager
+ ];
+ home-manager = {
+ backupFileExtension = "bak";
+ useGlobalPkgs = true;
+ useUserPackages = true;
+ extraSpecialArgs = {inherit inputs my-lib;};
+ users.${username} = {
+ imports =
+ [
+ ../../modules/options.nix
+ ../../hosts/${hostname}/config.nix
+ (lazyImport ../../hosts/${hostname}/home.nix)
+ {
+ home.preferXdgDirectories = true;
+ }
+ ]
+ ++ (listModules
+ |> (builtins.map (modName: [
+ (lazyImport ../../modules/${modName}/options.nix)
+ (lazyImport ../../modules/${modName}/home/default.nix)
+ ]))
+ |> my-lib.flatten);
+ };
+ };
+ }
+ else {}
+ )
+
+ # Hjem-sided modules
+ (
+ if (builtins.elem "hjem" module_types)
+ then {
+ imports = [
+ inputs.hjem.nixosModules.hjem
+ ];
+ hjem = {
+ extraModules =
+ [
+ ../../modules/options.nix
+ ../../hosts/${hostname}/config.nix
+ (lazyImport ../../hosts/${hostname}/hjem.nix)
+ ]
+ ++ (listModules
+ |> (builtins.map (modName: [
+ (lazyImport ../../modules/${modName}/options.nix)
+ (lazyImport ../../modules/${modName}/hjem/default.nix)
+ ]))
+ |> my-lib.flatten);
+ specialArgs = {inherit inputs my-lib;};
+ users.${username} = {
+ enable = true;
+ user = username;
+ directory = "/home/${username}";
+ };
+ };
+ }
+ else {}
+ )
+ ];
+ };
+
+ mkSystemManagerSystem = {
+ inputs,
+ hostname,
+ }:
+ inputs.system-manager.lib.makeSystemConfig {
+ modules =
+ [../../modules/options.nix ../../hosts/${hostname}/system.nix]
+ ++ (listModules
+ |> (builtins.map (modName: [
+ (lazyImport ../../modules/${modName}/options.nix)
+ (lazyImport ../../modules/${modName}/system/default.nix)
+ ]))
+ |> my-lib.flatten);
+ };
+in {
+ inherit mkNixosSystem mkSystemManagerSystem;
+}