mirror of
https://github.com/nix-community/srvos.git
synced 2024-10-03 18:47:28 +03:00
allow exposeModules to be shared
This commit is contained in:
parent
d6280e5c12
commit
ea3d082265
35
lib/exposeModules.nix
Normal file
35
lib/exposeModules.nix
Normal file
@ -0,0 +1,35 @@
|
||||
let
|
||||
inherit (builtins)
|
||||
listToAttrs
|
||||
replaceStrings
|
||||
stringLength
|
||||
substring
|
||||
;
|
||||
|
||||
removeSuffix =
|
||||
# Suffix to remove if it matches
|
||||
suffix:
|
||||
# Input string
|
||||
str:
|
||||
let
|
||||
sufLen = stringLength suffix;
|
||||
sLen = stringLength str;
|
||||
in
|
||||
if sufLen <= sLen && suffix == substring (sLen - sufLen) sufLen str then
|
||||
substring 0 (sLen - sufLen) str
|
||||
else
|
||||
str;
|
||||
in
|
||||
# Map 1:1 between paths and modules
|
||||
baseDir: paths:
|
||||
let
|
||||
prefix = stringLength (toString baseDir) + 1;
|
||||
|
||||
toPair = path: {
|
||||
name = replaceStrings [ "/" ] [ "-" ] (
|
||||
removeSuffix ".nix" (substring prefix 1000000 (toString path))
|
||||
);
|
||||
value = path;
|
||||
};
|
||||
in
|
||||
listToAttrs (map toPair paths)
|
@ -1,39 +1,5 @@
|
||||
let
|
||||
inherit (builtins)
|
||||
listToAttrs
|
||||
replaceStrings
|
||||
stringLength
|
||||
substring
|
||||
;
|
||||
|
||||
removeSuffix =
|
||||
# Suffix to remove if it matches
|
||||
suffix:
|
||||
# Input string
|
||||
str:
|
||||
let
|
||||
sufLen = stringLength suffix;
|
||||
sLen = stringLength str;
|
||||
in
|
||||
if sufLen <= sLen && suffix == substring (sLen - sufLen) sufLen str then
|
||||
substring 0 (sLen - sufLen) str
|
||||
else
|
||||
str;
|
||||
|
||||
# Map 1:1 between paths and modules
|
||||
exposeModules = baseDir: paths:
|
||||
let
|
||||
prefix = stringLength (toString baseDir) + 1;
|
||||
|
||||
toPair = path: {
|
||||
name = replaceStrings [ "/" ] [ "-" ] (removeSuffix ".nix" (substring prefix 1000000
|
||||
(toString path)));
|
||||
value = path;
|
||||
};
|
||||
in
|
||||
listToAttrs (map toPair paths)
|
||||
;
|
||||
|
||||
exposeModules = import ../lib/exposeModules.nix;
|
||||
in
|
||||
exposeModules ./. [
|
||||
./common
|
||||
|
Loading…
Reference in New Issue
Block a user