mirror of
https://github.com/nix-community/srvos.git
synced 2024-09-11 14:17:02 +03:00
36 lines
713 B
Nix
36 lines
713 B
Nix
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)
|