about summary refs log tree commit diff
path: root/nix/lib
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2024-12-08 13:58:02 -0800
committerFranck Cuny <franck@fcuny.net>2024-12-08 15:35:17 -0800
commit52ac07299f2342afe0c309f3b8be3ea05c7549ff (patch)
treebad76e67ba8a1f9301eb87a8c5e66c8a5a260e76 /nix/lib
parentadd targets to create virtual machines (diff)
downloadworld-52ac07299f2342afe0c309f3b8be3ea05c7549ff.tar.gz
refactor overall configuration
The configuration of the various hosts and home-manager was becoming a
bit complex for no valid reasons. Try to simplify this a bit.
Diffstat (limited to '')
-rw-r--r--nix/lib/mkSystem.nix50
1 files changed, 50 insertions, 0 deletions
diff --git a/nix/lib/mkSystem.nix b/nix/lib/mkSystem.nix
new file mode 100644
index 0000000..dbacac6
--- /dev/null
+++ b/nix/lib/mkSystem.nix
@@ -0,0 +1,50 @@
+# This function creates a NixOS system based on our VM setup for a
+# particular architecture.
+{ nixpkgs, inputs }:
+
+name:
+{ system, user, darwin ? false, }:
+
+let
+  # The config files for this system.
+  machineConfig = ../machines/${name}.nix;
+  userOSConfig = ../users/${user}/${if darwin then "darwin" else "nixos"}.nix;
+  userHMConfig = ../users/${user}/home-manager.nix;
+
+  # NixOS vs nix-darwin functionst
+  systemFunc =
+    if darwin then inputs.darwin.lib.darwinSystem else nixpkgs.lib.nixosSystem;
+  home-manager =
+    if darwin then
+      inputs.home-manager.darwinModules
+    else
+      inputs.home-manager.nixosModules;
+in
+systemFunc rec {
+  inherit system;
+
+  modules = [
+    # Allow unfree packages.
+    { nixpkgs.config.allowUnfree = true; }
+
+    machineConfig
+    userOSConfig
+    home-manager.home-manager
+    {
+      home-manager.useGlobalPkgs = true;
+      home-manager.useUserPackages = true;
+      home-manager.users.${user} = import userHMConfig { inputs = inputs; };
+    }
+
+    # We expose some extra arguments so that our modules can parameterize
+    # better based on these values.
+    {
+      config._module.args = {
+        currentSystem = system;
+        currentSystemName = name;
+        currentSystemUser = user;
+        inputs = inputs;
+      };
+    }
+  ];
+}