diff options
author | Graham Christensen <graham@grahamc.com> | 2018-03-05 09:54:21 -0500 |
---|---|---|
committer | Graham Christensen <graham@grahamc.com> | 2018-03-05 09:58:06 -0500 |
commit | 059a71a6119d0ef52948ec9e749c46bd1f9aa3d2 (patch) | |
tree | 42cc31be179b15ac834b21b500b3f5e4101d6114 /lib/options.nix | |
parent | 830ccafedc6d3b0d51429b0c68c8b76ff9cadff4 (diff) | |
download | nixlib-059a71a6119d0ef52948ec9e749c46bd1f9aa3d2.tar nixlib-059a71a6119d0ef52948ec9e749c46bd1f9aa3d2.tar.gz nixlib-059a71a6119d0ef52948ec9e749c46bd1f9aa3d2.tar.bz2 nixlib-059a71a6119d0ef52948ec9e749c46bd1f9aa3d2.tar.lz nixlib-059a71a6119d0ef52948ec9e749c46bd1f9aa3d2.tar.xz nixlib-059a71a6119d0ef52948ec9e749c46bd1f9aa3d2.tar.zst nixlib-059a71a6119d0ef52948ec9e749c46bd1f9aa3d2.zip |
lib/options: teach showOptions about funny option names
Handle the case where options have funny symbols inside of them. Example: If I reference the following attribute without it being defined: security.acme.certs."example.com".webroot I now get the error: The option `security.acme.certs."example.com".webroot' is used but not defined. where before I got: The option `security.acme.certs.example.com.webroot' is used but not defined. which is not true.
Diffstat (limited to 'lib/options.nix')
-rw-r--r-- | lib/options.nix | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/options.nix b/lib/options.nix index 9446eca36778..01160b48ec01 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -127,7 +127,20 @@ rec { /* Helper functions. */ - showOption = concatStringsSep "."; + + # Convert an option, described as a list of the option parts in to a + # safe, human readable version. ie: + # + # (showOption ["foo" "bar" "baz"]) == "foo.bar.baz" + # (showOption ["foo" "bar.baz" "tux"]) == "foo.\"bar.baz\".tux" + showOption = parts: let + escapeOptionPart = part: + let + escaped = lib.strings.escapeNixString part; + in if escaped == "\"${part}\"" + then part + else escaped; + in (concatStringsSep ".") (map escapeOptionPart parts); showFiles = files: concatStringsSep " and " (map (f: "`${f}'") files); unknownModule = "<unknown-file>"; |