From ae466ba15c2f74cdd621a4fb548813b30cc524e4 Mon Sep 17 00:00:00 2001 From: aszlig Date: Fri, 29 Jan 2016 16:20:22 +0100 Subject: [PATCH] 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 --- nixos/doc/manual/default.nix | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/nixos/doc/manual/default.nix b/nixos/doc/manual/default.nix index 5a4d36d9dcc0..de3f9a95d95a 100644 --- a/nixos/doc/manual/default.nix +++ b/nixos/doc/manual/default.nix @@ -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');