nixos-manual: Simplify stripping prefixes
Let's use a simple (unflipped) fold and break out the actual core stripPrefix function from stripAnyPrefixes (I personally love point-less^H^H^H^Hfree style but if I'd be anal I'd even go further and factor away the "fn:"). Also, let's use path as a better name for "fn" (filename), because that's what it is and also cannot be confused with "fn" meaning "function". We now toString all of the prefixes, so there shouldn't be any need to implicily toString the extraSources anymore. Signed-off-by: aszlig <aszlig@redmoonstudios.org>
This commit is contained in:
parent
a581f72f22
commit
ae466ba15c
1 changed files with 10 additions and 10 deletions
|
@ -17,7 +17,7 @@ let
|
|||
|
||||
# Clean up declaration sites to not refer to the NixOS source tree.
|
||||
optionsList' = flip map optionsList (opt: opt // {
|
||||
declarations = map (fn: stripAnyPrefixes fn) opt.declarations;
|
||||
declarations = map stripAnyPrefixes opt.declarations;
|
||||
}
|
||||
// optionalAttrs (opt ? example) { example = substFunction opt.example; }
|
||||
// optionalAttrs (opt ? default) { default = substFunction opt.default; }
|
||||
|
@ -28,16 +28,16 @@ let
|
|||
# or else the build will fail.
|
||||
#
|
||||
# E.g. if some `options` came from modules in ${pkgs.customModules}/nix,
|
||||
# you'd need to include `extraSources = [ "#{pkgs.customModules}" ]`
|
||||
herePrefix = toString ../../..;
|
||||
prefixesToStrip = [ herePrefix ] ++ extraSources;
|
||||
# you'd need to include `extraSources = [ pkgs.customModules ]`
|
||||
prefixesToStrip = map toString ([ ../../.. ] ++ extraSources);
|
||||
|
||||
stripAnyPrefixes = fn:
|
||||
flip (flip fold fn) prefixesToStrip (prefix: fn:
|
||||
if substring 0 (stringLength prefix) fn == prefix then
|
||||
substring (stringLength prefix + 1) 1000 fn
|
||||
else
|
||||
fn);
|
||||
stripPrefix = prefix: fullPath:
|
||||
if substring 0 (stringLength prefix) fullPath == prefix then
|
||||
substring (stringLength prefix + 1) 1000 fullPath
|
||||
else
|
||||
fileName;
|
||||
|
||||
stripAnyPrefixes = fullPath: fold stripPrefix fullPath prefixesToStrip;
|
||||
|
||||
# Convert the list of options into an XML file.
|
||||
optionsXML = builtins.toFile "options.xml" (builtins.toXML optionsList');
|
||||
|
|
Loading…
Reference in a new issue