From 1ee256fa62eb6372bab70f403a607c2a970b406c Mon Sep 17 00:00:00 2001 From: PerchunPak Date: Tue, 16 Apr 2024 11:19:30 +0200 Subject: [PATCH] fix: allow modules modules that are not functions --- snowfall-lib/default.nix | 14 +++++++++++--- snowfall-lib/internal/default.nix | 12 ++++++++++-- snowfall-lib/module/default.nix | 8 ++++++-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/snowfall-lib/default.nix b/snowfall-lib/default.nix index f4f560d..b59e1d7 100644 --- a/snowfall-lib/default.nix +++ b/snowfall-lib/default.nix @@ -18,7 +18,7 @@ core-inputs: user-options: let user-inputs = user-options.inputs // {src = user-options.src;}; - inherit (core-inputs.nixpkgs.lib) assertMsg fix filterAttrs mergeAttrs fold recursiveUpdate callPackageWith; + inherit (core-inputs.nixpkgs.lib) assertMsg fix filterAttrs mergeAttrs fold recursiveUpdate callPackageWith isFunction; # Recursively merge a list of attribute sets. # Type: [Attrs] -> Attrs @@ -58,7 +58,7 @@ core-inputs: user-options: let core-inputs-libs = get-libs (without-self core-inputs); user-inputs-libs = get-libs (without-self user-inputs); - # NOTE: This root is different to accomodate the creation + # NOTE: This root is different to accommodate the creation # of a fake user-lib in order to run documentation on this flake. snowfall-lib-root = "${core-inputs.src}/snowfall-lib"; snowfall-lib-dirs = let @@ -103,7 +103,15 @@ core-inputs: user-options: let }; libs = builtins.map - (path: callPackageWith attrs path {}) + ( + path: let + imported-module = import path; + in + if isFunction imported-module + then callPackageWith attrs path {} + # the only difference is that there is no `override` and `overrideDerivation` on returned value + else imported-module + ) user-lib-modules; in merge-deep libs diff --git a/snowfall-lib/internal/default.nix b/snowfall-lib/internal/default.nix index fb01412..334f3f1 100644 --- a/snowfall-lib/internal/default.nix +++ b/snowfall-lib/internal/default.nix @@ -4,7 +4,7 @@ snowfall-lib, snowfall-config, }: let - inherit (core-inputs.nixpkgs.lib) assertMsg fix fold filterAttrs callPackageWith; + inherit (core-inputs.nixpkgs.lib) fix filterAttrs callPackageWith isFunction; core-inputs-libs = snowfall-lib.flake.get-libs (snowfall-lib.flake.without-self core-inputs); user-inputs-libs = snowfall-lib.flake.get-libs (snowfall-lib.flake.without-self user-inputs); @@ -34,7 +34,15 @@ }; libs = builtins.map - (path: callPackageWith attrs path {}) + ( + path: let + imported-module = import path; + in + if isFunction imported-module + then callPackageWith attrs path {} + # the only difference is that there is no `override` and `overrideDerivation` on returned value + else imported-module + ) user-lib-modules; in snowfall-lib.attrs.merge-deep libs diff --git a/snowfall-lib/module/default.nix b/snowfall-lib/module/default.nix index 8fe7601..2a00827 100644 --- a/snowfall-lib/module/default.nix +++ b/snowfall-lib/module/default.nix @@ -5,7 +5,7 @@ snowfall-config, }: let inherit (builtins) baseNameOf; - inherit (core-inputs.nixpkgs.lib) assertMsg foldl mapAttrs hasPrefix; + inherit (core-inputs.nixpkgs.lib) foldl mapAttrs hasPrefix isFunction; user-modules-root = snowfall-lib.fs.get-snowfall-file "modules"; in { @@ -67,7 +67,11 @@ in { inputs = snowfall-lib.flake.without-src user-inputs; }; - user-module = import metadata.path modified-args; + imported-user-module = import metadata.path; + user-module = + if isFunction imported-user-module + then imported-user-module modified-args + else imported-user-module; in user-module // {_file = metadata.path;}; };