Skip to content

Commit

Permalink
lib.replaceChars: warn about being a deprecated alias
Browse files Browse the repository at this point in the history
replaceStrings has been in nix since 2015(nix 1.10)

so it is safe to remove the fallback

NixOS/nix@d6d5885
  • Loading branch information
Artturin committed Dec 15, 2022
1 parent 084fd69 commit 05a2dfd
Show file tree
Hide file tree
Showing 47 changed files with 64 additions and 75 deletions.
23 changes: 6 additions & 17 deletions lib/strings.nix
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ rec {
escape ["(" ")"] "(foo)"
=> "\\(foo\\)"
*/
escape = list: replaceChars list (map (c: "\\${c}") list);
escape = list: replaceStrings list (map (c: "\\${c}") list);

/* Escape occurence of the element of `list` in `string` by
converting to its ASCII value and prefixing it with \\x.
Expand All @@ -341,7 +341,7 @@ rec {
=> "foo\\x20bar"
*/
escapeC = list: replaceChars list (map (c: "\\x${ toLower (lib.toHexString (charToInt c))}") list);
escapeC = list: replaceStrings list (map (c: "\\x${ toLower (lib.toHexString (charToInt c))}") list);

/* Quote string to be used safely within the Bourne shell.
Expand Down Expand Up @@ -471,19 +471,8 @@ rec {
["\"" "'" "<" ">" "&"]
["&quot;" "&apos;" "&lt;" "&gt;" "&amp;"];

# Obsolete - use replaceStrings instead.
replaceChars = builtins.replaceStrings or (
del: new: s:
let
substList = lib.zipLists del new;
subst = c:
let found = lib.findFirst (sub: sub.fst == c) null substList; in
if found == null then
c
else
found.snd;
in
stringAsChars subst s);
# warning added 12-12-2022
replaceChars = lib.warn "replaceChars is a deprecated alias of replaceStrings, replace usages of it with replaceStrings." builtins.replaceStrings;

# Case conversion utilities.
lowerChars = stringToCharacters "abcdefghijklmnopqrstuvwxyz";
Expand All @@ -497,7 +486,7 @@ rec {
toLower "HOME"
=> "home"
*/
toLower = replaceChars upperChars lowerChars;
toLower = replaceStrings upperChars lowerChars;

/* Converts an ASCII string to upper-case.
Expand All @@ -507,7 +496,7 @@ rec {
toUpper "home"
=> "HOME"
*/
toUpper = replaceChars lowerChars upperChars;
toUpper = replaceStrings lowerChars upperChars;

/* Appends string context from another string. This is an implementation
detail of Nix and should be used carefully.
Expand Down
6 changes: 3 additions & 3 deletions nixos/lib/systemd-lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ let
systemd = cfg.package;
in rec {

shellEscape = s: (replaceChars [ "\\" ] [ "\\\\" ] s);
shellEscape = s: (replaceStrings [ "\\" ] [ "\\\\" ] s);

mkPathSafeName = lib.replaceChars ["@" ":" "\\" "[" "]"] ["-" "-" "-" "" ""];
mkPathSafeName = lib.replaceStrings ["@" ":" "\\" "[" "]"] ["-" "-" "-" "" ""];

# a type for options that take a unit name
unitNameType = types.strMatching "[a-zA-Z0-9@%:_.\\-]+[.](service|socket|device|mount|automount|swap|target|path|timer|scope|slice)";
Expand Down Expand Up @@ -258,7 +258,7 @@ in rec {

makeJobScript = name: text:
let
scriptName = replaceChars [ "\\" "@" ] [ "-" "_" ] (shellEscape name);
scriptName = replaceStrings [ "\\" "@" ] [ "-" "_" ] (shellEscape name);
out = (pkgs.writeShellScriptBin scriptName ''
set -e
${text}
Expand Down
6 changes: 3 additions & 3 deletions nixos/lib/utils.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ rec {
trim = s: removeSuffix "/" (removePrefix "/" s);
normalizedPath = strings.normalizePath s;
in
replaceChars ["/"] ["-"]
replaceStrings ["/"] ["-"]
(replacePrefix "." (strings.escapeC ["."] ".")
(strings.escapeC (stringToCharacters " !\"#$%&'()*+,;<=>=@[\\]^`{|}~-")
(if normalizedPath == "/" then normalizedPath else trim normalizedPath)));
Expand All @@ -67,7 +67,7 @@ rec {
else if builtins.isInt arg || builtins.isFloat arg then toString arg
else throw "escapeSystemdExecArg only allows strings, paths and numbers";
in
replaceChars [ "%" "$" ] [ "%%" "$$" ] (builtins.toJSON s);
replaceStrings [ "%" "$" ] [ "%%" "$$" ] (builtins.toJSON s);

# Quotes a list of arguments into a single string for use in a Exec*
# line.
Expand Down Expand Up @@ -112,7 +112,7 @@ rec {
else if isAttrs item then
map (name:
let
escapedName = ''"${replaceChars [''"'' "\\"] [''\"'' "\\\\"] name}"'';
escapedName = ''"${replaceStrings [''"'' "\\"] [''\"'' "\\\\"] name}"'';
in
recurse (prefix + "." + escapedName) item.${name}) (attrNames item)
else if isList item then
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/config/swap.nix
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ let
config = rec {
device = mkIf options.label.isDefined
"/dev/disk/by-label/${config.label}";
deviceName = lib.replaceChars ["\\"] [""] (escapeSystemdPath config.device);
deviceName = lib.replaceStrings ["\\"] [""] (escapeSystemdPath config.device);
realDevice = if config.randomEncryption.enable then "/dev/mapper/${deviceName}" else config.device;
};

Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/programs/xfs_quota.nix
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ in
'';

wantedBy = [ "multi-user.target" ];
after = [ ((replaceChars [ "/" ] [ "-" ] opts.fileSystem) + ".mount") ];
after = [ ((replaceStrings [ "/" ] [ "-" ] opts.fileSystem) + ".mount") ];

restartTriggers = [ config.environment.etc.projects.source ];

Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/services/mail/listmonk.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let
# Escaping is done according to https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS
setDatabaseOption = key: value:
"UPDATE settings SET value = '${
lib.replaceChars [ "'" ] [ "''" ] (builtins.toJSON value)
lib.replaceStrings [ "'" ] [ "''" ] (builtins.toJSON value)
}' WHERE key = '${key}';";
updateDatabaseConfigSQL = pkgs.writeText "update-database-config.sql"
(concatStringsSep "\n" (mapAttrsToList setDatabaseOption
Expand Down
6 changes: 3 additions & 3 deletions nixos/modules/services/networking/supplicant.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let
serviceName = iface: "supplicant-${if (iface=="WLAN") then "wlan@" else (
if (iface=="LAN") then "lan@" else (
if (iface=="DBUS") then "dbus"
else (replaceChars [" "] ["-"] iface)))}";
else (replaceStrings [" "] ["-"] iface)))}";

# TODO: Use proper privilege separation for wpa_supplicant
supplicantService = iface: suppl:
Expand All @@ -27,7 +27,7 @@ let
driverArg = optionalString (suppl.driver != null) "-D${suppl.driver}";
bridgeArg = optionalString (suppl.bridge!="") "-b${suppl.bridge}";
confFileArg = optionalString (suppl.configFile.path!=null) "-c${suppl.configFile.path}";
extraConfFile = pkgs.writeText "supplicant-extra-conf-${replaceChars [" "] ["-"] iface}" ''
extraConfFile = pkgs.writeText "supplicant-extra-conf-${replaceStrings [" "] ["-"] iface}" ''
${optionalString suppl.userControlled.enable "ctrl_interface=DIR=${suppl.userControlled.socketDir} GROUP=${suppl.userControlled.group}"}
${optionalString suppl.configFile.writable "update_config=1"}
${suppl.extraConf}
Expand Down Expand Up @@ -223,7 +223,7 @@ in
text = ''
${flip (concatMapStringsSep "\n") (filter (n: n!="WLAN" && n!="LAN" && n!="DBUS") (attrNames cfg)) (iface:
flip (concatMapStringsSep "\n") (splitString " " iface) (i: ''
ACTION=="add", SUBSYSTEM=="net", ENV{INTERFACE}=="${i}", TAG+="systemd", ENV{SYSTEMD_WANTS}+="supplicant-${replaceChars [" "] ["-"] iface}.service", TAG+="SUPPLICANT_ASSIGNED"''))}
ACTION=="add", SUBSYSTEM=="net", ENV{INTERFACE}=="${i}", TAG+="systemd", ENV{SYSTEMD_WANTS}+="supplicant-${replaceStrings [" "] ["-"] iface}.service", TAG+="SUPPLICANT_ASSIGNED"''))}
${optionalString (hasAttr "WLAN" cfg) ''
ACTION=="add", SUBSYSTEM=="net", ENV{DEVTYPE}=="wlan", TAG!="SUPPLICANT_ASSIGNED", TAG+="systemd", PROGRAM="/run/current-system/systemd/bin/systemd-escape -p %E{INTERFACE}", ENV{SYSTEMD_WANTS}+="supplicant-wlan@$result.service"
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/services/networking/wireguard.nix
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ let

peerUnitServiceName = interfaceName: publicKey: dynamicRefreshEnabled:
let
keyToUnitName = replaceChars
keyToUnitName = replaceStrings
[ "/" "-" " " "+" "=" ]
[ "-" "\\x2d" "\\x20" "\\x2b" "\\x3d" ];
unitName = keyToUnitName publicKey;
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/system/boot/loader/grub/grub.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ let
grubConfig = args:
let
efiSysMountPoint = if args.efiSysMountPoint == null then args.path else args.efiSysMountPoint;
efiSysMountPoint' = replaceChars [ "/" ] [ "-" ] efiSysMountPoint;
efiSysMountPoint' = replaceStrings [ "/" ] [ "-" ] efiSysMountPoint;
in
pkgs.writeText "grub-config.xml" (builtins.toXML
{ splashImage = f cfg.splashImage;
Expand Down
6 changes: 3 additions & 3 deletions nixos/modules/tasks/network-interfaces.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1377,12 +1377,12 @@ in
# networkmanager falls back to "/proc/sys/net/ipv6/conf/default/use_tempaddr"
"net.ipv6.conf.default.use_tempaddr" = tempaddrValues.${cfg.tempAddresses}.sysctl;
} // listToAttrs (forEach interfaces
(i: nameValuePair "net.ipv4.conf.${replaceChars ["."] ["/"] i.name}.proxy_arp" i.proxyARP))
(i: nameValuePair "net.ipv4.conf.${replaceStrings ["."] ["/"] i.name}.proxy_arp" i.proxyARP))
// listToAttrs (forEach interfaces
(i: let
opt = i.tempAddress;
val = tempaddrValues.${opt}.sysctl;
in nameValuePair "net.ipv6.conf.${replaceChars ["."] ["/"] i.name}.use_tempaddr" val));
in nameValuePair "net.ipv6.conf.${replaceStrings ["."] ["/"] i.name}.use_tempaddr" val));

security.wrappers = {
ping = {
Expand Down Expand Up @@ -1495,7 +1495,7 @@ in
in
''
# override to ${msg} for ${i.name}
ACTION=="add", SUBSYSTEM=="net", RUN+="${pkgs.procps}/bin/sysctl net.ipv6.conf.${replaceChars ["."] ["/"] i.name}.use_tempaddr=${val}"
ACTION=="add", SUBSYSTEM=="net", RUN+="${pkgs.procps}/bin/sysctl net.ipv6.conf.${replaceStrings ["."] ["/"] i.name}.use_tempaddr=${val}"
'') (filter (i: i.tempAddress != cfg.tempAddresses) interfaces);
})
] ++ lib.optional (cfg.wlanInterfaces != {})
Expand Down
2 changes: 1 addition & 1 deletion nixos/tests/installer.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ let
hardware.enableAllFirmware = lib.mkForce false;
${replaceChars ["\n"] ["\n "] extraConfig}
${replaceStrings ["\n"] ["\n "] extraConfig}
}
'';

Expand Down
4 changes: 2 additions & 2 deletions nixos/tests/prometheus-exporters.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let
inherit (import ../lib/testing-python.nix { inherit system pkgs; }) makeTest;
inherit (pkgs.lib) concatStringsSep maintainers mapAttrs mkMerge
removeSuffix replaceChars singleton splitString;
removeSuffix replaceStrings singleton splitString;

/*
* The attrset `exporterTests` contains one attribute
Expand Down Expand Up @@ -182,7 +182,7 @@ let
enable = true;
extraFlags = [ "--web.collectd-push-path /collectd" ];
};
exporterTest = let postData = replaceChars [ "\n" ] [ "" ] ''
exporterTest = let postData = replaceStrings [ "\n" ] [ "" ] ''
[{
"values":[23],
"dstypes":["gauge"],
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/audio/munt/libmt32emu.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ stdenv.mkDerivation rec {
src = fetchFromGitHub {
owner = "munt";
repo = "munt";
rev = "${pname}_${lib.replaceChars [ "." ] [ "_" ] version}";
rev = "${pname}_${lib.replaceStrings [ "." ] [ "_" ] version}";
sha256 = "sha256-XGds9lDfSiY0D8RhYG4TGyjYEVvVYuAfNSv9+VxiJEs=";
};

Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/audio/munt/mt32emu-qt.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}:

let
char2underscore = char: str: lib.replaceChars [ char ] [ "_" ] str;
char2underscore = char: str: lib.replaceStrings [ char ] [ "_" ] str;
in
mkDerivation rec {
pname = "mt32emu-qt";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/audio/munt/mt32emu-smf2wav.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}:

let
char2underscore = char: str: lib.replaceChars [ char ] [ "_" ] str;
char2underscore = char: str: lib.replaceStrings [ char ] [ "_" ] str;
in
stdenv.mkDerivation rec {
pname = "mt32emu-smf2wav";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/audio/qjackctl/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mkDerivation rec {
src = fetchFromGitHub {
owner = "rncbc";
repo = "qjackctl";
rev = "${pname}_${lib.replaceChars ["."] ["_"] version}";
rev = "${pname}_${lib.replaceStrings ["."] ["_"] version}";
sha256 = "sha256-PchW9cM5qEP51G9RXUZ3j/AvKqTkgNiw3esqSQqsy0M=";
};

Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/audio/roomeqwizard/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ stdenv.mkDerivation rec {
version = "5.20.5";

src = fetchurl {
url = "https://www.roomeqwizard.com/installers/REW_linux_${lib.replaceChars [ "." ] [ "_" ] version}.sh";
url = "https://www.roomeqwizard.com/installers/REW_linux_${lib.replaceStrings [ "." ] [ "_" ] version}.sh";
sha256 = "NYTRiOZmwkni4k+jI2SV84z5umO7+l+eKpwPCdlDD3U=";
};

Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/editors/jetbrains/linux.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ with stdenv; lib.makeOverridable mkDerivation (rec {
desktopItem = makeDesktopItem {
name = pname;
exec = pname;
comment = lib.replaceChars ["\n"] [" "] meta.longDescription;
comment = lib.replaceStrings ["\n"] [" "] meta.longDescription;
desktopName = product;
genericName = meta.description;
categories = [ "Development" ];
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/emulators/atari800/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ stdenv.mkDerivation rec {
src = fetchFromGitHub {
owner = "atari800";
repo = "atari800";
rev = "ATARI800_${replaceChars ["."] ["_"] version}";
rev = "ATARI800_${replaceStrings ["."] ["_"] version}";
sha256 = "sha256-+eJXhqPyU0GhmzF7DbteTXzEnn5klCor9Io/UgXQfQg=";
};

Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/emulators/desmume/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ stdenv.mkDerivation (finalAttrs: {
src = fetchFromGitHub {
owner = "TASVideos";
repo = "desmume";
rev = "release_${lib.replaceChars ["."] ["_"] finalAttrs.version}";
rev = "release_${lib.replaceStrings ["."] ["_"] finalAttrs.version}";
hash = "sha256-vmjKXa/iXLTwtqnG+ZUvOnOQPZROeMpfM5J3Jh/Ynfo=";
};

Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/emulators/retroarch/mkLibretroCore.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}@args:

let
d2u = if normalizeCore then (lib.replaceChars [ "-" ] [ "_" ]) else (x: x);
d2u = if normalizeCore then (lib.replaceStrings [ "-" ] [ "_" ]) else (x: x);
coreDir = placeholder "out" + libretroCore;
coreFilename = "${d2u core}_libretro${stdenv.hostPlatform.extensions.sharedLibrary}";
mainProgram = "retroarch-${core}";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/misc/sweethome3d/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ let
};
};

d2u = lib.replaceChars ["."] ["_"];
d2u = lib.replaceStrings ["."] ["_"];

in {

Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/misc/sweethome3d/editors.nix
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ let

};

d2u = lib.replaceChars ["."] ["_"];
d2u = lib.replaceStrings ["."] ["_"];

in {

Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/science/math/weka/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ stdenv.mkDerivation rec {
version = "3.9.6";

src = fetchurl {
url = "mirror://sourceforge/weka/${lib.replaceChars ["."]["-"] "${pname}-${version}"}.zip";
url = "mirror://sourceforge/weka/${lib.replaceStrings ["."]["-"] "${pname}-${version}"}.zip";
sha256 = "sha256-8fVN4MXYqXNEmyVtXh1IrauHTBZWgWG8AvsGI5Y9Aj0=";
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let

hashname = r:
let
rpl = lib.replaceChars [ ":" "/" ] [ "_" "_" ];
rpl = lib.replaceStrings [ ":" "/" ] [ "_" "_" ];
in
(rpl r.url) + "-" + (rpl r.rev);

Expand Down
6 changes: 3 additions & 3 deletions pkgs/build-support/fetchmavenartifact/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ assert (repos != []) || (url != "") || (urls != []);
let
name_ =
lib.concatStrings [
(lib.replaceChars ["."] ["_"] groupId) "_"
(lib.replaceChars ["."] ["_"] artifactId) "-"
(lib.replaceStrings ["."] ["_"] groupId) "_"
(lib.replaceStrings ["."] ["_"] artifactId) "-"
version
];
mkJarUrl = repoUrl:
lib.concatStringsSep "/" [
(lib.removeSuffix "/" repoUrl)
(lib.replaceChars ["."] ["/"] groupId)
(lib.replaceStrings ["."] ["/"] groupId)
artifactId
version
"${artifactId}-${version}${lib.optionalString (!isNull classifier) "-${classifier}"}.jar"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let version_ = lib.splitString "-" crateVersion;
completeDepsDir = lib.concatStringsSep " " completeDeps;
completeBuildDepsDir = lib.concatStringsSep " " completeBuildDeps;
envFeatures = lib.concatStringsSep " " (
map (f: lib.replaceChars ["-"] ["_"] (lib.toUpper f)) crateFeatures
map (f: lib.replaceStrings ["-"] ["_"] (lib.toUpper f)) crateFeatures
);
in ''
${echo_colored colors}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/elm/makeDotElm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ver: deps:
let cmds = lib.mapAttrsToList (name: info: let
pkg = stdenv.mkDerivation {
name = lib.replaceChars ["/"] ["-"] name + "-${info.version}";
name = lib.replaceStrings ["/"] ["-"] name + "-${info.version}";

src = fetchurl {
url = "https://github.com/${name}/archive/${info.version}.tar.gz";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/interpreters/gauche/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ stdenv.mkDerivation rec {
src = fetchFromGitHub {
owner = "shirok";
repo = pname;
rev = "release${lib.replaceChars [ "." ] [ "_" ] version}";
rev = "release${lib.replaceStrings [ "." ] [ "_" ] version}";
sha256 = "0ki1w7sa10ivmg51sqjskby0gsznb0d3738nz80x589033km5hmb";
};

Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/libraries/icu/base.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let

baseAttrs = {
src = fetchurl {
url = "https://github.com/unicode-org/icu/releases/download/release-${lib.replaceChars [ "." ] [ "-" ] version}/icu4c-${lib.replaceChars [ "." ] [ "_" ] version}-src.tgz";
url = "https://github.com/unicode-org/icu/releases/download/release-${lib.replaceStrings [ "." ] [ "-" ] version}/icu4c-${lib.replaceStrings [ "." ] [ "_" ] version}-src.tgz";
inherit sha256;
};

Expand Down

0 comments on commit 05a2dfd

Please sign in to comment.