about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--flake.nix47
-rw-r--r--lib/default.nix62
2 files changed, 93 insertions, 16 deletions
diff --git a/flake.nix b/flake.nix
index 750c21a..e792668 100644
--- a/flake.nix
+++ b/flake.nix
@@ -1,6 +1,5 @@
 {
   description = "personal NixOS configurations";
-
   inputs = {
     # Nixpkgs, NixOS's official repo
     nixpkgs.url = "github:nixos/nixpkgs/release-21.11";
@@ -16,20 +15,36 @@
   };
 
   # Output config, or config for NixOS system
-  outputs = { self, nixpkgs, home-manager, ... }@inputs: {
-    nixosConfigurations = {
-      # desktop
-      carmel = nixpkgs.lib.nixosSystem {
-        system = "x86_64-linux";
-        modules = [
-          ./hosts/carmel/configuration.nix
-          home-manager.nixosModules.home-manager {
-            home-manager.useGlobalPkgs = true;
-            home-manager.useUserPackages = true;
-            home-manager.users.fcuny = import ./users/fcuny/desktop.nix;
-          }
-        ];
+  outputs = { ... }@inputs:
+    let
+      lib = import ./lib { inherit inputs; };
+    in: {
+      nixosConfigurations = {
+        carmel = lib.mkSystem {
+          hostname = "carmel";
+          system = "x86_64-linux";
+          desktop = true;
+        };
       };
-    };
-  };
+
+      homeConfigurations = {
+        "fcuny@carmel" = lib.mkHome {
+          username = "fcuny";
+          system = "x86_64-linux";
+          hostname = "carmel";
+          desktop = true;
+        };
+      };
+    } // inputs.utils.lib.eachDefaultSystem (system:
+      let
+        pkgs = import inputs.nixpkgs { inherit system overlays; };
+        home-manager = inputs.home-manager.defaultPackage."${system}";
+      in
+      {
+        packages = pkgs // { inherit home-manager; };
+
+        devShell = pkgs.mkShell {
+          buildInputs = with pkgs; [ nixUnstable nixfmt rnix-lsp home-manager git ];
+        };
+      });
 }
diff --git a/lib/default.nix b/lib/default.nix
new file mode 100644
index 0000000..7f0f8ed
--- /dev/null
+++ b/lib/default.nix
@@ -0,0 +1,62 @@
+{ inputs, overlays }:
+{
+  mkSystem =
+    { hostname
+    , system
+    , desktop ? false
+    }:
+    inputs.nixpkgs.lib.nixosSystem {
+      inherit system;
+      specialArgs = {
+        inherit inputs system hostname desktop;
+      };
+      modules = [
+        ../modules/deskop
+        ../modules/system
+        ../hosts/${hostname}
+        {
+          networking.hostName = hostname;
+          # Apply overlay and allow unfree packages
+          nixpkgs = {
+            inherit overlays;
+            config.allowUnfree = true;
+          };
+          # Add each input as a registry
+          nix.registry = inputs.nixpkgs.lib.mapAttrs'
+            (n: v:
+              inputs.nixpkgs.lib.nameValuePair (n) ({ flake = v; }))
+            inputs;
+        }
+      ]
+    };
+
+  mkHome =
+    { username
+    , system
+    , hostname
+    , desktop ? false
+    }:
+    inputs.home-manager.lib.homeManagerConfiguration {
+      inherit username system;
+      extraSpecialArgs = {
+        inherit system hostname graphical;
+      };
+      homeDirectory = "/home/${username}";
+      configuration = ../users/${username};
+      extraModules = [
+        ../modules/home-manager
+        # Base configuration
+        {
+          nixpkgs = {
+            inherit overlays;
+            config.allowUnfree = true;
+          };
+          programs = {
+            home-manager.enable = true;
+            git.enable = true;
+          };
+          systemd.user.startServices = "sd-switch";
+        }
+      ];
+    };
+}