Skip to content

Commit

Permalink
feat(lib): add loadfile Function.
Browse files Browse the repository at this point in the history
  • Loading branch information
shanyouli committed Oct 7, 2024
1 parent 9758acc commit 0e7ba96
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion nix/lib/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@
...
}: let
inherit (builtins) attrValues readDir pathExists concatLists;
inherit (lib) id mapAttrsToList filterAttrs hasPrefix hasSuffix nameValuePair removeSuffix mapAttrs';
inherit (lib) id mapAttrsToList filterAttrs hasPrefix hasSuffix nameValuePair removeSuffix mapAttrs' pathIsDirectory;
inherit (attrs) mapFilterAttrs';
in rec {
loadFile = fn: path: let
filePath = toString path;
in
if pathIsDirectory filePath
then fn (filePath + "/default.nix")
else if pathExists (filePath + ".nix")
then fn (filePath + ".nix")
else throw "unknown path ${path}";

mapModule = dir: fn: {namefn ? (n: removeSuffix ".nix" n), ...}:
mapAttrs' (name: _type: {
name = namefn name;
Expand Down

0 comments on commit 0e7ba96

Please sign in to comment.