From 1f4c50ab8116b151fb9a007b2dbf46decd7a1483 Mon Sep 17 00:00:00 2001 From: Lukas Wurzinger Date: Tue, 21 Oct 2025 15:02:59 +0200 Subject: [PATCH] lib/cli: deprecate toGNUCommandLine --- doc/release-notes/rl-2511.section.md | 2 + lib/cli.nix | 66 ++++++++++--------- nixos/modules/hardware/printers.nix | 2 +- .../services/finance/libeufin/common.nix | 6 +- nixos/modules/services/hardware/undervolt.nix | 2 +- .../services/home-automation/ebusd.nix | 2 +- nixos/modules/services/mail/mailpit.nix | 2 +- nixos/modules/services/misc/paperless.nix | 2 +- .../services/networking/gns3-server.nix | 2 +- .../services/networking/hylafax/systemd.nix | 12 ++-- nixos/modules/services/networking/newt.nix | 2 +- .../modules/services/networking/syncthing.nix | 2 +- .../modules/services/networking/wstunnel.nix | 2 +- nixos/modules/services/security/tsidp.nix | 2 +- nixos/modules/services/system/earlyoom.nix | 2 +- nixos/modules/services/system/self-deploy.nix | 2 +- .../services/web-apps/c2fmzq-server.nix | 6 +- .../services/web-apps/libretranslate.nix | 2 +- nixos/modules/services/web-apps/zitadel.nix | 2 +- .../modules/services/web-servers/fcgiwrap.nix | 2 +- .../system/boot/systemd/journald-gateway.nix | 2 +- .../system/boot/systemd/journald-remote.nix | 2 +- nixos/modules/virtualisation/containerd.nix | 2 +- .../virtualisation/virtualbox-image.nix | 4 +- pkgs/build-support/writers/scripts.nix | 8 ++- pkgs/by-name/an/antora/test/default.nix | 2 +- pkgs/by-name/li/lightway/package.nix | 2 +- .../dhall/build-dhall-package.nix | 2 +- 28 files changed, 81 insertions(+), 65 deletions(-) diff --git a/doc/release-notes/rl-2511.section.md b/doc/release-notes/rl-2511.section.md index df2eb32e9ef1..6793072fcf79 100644 --- a/doc/release-notes/rl-2511.section.md +++ b/doc/release-notes/rl-2511.section.md @@ -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`. diff --git a/lib/cli.nix b/lib/cli.nix index 487f7f44e969..f0ebeb76c4c2 100644 --- a/lib/cli.nix +++ b/lib/cli.nix @@ -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. diff --git a/nixos/modules/hardware/printers.nix b/nixos/modules/hardware/printers.nix index 8dbfea78a516..23f656579fe6 100644 --- a/nixos/modules/hardware/printers.nix +++ b/nixos/modules/hardware/printers.nix @@ -10,7 +10,7 @@ let ensurePrinter = p: let - args = lib.cli.toGNUCommandLineShell { } ( + args = lib.cli.toCommandLineShellGNU { } ( { p = p.name; v = p.deviceUri; diff --git a/nixos/modules/services/finance/libeufin/common.nix b/nixos/modules/services/finance/libeufin/common.nix index 71133248d607..461a96940123 100644 --- a/nixos/modules/services/finance/libeufin/common.nix +++ b/nixos/modules/services/finance/libeufin/common.nix @@ -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; }; diff --git a/nixos/modules/services/hardware/undervolt.nix b/nixos/modules/services/hardware/undervolt.nix index 5a8ad9806ef1..dd020181a6fe 100644 --- a/nixos/modules/services/hardware/undervolt.nix +++ b/nixos/modules/services/hardware/undervolt.nix @@ -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 diff --git a/nixos/modules/services/home-automation/ebusd.nix b/nixos/modules/services/home-automation/ebusd.nix index 3b98408ec9cc..7ee7d0751303 100644 --- a/nixos/modules/services/home-automation/ebusd.nix +++ b/nixos/modules/services/home-automation/ebusd.nix @@ -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) diff --git a/nixos/modules/services/mail/mailpit.nix b/nixos/modules/services/mail/mailpit.nix index 6bc368e91f5f..c3b888f15c9b 100644 --- a/nixos/modules/services/mail/mailpit.nix +++ b/nixos/modules/services/mail/mailpit.nix @@ -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 { diff --git a/nixos/modules/services/misc/paperless.nix b/nixos/modules/services/misc/paperless.nix index 8ab3372c75d7..14bb792790a7 100644 --- a/nixos/modules/services/misc/paperless.nix +++ b/nixos/modules/services/misc/paperless.nix @@ -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 } ''; }; diff --git a/nixos/modules/services/networking/gns3-server.nix b/nixos/modules/services/networking/gns3-server.nix index 21679a3d8364..6d69090744be 100644 --- a/nixos/modules/services/networking/gns3-server.nix +++ b/nixos/modules/services/networking/gns3-server.nix @@ -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; diff --git a/nixos/modules/services/networking/hylafax/systemd.nix b/nixos/modules/services/networking/hylafax/systemd.nix index d0cc0f230278..d08c08e6ec42 100644 --- a/nixos/modules/services/networking/hylafax/systemd.nix +++ b/nixos/modules/services/networking/hylafax/systemd.nix @@ -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)}"; diff --git a/nixos/modules/services/networking/newt.nix b/nixos/modules/services/networking/newt.nix index bc2d1cc001a9..9caa45351958 100644 --- a/nixos/modules/services/networking/newt.nix +++ b/nixos/modules/services/networking/newt.nix @@ -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"; diff --git a/nixos/modules/services/networking/syncthing.nix b/nixos/modules/services/networking/syncthing.nix index 645852b646d3..f1fcaf855e96 100644 --- a/nixos/modules/services/networking/syncthing.nix +++ b/nixos/modules/services/networking/syncthing.nix @@ -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; diff --git a/nixos/modules/services/networking/wstunnel.nix b/nixos/modules/services/networking/wstunnel.nix index ce6195ec1011..8d20b37eeea8 100644 --- a/nixos/modules/services/networking/wstunnel.nix +++ b/nixos/modules/services/networking/wstunnel.nix @@ -26,7 +26,7 @@ let str (listOf str) ]); - generate = lib.cli.toGNUCommandLineShell { }; + generate = lib.cli.toCommandLineShellGNU { }; }; hostPortToString = { host, port, ... }: "${host}:${toString port}"; diff --git a/nixos/modules/services/security/tsidp.nix b/nixos/modules/services/security/tsidp.nix index 4b854cf183ca..5d1a32522875 100644 --- a/nixos/modules/services/security/tsidp.nix +++ b/nixos/modules/services/security/tsidp.nix @@ -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; diff --git a/nixos/modules/services/system/earlyoom.nix b/nixos/modules/services/system/earlyoom.nix index 674e075b9ad4..f52c4b4fb4e2 100644 --- a/nixos/modules/services/system/earlyoom.nix +++ b/nixos/modules/services/system/earlyoom.nix @@ -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}"; diff --git a/nixos/modules/services/system/self-deploy.nix b/nixos/modules/services/system/self-deploy.nix index 4f11e8df18ad..bde3ac811569 100644 --- a/nixos/modules/services/system/self-deploy.nix +++ b/nixos/modules/services/system/self-deploy.nix @@ -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; } diff --git a/nixos/modules/services/web-apps/c2fmzq-server.nix b/nixos/modules/services/web-apps/c2fmzq-server.nix index f1935e05407f..a7622d384cf3 100644 --- a/nixos/modules/services/web-apps/c2fmzq-server.nix +++ b/nixos/modules/services/web-apps/c2fmzq-server.nix @@ -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 diff --git a/nixos/modules/services/web-apps/libretranslate.nix b/nixos/modules/services/web-apps/libretranslate.nix index 1664b9ef4581..5ac68ad3c919 100644 --- a/nixos/modules/services/web-apps/libretranslate.nix +++ b/nixos/modules/services/web-apps/libretranslate.nix @@ -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; diff --git a/nixos/modules/services/web-apps/zitadel.nix b/nixos/modules/services/web-apps/zitadel.nix index c097d36d9039..6cfd1bbd4680 100644 --- a/nixos/modules/services/web-apps/zitadel.nix +++ b/nixos/modules/services/web-apps/zitadel.nix @@ -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; diff --git a/nixos/modules/services/web-servers/fcgiwrap.nix b/nixos/modules/services/web-servers/fcgiwrap.nix index 992f4a46ff4b..493cd710c1bb 100644 --- a/nixos/modules/services/web-servers/fcgiwrap.nix +++ b/nixos/modules/services/web-servers/fcgiwrap.nix @@ -151,7 +151,7 @@ in serviceConfig = { ExecStart = '' ${pkgs.fcgiwrap}/sbin/fcgiwrap ${ - cli.toGNUCommandLineShell { } ( + cli.toCommandLineShellGNU { } ( { c = cfg.process.prefork; } diff --git a/nixos/modules/system/boot/systemd/journald-gateway.nix b/nixos/modules/system/boot/systemd/journald-gateway.nix index b6cf300d3bfb..f0d80077e6d6 100644 --- a/nixos/modules/system/boot/systemd/journald-gateway.nix +++ b/nixos/modules/system/boot/systemd/journald-gateway.nix @@ -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 diff --git a/nixos/modules/system/boot/systemd/journald-remote.nix b/nixos/modules/system/boot/systemd/journald-remote.nix index 89baf421f591..7216c179b3a0 100644 --- a/nixos/modules/system/boot/systemd/journald-remote.nix +++ b/nixos/modules/system/boot/systemd/journald-remote.nix @@ -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"; diff --git a/nixos/modules/virtualisation/containerd.nix b/nixos/modules/virtualisation/containerd.nix index 9e061f851126..c43db34dbf99 100644 --- a/nixos/modules/virtualisation/containerd.nix +++ b/nixos/modules/virtualisation/containerd.nix @@ -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"; diff --git a/nixos/modules/virtualisation/virtualbox-image.nix b/nixos/modules/virtualisation/virtualbox-image.nix index 04d36c9ce82f..25de9ac0ce86 100644 --- a/nixos/modules/virtualisation/virtualbox-image.nix +++ b/nixos/modules/virtualisation/virtualbox-image.nix @@ -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) '' diff --git a/pkgs/build-support/writers/scripts.nix b/pkgs/build-support/writers/scripts.nix index bd4e9209ce67..8f2110bdfa58 100644 --- a/pkgs/build-support/writers/scripts.nix +++ b/pkgs/build-support/writers/scripts.nix @@ -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 = "."; diff --git a/pkgs/by-name/an/antora/test/default.nix b/pkgs/by-name/an/antora/test/default.nix index ce5e0d5f50bb..b473a87b1434 100644 --- a/pkgs/by-name/an/antora/test/default.nix +++ b/pkgs/by-name/an/antora/test/default.nix @@ -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"; diff --git a/pkgs/by-name/li/lightway/package.nix b/pkgs/by-name/li/lightway/package.nix index 0bf4c6a92840..82c22ee4df25 100644 --- a/pkgs/by-name/li/lightway/package.nix +++ b/pkgs/by-name/li/lightway/package.nix @@ -21,7 +21,7 @@ rustPlatform.buildRustPackage { cargoHash = "sha256-RFlac10XFJXT3Giayy31kZ3Nn1Q+YsPt/zCdkSV0Atk="; - cargoBuildFlags = lib.cli.toGNUCommandLine { } { + cargoBuildFlags = lib.cli.toCommandLineGNU { } { package = [ "lightway-client" "lightway-server" diff --git a/pkgs/development/interpreters/dhall/build-dhall-package.nix b/pkgs/development/interpreters/dhall/build-dhall-package.nix index 214fe7f92d28..3ce1c8fceb75 100644 --- a/pkgs/development/interpreters/dhall/build-dhall-package.nix +++ b/pkgs/development/interpreters/dhall/build-dhall-package.nix @@ -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;