summary refs log tree commit diff
path: root/lib/options.nix
diff options
context:
space:
mode:
authorJan Tojnar <jtojnar@gmail.com>2020-04-14 04:49:17 +0200
committerJan Tojnar <jtojnar@gmail.com>2020-04-14 04:49:17 +0200
commitc652b64a262184d5c7c0cdc003dc52635d4aa0d7 (patch)
tree275557636d9db8ad16a6f3203fcd03a5f5c6cbba /lib/options.nix
parent1ca2475b0ca64be3c359e7daf9e6a251bec93252 (diff)
downloadnixpkgs-c652b64a262184d5c7c0cdc003dc52635d4aa0d7.tar
nixpkgs-c652b64a262184d5c7c0cdc003dc52635d4aa0d7.tar.gz
nixpkgs-c652b64a262184d5c7c0cdc003dc52635d4aa0d7.tar.bz2
nixpkgs-c652b64a262184d5c7c0cdc003dc52635d4aa0d7.tar.lz
nixpkgs-c652b64a262184d5c7c0cdc003dc52635d4aa0d7.tar.xz
nixpkgs-c652b64a262184d5c7c0cdc003dc52635d4aa0d7.tar.zst
nixpkgs-c652b64a262184d5c7c0cdc003dc52635d4aa0d7.zip
lib/options: Relax showOption quoting
https://github.com/NixOS/nixpkgs/commit/124cccbe3b63122733e02e41e45a383ec48752fd
broke the build of NixOS manual.

It does not make sense to be as strict as with attributes since we
are not limited by the CLI's inability to handle numbers.
Placeholders should not be quoted either as they are not part of Nix
syntax but a meta-level construct.
Diffstat (limited to 'lib/options.nix')
-rw-r--r--lib/options.nix15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/options.nix b/lib/options.nix
index a53b8c9f264..7407905131b 100644
--- a/lib/options.nix
+++ b/lib/options.nix
@@ -192,8 +192,21 @@ rec {
      Example:
        (showOption ["foo" "bar" "baz"]) == "foo.bar.baz"
        (showOption ["foo" "bar.baz" "tux"]) == "foo.\"bar.baz\".tux"
+
+     Placeholders will not be quoted as they are not actual values:
+       (showOption ["foo" "*" "bar"]) == "foo.*.bar"
+       (showOption ["foo" "<name>" "bar"]) == "foo.<name>.bar"
+
+     Unlike attributes, options can also start with numbers:
+       (showOption ["windowManager" "2bwm" "enable"]) == "windowManager.2bwm.enable"
   */
-  showOption = parts: concatMapStringsSep "." escapeNixIdentifier parts;
+  showOption = parts:
+    let
+      escapeOptionPart = part:
+        if part == "*" || builtins.match "<.+>" part != null || builtins.match "[a-zA-Z0-9_][a-zA-Z0-9_'-]+" part != null
+        then part
+        else escapeNixIdentifier part;
+    in concatMapStringsSep "." escapeOptionPart parts;
   showFiles = files: concatStringsSep " and " (map (f: "`${f}'") files);
   unknownModule = "<unknown-file>";