From 56992b8c945d497a623fe693847c91235be1ae02 Mon Sep 17 00:00:00 2001 From: sefidel Date: Tue, 28 Dec 2021 01:11:25 +0900 Subject: initial commit --- lib/default.nix | 8 ++++++++ lib/home_configurations_as_packages.nix | 12 ++++++++++++ lib/mk_home.nix | 20 ++++++++++++++++++++ lib/mk_system.nix | 25 +++++++++++++++++++++++++ lib/nixos_configurations_as_packages.nix | 12 ++++++++++++ 5 files changed, 77 insertions(+) create mode 100644 lib/default.nix create mode 100644 lib/home_configurations_as_packages.nix create mode 100644 lib/mk_home.nix create mode 100644 lib/mk_system.nix create mode 100644 lib/nixos_configurations_as_packages.nix (limited to 'lib') 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; } -- cgit 1.4.1