Skip to content

Commit

Permalink
fix: allow modules modules that are not functions
Browse files Browse the repository at this point in the history
  • Loading branch information
PerchunPak authored and jakehamilton committed May 20, 2024
1 parent 63a1abf commit 1ee256f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
14 changes: 11 additions & 3 deletions snowfall-lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions snowfall-lib/internal/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions snowfall-lib/module/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;};
};
Expand Down

0 comments on commit 1ee256f

Please sign in to comment.