From ac5f147afca56a7fb4c9b21dcc28134661b923f0 Mon Sep 17 00:00:00 2001 From: Valentin Gagarin Date: Sun, 3 Mar 2024 22:37:55 +0100 Subject: [PATCH 1/2] fix `nix help-stores` the crash when calling `nix help-stores` was probably introduced an artifact from a prior untangling of merge conflicts. that said, `nix help-stores` should eventually cease to exist in favor of dedicated `--help` outputs and `man` pages for the various store types. --- doc/manual/generate-manpage.nix | 2 +- doc/manual/generate-settings.nix | 2 +- doc/manual/generate-store-info.nix | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/manual/generate-manpage.nix b/doc/manual/generate-manpage.nix index 14136016d..f799d393e 100644 --- a/doc/manual/generate-manpage.nix +++ b/doc/manual/generate-manpage.nix @@ -3,7 +3,7 @@ let attrNames attrValues fromJSON listToAttrs mapAttrs groupBy concatStringsSep concatMap length lessThan replaceStrings sort; inherit (import ) attrsToList concatStrings optionalString filterAttrs trim squash unique; - showStoreDocs = import ./generate-store-info.nix; + showStoreDocs = import ; in inlineHTML: commandDump: diff --git a/doc/manual/generate-settings.nix b/doc/manual/generate-settings.nix index 8736bb793..3add10075 100644 --- a/doc/manual/generate-settings.nix +++ b/doc/manual/generate-settings.nix @@ -1,6 +1,6 @@ let inherit (builtins) attrValues concatStringsSep isAttrs isBool mapAttrs; - inherit (import ./utils.nix) concatStrings indent optionalString squash; + inherit (import ) concatStrings indent optionalString squash; in # `inlineHTML` is a hack to accommodate inconsistent output from `lowdown` diff --git a/doc/manual/generate-store-info.nix b/doc/manual/generate-store-info.nix index 36215aadf..73defcb71 100644 --- a/doc/manual/generate-store-info.nix +++ b/doc/manual/generate-store-info.nix @@ -1,7 +1,7 @@ let inherit (builtins) attrValues mapAttrs; - inherit (import ./utils.nix) concatStrings optionalString; - showSettings = import ./generate-settings.nix; + inherit (import ) concatStrings optionalString; + showSettings = import ; in inlineHTML: storesInfo: From c2122d0ebc6892a06576fa872ae04007c3d2adce Mon Sep 17 00:00:00 2001 From: Valentin Gagarin Date: Mon, 4 Mar 2024 10:11:41 +0100 Subject: [PATCH 2/2] add tests for showing help --- flake.nix | 1 + tests/functional/help.sh | 69 +++++++++++++++++++++++++++++++++++++++ tests/functional/local.mk | 3 +- 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 tests/functional/help.sh diff --git a/flake.nix b/flake.nix index 5cf2a2419..c538e47e8 100644 --- a/flake.nix +++ b/flake.nix @@ -188,6 +188,7 @@ buildPackages.mercurial # FIXME: remove? only needed for tests buildPackages.jq # Also for custom mdBook preprocessor. buildPackages.openssh # only needed for tests (ssh-keygen) + buildPackages.man # needed for testing `nix-* --help` ] ++ lib.optionals stdenv.hostPlatform.isLinux [(buildPackages.util-linuxMinimal or buildPackages.utillinuxMinimal)]; diff --git a/tests/functional/help.sh b/tests/functional/help.sh new file mode 100644 index 000000000..868f5d2e9 --- /dev/null +++ b/tests/functional/help.sh @@ -0,0 +1,69 @@ +source common.sh + +clearStore + +# test help output + +nix-build --help +nix-shell --help + +nix-env --help +nix-env --install --help +nix-env --upgrade --help +nix-env --uninstall --help +nix-env --set --help +nix-env --set-flag --help +nix-env --query --help +nix-env --switch-profile --help +nix-env --list-generations --help +nix-env --delete-generations --help +nix-env --switch-generation --help +nix-env --rollback --help + +nix-store --help +nix-store --realise --help +nix-store --serve --help +nix-store --gc --help +nix-store --delete --help +nix-store --query --help +nix-store --add --help +nix-store --add-fixed --help +nix-store --verify --help +nix-store --verify-path --help +nix-store --repair-path --help +nix-store --dump --help +nix-store --restore --help +nix-store --export --help +nix-store --import --help +nix-store --optimise --help +nix-store --read-log --help +nix-store --dump-db --help +nix-store --load-db --help +nix-store --print-env --help +nix-store --generate-binary-cache-key --help + +nix-channel --help +nix-collect-garbage --help +nix-copy-closure --help +nix-daemon --help +nix-hash --help +nix-instantiate --help +nix-prefetch-url --help + +function subcommands() { + jq -r ' +def recurse($prefix): + to_entries[] | + ($prefix + [.key]) as $newPrefix | + (if .value | has("commands") then + ($newPrefix, (.value.commands | recurse($newPrefix))) + else + $newPrefix + end); +.args.commands | recurse([]) | join(" ") +' +} + +nix __dump-cli | subcommands | while IFS= read -r cmd; do + nix $cmd --help +done diff --git a/tests/functional/local.mk b/tests/functional/local.mk index 21dabca88..6241c15d3 100644 --- a/tests/functional/local.mk +++ b/tests/functional/local.mk @@ -124,7 +124,8 @@ nix_tests = \ toString-path.sh \ read-only-store.sh \ nested-sandboxing.sh \ - impure-env.sh + impure-env.sh \ + help.sh ifeq ($(HAVE_LIBCPUID), 1) nix_tests += compute-levels.sh