From 156895041071e0bf286787fbe474a9086eeecc59 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Thu, 26 Jun 2025 13:56:14 +0200 Subject: [PATCH] refactor: simplify buildClan remove any filtering --- lib/modules/default.nix | 53 +++++++++++--------------------- lib/modules/function-adapter.nix | 28 ----------------- lib/modules/tests.nix | 29 ++++++----------- 3 files changed, 28 insertions(+), 82 deletions(-) delete mode 100644 lib/modules/function-adapter.nix diff --git a/lib/modules/default.nix b/lib/modules/default.nix index a1f52072f..f8dbfa9fd 100644 --- a/lib/modules/default.nix +++ b/lib/modules/default.nix @@ -6,7 +6,8 @@ clanLib, ... }: -{ +rec { + # TODO: rename to clanModule flakePartsModule = { _module.args = { inherit clanLib; @@ -34,53 +35,35 @@ Public attributes of buildClan. As specified in publicAttrs. */ buildClanWith = - { clan-core, # TODO: Below should be module options such that the user can override them? nixpkgs, - publicAttrs ? import ./public.nix, nix-darwin ? null, }: { ## 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 - ## ... - }@attrs: + }@m: let - eval = import ./function-adapter.nix { - inherit - lib - nixpkgs - nix-darwin - clan-core - self - ; - inherit specialArgs; - }; - rest = builtins.removeAttrs attrs [ "specialArgs" ]; - result = eval { - imports = [ - rest - # implementation - ./clan/module.nix + result = lib.evalModules { + specialArgs = { + inherit (clan-core) clanLib; + inherit + self + clan-core + nixpkgs + nix-darwin + ; + }; + modules = [ + # buildClan arguments are equivalent to specifying a module + m + flakePartsModule ]; }; in - { - clan = lib.genAttrs publicAttrs.clan ( - name: - result.clanInternals.${name} - or (throw "Output: clanInternals.${name} not found. Check: ${result.file}") - ); - } - // lib.filterAttrs (name: _v: builtins.elem name publicAttrs.topLevel) result; + result.config; } diff --git a/lib/modules/function-adapter.nix b/lib/modules/function-adapter.nix deleted file mode 100644 index 6380cead3..000000000 --- a/lib/modules/function-adapter.nix +++ /dev/null @@ -1,28 +0,0 @@ -{ - lib, - nixpkgs, - nix-darwin ? null, - clan-core, - self, - specialArgs ? { }, -}: -# Returns a function that takes self, which should point to the directory of the flake -module: -(lib.evalModules { - specialArgs = { - inherit (clan-core) clanLib; - inherit - self - clan-core - nixpkgs - nix-darwin - ; - }; - modules = [ - ./clan/default.nix - module - { - inherit specialArgs; - } - ]; -}).config diff --git a/lib/modules/tests.nix b/lib/modules/tests.nix index 77d17aeea..c9d8f1be0 100644 --- a/lib/modules/tests.nix +++ b/lib/modules/tests.nix @@ -1,58 +1,49 @@ { lib, - nixpkgs, clan-core, - buildClan, ... }: let - evalClan = import ./function-adapter.nix { - inherit lib nixpkgs clan-core; - self = ./.; - }; - # Shallowly force all attribute values to be evaluated. shallowForceAllAttributes = lib.foldlAttrs ( _acc: _name: value: lib.seq value true ) true; + inherit (clan-core.clanLib) buildClan; in ####### { test_missing_self = let - config = buildClan { + clan = buildClan { meta.name = "test"; - imports = [ ./clan/module.nix ]; + directory = ./.; }; in { - expr = shallowForceAllAttributes config; - expectedError = { - type = "ThrownError"; - msg = "A definition for option `directory' is not of type `absolute path*"; - }; + inherit clan; + expr = shallowForceAllAttributes clan; + expected = true; }; test_only_required = let - config = evalClan { + clan = buildClan { self = { inputs = { }; outPath = ./.; }; meta.name = "test"; - imports = [ ./clan/module.nix ]; }; in { - expr = shallowForceAllAttributes config; + expr = shallowForceAllAttributes clan; expected = true; }; test_all_simple = let - config = evalClan { + config = buildClan { self = { inputs = { }; }; @@ -70,7 +61,7 @@ in test_outputs_clanInternals = let - config = evalClan { + config = buildClan { self = { inputs = { }; };