From 3c2708b263af6f225c3f4ff9273509d52e036af5 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Tue, 1 Apr 2025 15:39:02 +0200 Subject: [PATCH] feat(lib/buildClan): turn lib/build-clan into a 'buildClanModule' with sub-features such as 'buildClan' and 'flakePartsModule' --- flakeModules/clan.nix | 5 ++- lib/build-clan/default.nix | 78 +++++++++++++++++++++++--------------- lib/default.nix | 4 +- 3 files changed, 54 insertions(+), 33 deletions(-) diff --git a/flakeModules/clan.nix b/flakeModules/clan.nix index 66dfe9f05..e50192dee 100644 --- a/flakeModules/clan.nix +++ b/flakeModules/clan.nix @@ -9,6 +9,8 @@ clan-core: }: let inherit (lib) types; + + buildClanModule = clan-core.clanLib.buildClanModule; in { @@ -20,8 +22,7 @@ in inherit (inputs) nixpkgs; }; modules = [ - ../lib/build-clan/interface.nix - ../lib/build-clan/module.nix + buildClanModule.flakePartsModule ]; }; }; diff --git a/lib/build-clan/default.nix b/lib/build-clan/default.nix index 826cf08da..f412bd038 100644 --- a/lib/build-clan/default.nix +++ b/lib/build-clan/default.nix @@ -6,36 +6,54 @@ nixpkgs, clan-core, }: -{ - ## Inputs - self ? lib.warn "Argument: 'self' must be set when using 'buildClan'." null, # Reference to the current flake - # allows to include machine-specific modules i.e. machines.${name} = { ... } - # A map from arch to pkgs, if specified this nixpkgs will be only imported once for each system. - # This improves performance, but all nipxkgs.* options will be ignored. - # deadnix: skip - inventory ? { }, - ## Special inputs (not passed to the module system as config) - specialArgs ? { }, # Extra arguments to pass to nixosSystem i.e. useful to make self available # A set containing clan meta: name :: string, icon :: string, description :: string - ## - ... -}@attrs: let - eval = import ./function-adapter.nix { - inherit - lib - nixpkgs - clan-core - self - ; - inherit specialArgs; - }; - - rest = builtins.removeAttrs attrs [ "specialArgs" ]; -in -eval { - imports = [ - rest - # implementation - ./module.nix + clanResultAttributes = [ + "clanInternals" + "nixosConfigurations" ]; +in +{ + inherit clanResultAttributes; + flakePartsModule = { + imports = [ + ./interface.nix + ./module.nix + ]; + }; + /** + Function that returns the same result as the correlated flake-parts module + */ + buildClan = + { + ## Inputs + self ? lib.warn "Argument: 'self' must be set when using 'buildClan'." null, # Reference to the current flake + # allows to include machine-specific modules i.e. machines.${name} = { ... } + # A map from arch to pkgs, if specified this nixpkgs will be only imported once for each system. + # This improves performance, but all nipxkgs.* options will be ignored. + # deadnix: skip + inventory ? { }, + ## Special inputs (not passed to the module system as config) + specialArgs ? { }, # Extra arguments to pass to nixosSystem i.e. useful to make self available # A set containing clan meta: name :: string, icon :: string, description :: string + ## + ... + }@attrs: + let + eval = import ./function-adapter.nix { + inherit + lib + nixpkgs + clan-core + self + ; + inherit specialArgs; + }; + rest = builtins.removeAttrs attrs [ "specialArgs" ]; + in + eval { + imports = [ + rest + # implementation + ./module.nix + ]; + }; } diff --git a/lib/default.nix b/lib/default.nix index 59b6a873c..1190541bd 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -20,10 +20,12 @@ lib.fix (clanLib: { clan-core = self; pkgs = nixpkgs.legacyPackages.x86_64-linux; }; - buildClan = import ./build-clan { + + buildClanModule = import ./build-clan { inherit lib nixpkgs; clan-core = self; }; + buildClan = clanLib.buildClanModule.buildClan; # ------------------------------------ # Lib functions that don't depend on 'self' inventory = clanLib.callLib ./inventory { };