summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorVladimir Serov <me@cab404.ru>2022-03-14 07:11:05 +0300
committerVladimir Serov <me@cab404.ru>2022-03-15 14:17:59 +0300
commit0c68e23f5238b60dbbd5bf994a08060bd311f89d (patch)
tree8922898f013691715af5cf0e3ce5f8824cd48109 /nixos
parent976a5bc9fffaad437069df4d06edf0315f7a020f (diff)
downloadnixpkgs-0c68e23f5238b60dbbd5bf994a08060bd311f89d.tar
nixpkgs-0c68e23f5238b60dbbd5bf994a08060bd311f89d.tar.gz
nixpkgs-0c68e23f5238b60dbbd5bf994a08060bd311f89d.tar.bz2
nixpkgs-0c68e23f5238b60dbbd5bf994a08060bd311f89d.tar.lz
nixpkgs-0c68e23f5238b60dbbd5bf994a08060bd311f89d.tar.xz
nixpkgs-0c68e23f5238b60dbbd5bf994a08060bd311f89d.tar.zst
nixpkgs-0c68e23f5238b60dbbd5bf994a08060bd311f89d.zip
nixos/modules/version: remove unnecessary quoting
(In cases it is unnecessary)
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/misc/version.nix6
1 files changed, 5 insertions, 1 deletions
diff --git a/nixos/modules/misc/version.nix b/nixos/modules/misc/version.nix
index 6c072021ed8..d825f4beb30 100644
--- a/nixos/modules/misc/version.nix
+++ b/nixos/modules/misc/version.nix
@@ -8,8 +8,12 @@ let
     concatStringsSep mapAttrsToList toLower
     literalExpression mkRenamedOptionModule mkDefault mkOption trivial types;
 
+  needsEscaping = s: null != builtins.match "[a-zA-Z0-9]+" s;
+  escapeIfNeccessary = s: if needsEscaping s then s else ''"${lib.escape [ "\$" "\"" "\\" "\`" ] s}"'';
   attrsToText = attrs:
-    concatStringsSep "\n" (mapAttrsToList (n: v: ''${n}="${toString v}"'') attrs);
+    concatStringsSep "\n" (
+      mapAttrsToList (n: v: ''${n}=${escapeIfNeccessary (toString v)}'') attrs
+    );
 
 in
 {