about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorsefidel <contact@sefidel.net>2021-12-28 01:11:25 +0900
committersefidel <contact@sefidel.net>2021-12-28 01:12:48 +0900
commit56992b8c945d497a623fe693847c91235be1ae02 (patch)
tree102ff8c8872d7e14ce3e3dba69bf16685374504e /lib
downloadnixrc-56992b8c945d497a623fe693847c91235be1ae02.tar.gz
nixrc-56992b8c945d497a623fe693847c91235be1ae02.zip
initial commit
Diffstat (limited to 'lib')
-rw-r--r--lib/default.nix8
-rw-r--r--lib/home_configurations_as_packages.nix12
-rw-r--r--lib/mk_home.nix20
-rw-r--r--lib/mk_system.nix25
-rw-r--r--lib/nixos_configurations_as_packages.nix12
5 files changed, 77 insertions, 0 deletions
diff --git a/lib/default.nix b/lib/default.nix
new file mode 100644
index 0000000..b75be10
--- /dev/null
+++ b/lib/default.nix
@@ -0,0 +1,8 @@
+inputs:
+
+{
+  mkSystem = import ./mk_system.nix inputs;
+  mkHome = import ./mk_home.nix inputs;
+  nixosConfigurationsAsPackages = import ./nixos_configurations_as_packages.nix inputs;
+  homeConfigurationsAsPackages = import ./home_configurations_as_packages.nix inputs;
+}
diff --git a/lib/home_configurations_as_packages.nix b/lib/home_configurations_as_packages.nix
new file mode 100644
index 0000000..41fd7b4
--- /dev/null
+++ b/lib/home_configurations_as_packages.nix
@@ -0,0 +1,12 @@
+{ self, ... } @ inputs:
+
+let
+  pkgs = import inputs.nixpkgs { system = "x86_64-linux"; };
+
+  inherit (pkgs.lib) genAttrs mapAttrs';
+
+  hostNames = __attrNames self.homeConfigurations;
+  attrHostNames = genAttrs hostNames (name: "home/config/${name}");
+  configs = mapAttrs' (name: pname: { name = pname; value = self.homeConfigurations.${name}.activationPackage; }) attrHostNames;
+in
+{ x86_64-linux = configs; }
diff --git a/lib/mk_home.nix b/lib/mk_home.nix
new file mode 100644
index 0000000..e352f5f
--- /dev/null
+++ b/lib/mk_home.nix
@@ -0,0 +1,20 @@
+{ self, home-manager, ... } @ inputs:
+
+username: hostname: system: nixpkgs: version:
+let
+  args = inputs;
+  entrypoint = "${self}/home/configurations/${username}@${hostname}.nix";
+in
+  home-manager.lib.homeManagerConfiguration {
+    inherit username system;
+    homeDirectory = "/home/${username}";
+    stateVersion = version;    
+    pkgs = nixpkgs.legacyPackages.${system};
+
+    configuration = { lib, ... }: {
+      _module = { inherit args; };
+      imports = [
+        entrypoint
+      ] ++ __attrValues self.homeModules;
+    };
+  }
diff --git a/lib/mk_system.nix b/lib/mk_system.nix
new file mode 100644
index 0000000..ee0037b
--- /dev/null
+++ b/lib/mk_system.nix
@@ -0,0 +1,25 @@
+{ self, ... } @ args:
+
+name: nixpkgs:
+nixpkgs.lib.nixosSystem (
+  let
+    configFolder = "${self}/nixos/configurations";
+    entryPoint = "${configFolder}/${name}.nix";
+    hardware = "${configFolder}/hardware/${name}.nix";
+  in
+  {
+    system = "x86_64-linux";
+
+    modules = [
+      {
+        _module.args = args;
+        networking.hostName = name;
+        nix.flakes.enable = true;
+        system.configurationRevision = self.rev or "dirty";
+        documentation.man = { enable = true; generateCaches = true; };
+      }
+      entryPoint
+      hardware
+    ] ++ __attrValues self.nixosModules;
+  }
+)
diff --git a/lib/nixos_configurations_as_packages.nix b/lib/nixos_configurations_as_packages.nix
new file mode 100644
index 0000000..f257c6d
--- /dev/null
+++ b/lib/nixos_configurations_as_packages.nix
@@ -0,0 +1,12 @@
+{ self, ... } @ inputs:
+
+let
+  pkgs = import inputs.nixpkgs { system = "x86_64-linux"; };
+
+  inherit (pkgs.lib) genAttrs mapAttrs';
+
+  hostNames = __attrNames self.nixosConfigurations;
+  attrHostNames = genAttrs hostNames (name: "nixos/config/${name}");
+  configs = mapAttrs' (name: pname: { name = pname; value = self.nixosConfigurations.${name}.config.system.build.toplevel; }) attrHostNames;
+in
+{ x86_64-linux = configs; }