-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Arnold
committed
Apr 14, 2021
1 parent
bcfc9d3
commit 33bcda7
Showing
1 changed file
with
42 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,47 @@ | ||
{ flake-utils-plus }: let | ||
|
||
modulesFromListExporter = | ||
|
||
let | ||
|
||
removeSuffix = suffix: str: | ||
let | ||
sufLen = builtins.stringLength suffix; | ||
sLen = builtins.stringLength str; | ||
in | ||
if sufLen <= sLen && suffix == builtins.substring (sLen - sufLen) sufLen str then | ||
builtins.substring 0 (sLen - sufLen) str | ||
else | ||
str; | ||
|
||
genAttrs' = func: values: builtins.listToAttrs (map func values); | ||
|
||
in | ||
|
||
paths: genAttrs' | ||
(path: { | ||
name = removeSuffix ".nix" (baseNameOf path); | ||
value = import path; | ||
}) | ||
paths; | ||
modulesFromListExporter = paths: | ||
/** | ||
Synopsis: modulesFromListExporter _paths_ | ||
paths: [ <path> <path> ] | ||
Returns an attribute set of modules from a list of paths by converting | ||
the path's basename into the attribute key. | ||
Example: | ||
paths: [ ./path/to/moduleA.nix ./path/to/moduleBfolder ] | ||
{ | ||
moduleA = import ./path/to/moduleA.nix; | ||
moduleBfolder = import ./path/to/moduleBfolder; | ||
} | ||
**/ | ||
|
||
let | ||
|
||
removeSuffix = suffix: str: | ||
let | ||
sufLen = builtins.stringLength suffix; | ||
sLen = builtins.stringLength str; | ||
in | ||
if sufLen <= sLen && suffix == builtins.substring (sLen - sufLen) sufLen str then | ||
builtins.substring 0 (sLen - sufLen) str | ||
else | ||
str; | ||
|
||
genAttrs' = func: values: builtins.listToAttrs (map func values); | ||
|
||
in | ||
|
||
genAttrs' | ||
(path: { | ||
name = removeSuffix ".nix" (baseNameOf path); | ||
value = import path; | ||
}) | ||
paths; | ||
|
||
in | ||
modulesFromListExporter |