lib/cli: deprecate toGNUCommandLine

This commit is contained in:
Lukas Wurzinger
2025-10-21 15:02:59 +02:00
parent 73e8a483e6
commit 1f4c50ab81
28 changed files with 81 additions and 65 deletions

View File

@@ -353,6 +353,8 @@
- `number` - `number`
- `numbers.*` - `numbers.*`
- `lib.cli.toGNUCommandLine` and `lib.cli.toGNUCommandLineShell` have been deprecated in favor of `lib.cli.toCommandLine`, `lib.cli.toCommandLineShell`, `lib.cli.toCommandLineGNU` and `lib.cli.toCommandLineShellGNU`.
### Additions and Improvements {#sec-nixpkgs-release-25.11-lib-additions-improvements} ### Additions and Improvements {#sec-nixpkgs-release-25.11-lib-additions-improvements}
- `neovim`: Added support for the `vim.o.exrc` option, the `VIMINIT` environment variable, and sourcing of `sysinit.vim`. - `neovim`: Added support for the `vim.o.exrc` option, the `VIMINIT` environment variable, and sourcing of `sysinit.vim`.

View File

@@ -40,7 +40,9 @@
::: :::
*/ */
toGNUCommandLineShell = toGNUCommandLineShell =
options: attrs: lib.escapeShellArgs (lib.cli.toGNUCommandLine options attrs); lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2511)
"lib.cli.toGNUCommandLineShell is deprecated, please use lib.cli.toCommandLineShell or lib.cli.toCommandLineShellGNU instead."
(options: attrs: lib.escapeShellArgs (lib.cli.toGNUCommandLine options attrs));
/** /**
Automatically convert an attribute set to a list of command-line options. Automatically convert an attribute set to a list of command-line options.
@@ -114,6 +116,9 @@
::: :::
*/ */
toGNUCommandLine = toGNUCommandLine =
lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2511)
"lib.cli.toGNUCommandLine is deprecated, please use lib.cli.toCommandLine or lib.cli.toCommandLineShellGNU instead."
(
{ {
mkOptionName ? k: if builtins.stringLength k == 1 then "-${k}" else "--${k}", mkOptionName ? k: if builtins.stringLength k == 1 then "-${k}" else "--${k}",
@@ -147,7 +152,8 @@
mkOption k v; mkOption k v;
in in
builtins.concatLists (lib.mapAttrsToList render options); builtins.concatLists (lib.mapAttrsToList render options)
);
/** /**
Converts the given attributes into a single shell-escaped command-line string. Converts the given attributes into a single shell-escaped command-line string.

View File

@@ -10,7 +10,7 @@ let
ensurePrinter = ensurePrinter =
p: p:
let let
args = lib.cli.toGNUCommandLineShell { } ( args = lib.cli.toCommandLineShellGNU { } (
{ {
p = p.name; p = p.name;
v = p.deviceUri; v = p.deviceUri;

View File

@@ -48,7 +48,7 @@ libeufinComponent:
DynamicUser = true; DynamicUser = true;
ExecStart = ExecStart =
let let
args = lib.cli.toGNUCommandLineShell { } { args = lib.cli.toCommandLineShellGNU { } {
c = configFile; c = configFile;
L = if cfg.debug then "debug" else null; L = if cfg.debug then "debug" else null;
}; };
@@ -80,7 +80,7 @@ libeufinComponent:
initialAccountRegistration = lib.concatMapStringsSep "\n" ( initialAccountRegistration = lib.concatMapStringsSep "\n" (
account: account:
let let
args = lib.cli.toGNUCommandLineShell { } { args = lib.cli.toCommandLineShellGNU { } {
c = configFile; c = configFile;
inherit (account) username password name; inherit (account) username password name;
payto_uri = "payto://x-taler-bank/${bankHost}/${account.username}?receiver-name=${account.name}"; payto_uri = "payto://x-taler-bank/${bankHost}/${account.username}?receiver-name=${account.name}";
@@ -90,7 +90,7 @@ libeufinComponent:
"${lib.getExe' cfg.package "libeufin-bank"} create-account ${args}" "${lib.getExe' cfg.package "libeufin-bank"} create-account ${args}"
) cfg.initialAccounts; ) cfg.initialAccounts;
args = lib.cli.toGNUCommandLineShell { } { args = lib.cli.toCommandLineShellGNU { } {
c = configFile; c = configFile;
L = if cfg.debug then "debug" else null; L = if cfg.debug then "debug" else null;
}; };

View File

@@ -16,7 +16,7 @@ let
limit != null && window != null limit != null && window != null
) "Both power limit and window must be set"; ) "Both power limit and window must be set";
"${toString limit} ${toString window}"; "${toString limit} ${toString window}";
cliArgs = lib.cli.toGNUCommandLine { } { cliArgs = lib.cli.toCommandLineGNU { } {
inherit (cfg) inherit (cfg)
verbose verbose
temp temp

View File

@@ -170,7 +170,7 @@ in
serviceConfig = { serviceConfig = {
ExecStart = ExecStart =
let let
args = lib.cli.toGNUCommandLineShell { optionValueSeparator = "="; } ( args = lib.cli.toCommandLineShellGNU { } (
lib.foldr (a: b: a // b) { } [ lib.foldr (a: b: a // b) { } [
{ {
inherit (cfg) inherit (cfg)

View File

@@ -22,7 +22,7 @@ let
isNonNull = v: v != null; isNonNull = v: v != null;
genCliFlags = genCliFlags =
settings: concatStringsSep " " (cli.toGNUCommandLine { } (filterAttrs (const isNonNull) settings)); settings: concatStringsSep " " (cli.toCommandLineGNU { } (filterAttrs (const isNonNull) settings));
in in
{ {
options.services.mailpit.instances = mkOption { options.services.mailpit.instances = mkOption {

View File

@@ -686,7 +686,7 @@ in
path = [ manage ]; path = [ manage ];
script = '' script = ''
paperless-manage document_exporter ${cfg.exporter.directory} ${ paperless-manage document_exporter ${cfg.exporter.directory} ${
lib.cli.toGNUCommandLineShell { } cfg.exporter.settings lib.cli.toCommandLineShellGNU { } cfg.exporter.settings
} }
''; '';
}; };

View File

@@ -187,7 +187,7 @@ in
systemd.services.gns3-server = systemd.services.gns3-server =
let let
commandArgs = lib.cli.toGNUCommandLineShell { } { commandArgs = lib.cli.toCommandLineShellGNU { } {
config = "/etc/gns3/gns3_server.conf"; config = "/etc/gns3/gns3_server.conf";
pid = "/run/gns3/server.pid"; pid = "/run/gns3/server.pid";
log = cfg.log.file; log = cfg.log.file;

View File

@@ -14,7 +14,13 @@ let
mkMerge mkMerge
optional optional
; ;
inherit (lib.cli) toGNUCommandLine; inherit (lib.cli) toCommandLine;
optionFormat = optionName: {
option = "-${optionName}";
sep = null;
explicitBool = false;
};
cfg = config.services.hylafax; cfg = config.services.hylafax;
mapModems = lib.forEach (lib.attrValues cfg.modems); mapModems = lib.forEach (lib.attrValues cfg.modems);
@@ -23,9 +29,7 @@ let
prefix: program: posArg: options: prefix: program: posArg: options:
let let
start = "${prefix}${cfg.package}/spool/bin/${program}"; start = "${prefix}${cfg.package}/spool/bin/${program}";
optionsList = toGNUCommandLine { mkOptionName = k: "-${k}"; } ( optionsList = toCommandLine optionFormat ({ q = cfg.spoolAreaPath; } // options);
{ q = cfg.spoolAreaPath; } // options
);
posArgList = optional (posArg != null) posArg; posArgList = optional (posArg != null) posArg;
in in
"${start} ${escapeShellArgs (optionsList ++ posArgList)}"; "${start} ${escapeShellArgs (optionsList ++ posArgList)}";

View File

@@ -83,7 +83,7 @@ in
}; };
# the flag values will all be overwritten if also defined in the env file # the flag values will all be overwritten if also defined in the env file
serviceConfig = { serviceConfig = {
ExecStart = "${lib.getExe cfg.package} ${lib.cli.toGNUCommandLineShell { } cfg.settings}"; ExecStart = "${lib.getExe cfg.package} ${lib.cli.toCommandLineShellGNU { } cfg.settings}";
DynamicUser = true; DynamicUser = true;
StateDirectory = "newt"; StateDirectory = "newt";
StateDirectoryMode = "0700"; StateDirectoryMode = "0700";

View File

@@ -947,7 +947,7 @@ in
ExecStart = ExecStart =
let let
args = lib.escapeShellArgs ( args = lib.escapeShellArgs (
(lib.cli.toGNUCommandLine { } { (lib.cli.toCommandLineGNU { } {
"no-browser" = true; "no-browser" = true;
"gui-address" = (if isUnixGui then "unix://" else "") + cfg.guiAddress; "gui-address" = (if isUnixGui then "unix://" else "") + cfg.guiAddress;
"config" = cfg.configDir; "config" = cfg.configDir;

View File

@@ -26,7 +26,7 @@ let
str str
(listOf str) (listOf str)
]); ]);
generate = lib.cli.toGNUCommandLineShell { }; generate = lib.cli.toCommandLineShellGNU { };
}; };
hostPortToString = { host, port, ... }: "${host}:${toString port}"; hostPortToString = { host, port, ... }: "${host}:${toString port}";

View File

@@ -164,7 +164,7 @@ in
Type = "simple"; Type = "simple";
ExecStart = ExecStart =
let let
args = lib.cli.toGNUCommandLineShell { mkOptionName = k: "-${k}"; } { args = lib.cli.toCommandLineShellGNU { } {
dir = stateDir; dir = stateDir;
hostname = cfg.settings.hostName; hostname = cfg.settings.hostName;
port = cfg.settings.port; port = cfg.settings.port;

View File

@@ -179,7 +179,7 @@ in
serviceConfig.EnvironmentFile = ""; serviceConfig.EnvironmentFile = "";
environment.EARLYOOM_ARGS = environment.EARLYOOM_ARGS =
lib.cli.toGNUCommandLineShell { } { lib.cli.toCommandLineShellGNU { } {
m = m =
"${toString cfg.freeMemThreshold}" "${toString cfg.freeMemThreshold}"
+ optionalString (cfg.freeMemKillThreshold != null) ",${toString cfg.freeMemKillThreshold}"; + optionalString (cfg.freeMemKillThreshold != null) ",${toString cfg.freeMemKillThreshold}";

View File

@@ -179,7 +179,7 @@ in
${gitWithRepo} checkout FETCH_HEAD ${gitWithRepo} checkout FETCH_HEAD
nix-build${renderNixArgs cfg.nixArgs} ${ nix-build${renderNixArgs cfg.nixArgs} ${
lib.cli.toGNUCommandLineShell { } { lib.cli.toCommandLineShellGNU { } {
attr = cfg.nixAttribute; attr = cfg.nixAttribute;
out-link = outPath; out-link = outPath;
} }

View File

@@ -25,10 +25,8 @@ let
str str
]) ])
); );
generate = lib.cli.toGNUCommandLineShell { generate = lib.cli.toCommandLineShellGNU {
mkBool = k: v: [ explicitBool = true;
"--${k}=${if v then "true" else "false"}"
];
}; };
}; };
in in

View File

@@ -146,7 +146,7 @@ in
Type = "simple"; Type = "simple";
ExecStart = '' ExecStart = ''
${cfg.package}/bin/libretranslate ${ ${cfg.package}/bin/libretranslate ${
lib.cli.toGNUCommandLineShell { } ( lib.cli.toCommandLineShellGNU { } (
cfg.extraArgs cfg.extraArgs
// { // {
inherit (cfg) host port threads; inherit (cfg) host port threads;

View File

@@ -207,7 +207,7 @@ in
configFile = settingsFormat.generate "config.yaml" cfg.settings; configFile = settingsFormat.generate "config.yaml" cfg.settings;
stepsFile = settingsFormat.generate "steps.yaml" cfg.steps; stepsFile = settingsFormat.generate "steps.yaml" cfg.steps;
args = lib.cli.toGNUCommandLineShell { } { args = lib.cli.toCommandLineShellGNU { } {
config = cfg.extraSettingsPaths ++ [ configFile ]; config = cfg.extraSettingsPaths ++ [ configFile ];
steps = cfg.extraStepsPaths ++ [ stepsFile ]; steps = cfg.extraStepsPaths ++ [ stepsFile ];
masterkeyFile = cfg.masterKeyFile; masterkeyFile = cfg.masterKeyFile;

View File

@@ -151,7 +151,7 @@ in
serviceConfig = { serviceConfig = {
ExecStart = '' ExecStart = ''
${pkgs.fcgiwrap}/sbin/fcgiwrap ${ ${pkgs.fcgiwrap}/sbin/fcgiwrap ${
cli.toGNUCommandLineShell { } ( cli.toCommandLineShellGNU { } (
{ {
c = cfg.process.prefork; c = cfg.process.prefork;
} }

View File

@@ -8,7 +8,7 @@
let let
cfg = config.services.journald.gateway; cfg = config.services.journald.gateway;
cliArgs = lib.cli.toGNUCommandLineShell { } { cliArgs = lib.cli.toCommandLineShellGNU { } {
# If either of these are null / false, they are not passed in the command-line # If either of these are null / false, they are not passed in the command-line
inherit (cfg) inherit (cfg)
cert cert

View File

@@ -9,7 +9,7 @@ let
cfg = config.services.journald.remote; cfg = config.services.journald.remote;
format = pkgs.formats.systemd { }; format = pkgs.formats.systemd { };
cliArgs = lib.cli.toGNUCommandLineShell { } { cliArgs = lib.cli.toCommandLineShellGNU { } {
inherit (cfg) output; inherit (cfg) output;
# "-3" specifies the file descriptor from the .socket unit. # "-3" specifies the file descriptor from the .socket unit.
"listen-${cfg.listen}" = "-3"; "listen-${cfg.listen}" = "-3";

View File

@@ -90,7 +90,7 @@ in
++ lib.optional config.boot.zfs.enabled config.boot.zfs.package; ++ lib.optional config.boot.zfs.enabled config.boot.zfs.package;
serviceConfig = { serviceConfig = {
ExecStart = ''${pkgs.containerd}/bin/containerd ${ ExecStart = ''${pkgs.containerd}/bin/containerd ${
lib.concatStringsSep " " (lib.cli.toGNUCommandLine { } cfg.args) lib.concatStringsSep " " (lib.cli.toCommandLineGNU { } cfg.args)
}''; }'';
Delegate = "yes"; Delegate = "yes";
KillMode = "process"; KillMode = "process";

View File

@@ -252,8 +252,8 @@ in
--ostype ${if pkgs.stdenv.hostPlatform.system == "x86_64-linux" then "Linux26_64" else "Linux26"} --ostype ${if pkgs.stdenv.hostPlatform.system == "x86_64-linux" then "Linux26_64" else "Linux26"}
VBoxManage modifyvm "$vmName" \ VBoxManage modifyvm "$vmName" \
--memory ${toString cfg.memorySize} \ --memory ${toString cfg.memorySize} \
${lib.cli.toGNUCommandLineShell { } cfg.params} ${lib.cli.toCommandLineShellGNU { } cfg.params}
VBoxManage storagectl "$vmName" ${lib.cli.toGNUCommandLineShell { } cfg.storageController} VBoxManage storagectl "$vmName" ${lib.cli.toCommandLineShellGNU { } cfg.storageController}
VBoxManage storageattach "$vmName" --storagectl ${cfg.storageController.name} --port 0 --device 0 --type hdd \ VBoxManage storageattach "$vmName" --storagectl ${cfg.storageController.name} --port 0 --device 0 --type hdd \
--medium disk.vdi --medium disk.vdi
${lib.optionalString (cfg.extraDisk != null) '' ${lib.optionalString (cfg.extraDisk != null) ''

View File

@@ -812,7 +812,13 @@ rec {
strip ? true, strip ? true,
}: }:
let let
nimCompileCmdArgs = lib.cli.toGNUCommandLineShell { optionValueSeparator = ":"; } ( optionFormat = optionName: {
option = "--${optionName}";
sep = ":";
explicitBool = false;
};
nimCompileCmdArgs = lib.cli.toCommandLineShell optionFormat (
{ {
d = "release"; d = "release";
nimcache = "."; nimcache = ".";

View File

@@ -43,7 +43,7 @@ stdenvNoCC.mkDerivation {
# The --to-dir and --ui-bundle-url options are not included in the # The --to-dir and --ui-bundle-url options are not included in the
# playbook due to Antora and Nix limitations. # playbook due to Antora and Nix limitations.
antora ${ antora ${
lib.cli.toGNUCommandLineShell { } { lib.cli.toCommandLineShellGNU { } {
cache-dir = "$(mktemp --directory)"; cache-dir = "$(mktemp --directory)";
extension = if antora-lunr-extension-test then antora-lunr-extension else false; extension = if antora-lunr-extension-test then antora-lunr-extension else false;
to-dir = placeholder "out"; to-dir = placeholder "out";

View File

@@ -21,7 +21,7 @@ rustPlatform.buildRustPackage {
cargoHash = "sha256-RFlac10XFJXT3Giayy31kZ3Nn1Q+YsPt/zCdkSV0Atk="; cargoHash = "sha256-RFlac10XFJXT3Giayy31kZ3Nn1Q+YsPt/zCdkSV0Atk=";
cargoBuildFlags = lib.cli.toGNUCommandLine { } { cargoBuildFlags = lib.cli.toCommandLineGNU { } {
package = [ package = [
"lightway-client" "lightway-client"
"lightway-server" "lightway-server"

View File

@@ -101,7 +101,7 @@ runCommand name { inherit dependencies; } ''
mkdir -p $out/${dataDhall} mkdir -p $out/${dataDhall}
XDG_DATA_HOME=$out/${data} ${dhall-docs}/bin/dhall-docs --output-link $out/docs ${ XDG_DATA_HOME=$out/${data} ${dhall-docs}/bin/dhall-docs --output-link $out/docs ${
lib.cli.toGNUCommandLineShell { } { lib.cli.toCommandLineShellGNU { } {
base-import-url = baseImportUrl; base-import-url = baseImportUrl;
input = documentationRoot; input = documentationRoot;