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`
- `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}
- `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 =
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.
@@ -114,40 +116,44 @@
:::
*/
toGNUCommandLine =
{
mkOptionName ? k: if builtins.stringLength k == 1 then "-${k}" else "--${k}",
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}",
mkBool ? k: v: lib.optional v (mkOptionName k),
mkBool ? k: v: lib.optional v (mkOptionName k),
mkList ? k: v: lib.concatMap (mkOption k) v,
mkList ? k: v: lib.concatMap (mkOption k) v,
mkOption ?
k: v:
if v == null then
[ ]
else if optionValueSeparator == null then
[
(mkOptionName k)
(lib.generators.mkValueStringDefault { } v)
]
else
[ "${mkOptionName k}${optionValueSeparator}${lib.generators.mkValueStringDefault { } v}" ],
mkOption ?
k: v:
if v == null then
[ ]
else if optionValueSeparator == null then
[
(mkOptionName k)
(lib.generators.mkValueStringDefault { } v)
]
else
[ "${mkOptionName k}${optionValueSeparator}${lib.generators.mkValueStringDefault { } v}" ],
optionValueSeparator ? null,
}:
options:
let
render =
k: v:
if builtins.isBool v then
mkBool k v
else if builtins.isList v then
mkList k v
else
mkOption k v;
optionValueSeparator ? null,
}:
options:
let
render =
k: v:
if builtins.isBool v then
mkBool k v
else if builtins.isList v then
mkList k v
else
mkOption k v;
in
builtins.concatLists (lib.mapAttrsToList render options);
in
builtins.concatLists (lib.mapAttrsToList render options)
);
/**
Converts the given attributes into a single shell-escaped command-line string.

View File

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

View File

@@ -48,7 +48,7 @@ libeufinComponent:
DynamicUser = true;
ExecStart =
let
args = lib.cli.toGNUCommandLineShell { } {
args = lib.cli.toCommandLineShellGNU { } {
c = configFile;
L = if cfg.debug then "debug" else null;
};
@@ -80,7 +80,7 @@ libeufinComponent:
initialAccountRegistration = lib.concatMapStringsSep "\n" (
account:
let
args = lib.cli.toGNUCommandLineShell { } {
args = lib.cli.toCommandLineShellGNU { } {
c = configFile;
inherit (account) username password 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}"
) cfg.initialAccounts;
args = lib.cli.toGNUCommandLineShell { } {
args = lib.cli.toCommandLineShellGNU { } {
c = configFile;
L = if cfg.debug then "debug" else null;
};

View File

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

View File

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

View File

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

View File

@@ -686,7 +686,7 @@ in
path = [ manage ];
script = ''
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 =
let
commandArgs = lib.cli.toGNUCommandLineShell { } {
commandArgs = lib.cli.toCommandLineShellGNU { } {
config = "/etc/gns3/gns3_server.conf";
pid = "/run/gns3/server.pid";
log = cfg.log.file;

View File

@@ -14,7 +14,13 @@ let
mkMerge
optional
;
inherit (lib.cli) toGNUCommandLine;
inherit (lib.cli) toCommandLine;
optionFormat = optionName: {
option = "-${optionName}";
sep = null;
explicitBool = false;
};
cfg = config.services.hylafax;
mapModems = lib.forEach (lib.attrValues cfg.modems);
@@ -23,9 +29,7 @@ let
prefix: program: posArg: options:
let
start = "${prefix}${cfg.package}/spool/bin/${program}";
optionsList = toGNUCommandLine { mkOptionName = k: "-${k}"; } (
{ q = cfg.spoolAreaPath; } // options
);
optionsList = toCommandLine optionFormat ({ q = cfg.spoolAreaPath; } // options);
posArgList = optional (posArg != null) posArg;
in
"${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
serviceConfig = {
ExecStart = "${lib.getExe cfg.package} ${lib.cli.toGNUCommandLineShell { } cfg.settings}";
ExecStart = "${lib.getExe cfg.package} ${lib.cli.toCommandLineShellGNU { } cfg.settings}";
DynamicUser = true;
StateDirectory = "newt";
StateDirectoryMode = "0700";

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -8,7 +8,7 @@
let
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
inherit (cfg)
cert

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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