From 8f4200d165b73db63dc277e9984a480984415593 Mon Sep 17 00:00:00 2001 From: Anderson Torres Date: Wed, 14 Aug 2024 11:16:23 -0300 Subject: [PATCH 01/12] installShellFiles: move setup script to the same directory So that it can be migrated to by-name later. --- pkgs/build-support/install-shell-files/default.nix | 4 ++-- .../setup-hook.sh} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename pkgs/build-support/{setup-hooks/install-shell-files.sh => install-shell-files/setup-hook.sh} (100%) diff --git a/pkgs/build-support/install-shell-files/default.nix b/pkgs/build-support/install-shell-files/default.nix index d50661ddc65d..00f3caa7f721 100644 --- a/pkgs/build-support/install-shell-files/default.nix +++ b/pkgs/build-support/install-shell-files/default.nix @@ -1,8 +1,8 @@ { makeSetupHook, tests }: -# See the header comment in ../setup-hooks/install-shell-files.sh for example usage. +# See the header comment in ./setup-hook.sh for example usage. let - setupHook = makeSetupHook { name = "install-shell-files"; } ../setup-hooks/install-shell-files.sh; + setupHook = makeSetupHook { name = "install-shell-files"; } ./setup-hook.sh; in setupHook.overrideAttrs (oldAttrs: { diff --git a/pkgs/build-support/setup-hooks/install-shell-files.sh b/pkgs/build-support/install-shell-files/setup-hook.sh similarity index 100% rename from pkgs/build-support/setup-hooks/install-shell-files.sh rename to pkgs/build-support/install-shell-files/setup-hook.sh From f72e74d7aef142ea16d0841fa4322fc1310bb913 Mon Sep 17 00:00:00 2001 From: Anderson Torres Date: Wed, 14 Aug 2024 11:34:43 -0300 Subject: [PATCH 02/12] installShellFiles: migrate tests to tests subdirectory Rationale: Since RFCs 140 and 146, the old category-based hierarchy is deprecated and obsolete, and a new approach took place: packages should be as self-contained as possible. This paradigm is reflected in many new strict checks that prohibit a package to refer to files outside its directory tree. Following this spirit, this commit essentially moves nixpkgs pkgs/test/default.nix to ./tests/default.nix. Further, to keep the top-level `tests` attribute, a green alias is kept in the place of older file. --- .../install-shell-files/default.nix | 4 +- .../install-shell-files/tests/default.nix | 125 +++++++++++++++++ pkgs/test/install-shell-files/default.nix | 126 +----------------- 3 files changed, 129 insertions(+), 126 deletions(-) create mode 100644 pkgs/build-support/install-shell-files/tests/default.nix diff --git a/pkgs/build-support/install-shell-files/default.nix b/pkgs/build-support/install-shell-files/default.nix index 00f3caa7f721..1b7351847258 100644 --- a/pkgs/build-support/install-shell-files/default.nix +++ b/pkgs/build-support/install-shell-files/default.nix @@ -1,4 +1,4 @@ -{ makeSetupHook, tests }: +{ callPackage, makeSetupHook }: # See the header comment in ./setup-hook.sh for example usage. let @@ -7,6 +7,6 @@ in setupHook.overrideAttrs (oldAttrs: { passthru = (oldAttrs.passthru or {}) // { - tests = tests.install-shell-files; + tests = callPackage ./tests { }; }; }) diff --git a/pkgs/build-support/install-shell-files/tests/default.nix b/pkgs/build-support/install-shell-files/tests/default.nix new file mode 100644 index 000000000000..aef5acc1de6b --- /dev/null +++ b/pkgs/build-support/install-shell-files/tests/default.nix @@ -0,0 +1,125 @@ +{ lib, runCommandLocal, recurseIntoAttrs, installShellFiles }: + +let + runTest = name: env: buildCommand: + runCommandLocal "install-shell-files--${name}" ({ + nativeBuildInputs = [ installShellFiles ]; + meta.platforms = lib.platforms.all; + } // env) buildCommand; +in + +recurseIntoAttrs { + # installManPage + + install-manpage = runTest "install-manpage" {} '' + mkdir -p doc + echo foo > doc/foo.1 + echo bar > doc/bar.2.gz + echo baz > doc/baz.3 + + installManPage doc/* + + cmp doc/foo.1 $out/share/man/man1/foo.1 + cmp doc/bar.2.gz $out/share/man/man2/bar.2.gz + cmp doc/baz.3 $out/share/man/man3/baz.3 + ''; + install-manpage-outputs = runTest "install-manpage-outputs" { + outputs = [ "out" "man" "devman" ]; + } '' + mkdir -p doc + echo foo > doc/foo.1 + echo bar > doc/bar.3 + + installManPage doc/* + + # assert they didn't go into $out + [[ ! -f $out/share/man/man1/foo.1 && ! -f $out/share/man/man3/bar.3 ]] + + # foo.1 alone went into man + cmp doc/foo.1 ''${!outputMan:?}/share/man/man1/foo.1 + [[ ! -f ''${!outputMan:?}/share/man/man3/bar.3 ]] + + # bar.3 alone went into devman + cmp doc/bar.3 ''${!outputDevman:?}/share/man/man3/bar.3 + [[ ! -f ''${!outputDevman:?}/share/man/man1/foo.1 ]] + + touch $out + ''; + + # installShellCompletion + + install-completion = runTest "install-completion" {} '' + echo foo > foo + echo bar > bar + echo baz > baz + echo qux > qux.zsh + echo quux > quux + + installShellCompletion --bash foo bar --zsh baz qux.zsh --fish quux + + cmp foo $out/share/bash-completion/completions/foo + cmp bar $out/share/bash-completion/completions/bar + cmp baz $out/share/zsh/site-functions/_baz + cmp qux.zsh $out/share/zsh/site-functions/_qux + cmp quux $out/share/fish/vendor_completions.d/quux + ''; + install-completion-output = runTest "install-completion-output" { + outputs = [ "out" "bin" ]; + } '' + echo foo > foo + + installShellCompletion --bash foo + + # assert it didn't go into $out + [[ ! -f $out/share/bash-completion/completions/foo ]] + + cmp foo ''${!outputBin:?}/share/bash-completion/completions/foo + + touch $out + ''; + install-completion-name = runTest "install-completion-name" {} '' + echo foo > foo + echo bar > bar + echo baz > baz + + installShellCompletion --bash --name foobar.bash foo --zsh --name _foobar bar --fish baz + + cmp foo $out/share/bash-completion/completions/foobar.bash + cmp bar $out/share/zsh/site-functions/_foobar + cmp baz $out/share/fish/vendor_completions.d/baz + ''; + install-completion-inference = runTest "install-completion-inference" {} '' + echo foo > foo.bash + echo bar > bar.zsh + echo baz > baz.fish + + installShellCompletion foo.bash bar.zsh baz.fish + + cmp foo.bash $out/share/bash-completion/completions/foo.bash + cmp bar.zsh $out/share/zsh/site-functions/_bar + cmp baz.fish $out/share/fish/vendor_completions.d/baz.fish + ''; + install-completion-cmd = runTest "install-completion-cmd" {} '' + echo foo > foo.bash + echo bar > bar.zsh + echo baz > baz.fish + echo qux > qux.fish + + installShellCompletion --cmd foobar --bash foo.bash --zsh bar.zsh --fish baz.fish --name qux qux.fish + + cmp foo.bash $out/share/bash-completion/completions/foobar.bash + cmp bar.zsh $out/share/zsh/site-functions/_foobar + cmp baz.fish $out/share/fish/vendor_completions.d/foobar.fish + cmp qux.fish $out/share/fish/vendor_completions.d/qux + ''; + install-completion-fifo = runTest "install-completion-fifo" {} '' + installShellCompletion \ + --bash --name foo.bash <(echo foo) \ + --zsh --name _foo <(echo bar) \ + --fish --name foo.fish <(echo baz) + + [[ $(<$out/share/bash-completion/completions/foo.bash) == foo ]] || { echo "foo.bash comparison failed"; exit 1; } + [[ $(<$out/share/zsh/site-functions/_foo) == bar ]] || { echo "_foo comparison failed"; exit 1; } + [[ $(<$out/share/fish/vendor_completions.d/foo.fish) == baz ]] || { echo "foo.fish comparison failed"; exit 1; } + ''; +} diff --git a/pkgs/test/install-shell-files/default.nix b/pkgs/test/install-shell-files/default.nix index aef5acc1de6b..21894698fe1b 100644 --- a/pkgs/test/install-shell-files/default.nix +++ b/pkgs/test/install-shell-files/default.nix @@ -1,125 +1,3 @@ -{ lib, runCommandLocal, recurseIntoAttrs, installShellFiles }: +{ installShellFiles }: -let - runTest = name: env: buildCommand: - runCommandLocal "install-shell-files--${name}" ({ - nativeBuildInputs = [ installShellFiles ]; - meta.platforms = lib.platforms.all; - } // env) buildCommand; -in - -recurseIntoAttrs { - # installManPage - - install-manpage = runTest "install-manpage" {} '' - mkdir -p doc - echo foo > doc/foo.1 - echo bar > doc/bar.2.gz - echo baz > doc/baz.3 - - installManPage doc/* - - cmp doc/foo.1 $out/share/man/man1/foo.1 - cmp doc/bar.2.gz $out/share/man/man2/bar.2.gz - cmp doc/baz.3 $out/share/man/man3/baz.3 - ''; - install-manpage-outputs = runTest "install-manpage-outputs" { - outputs = [ "out" "man" "devman" ]; - } '' - mkdir -p doc - echo foo > doc/foo.1 - echo bar > doc/bar.3 - - installManPage doc/* - - # assert they didn't go into $out - [[ ! -f $out/share/man/man1/foo.1 && ! -f $out/share/man/man3/bar.3 ]] - - # foo.1 alone went into man - cmp doc/foo.1 ''${!outputMan:?}/share/man/man1/foo.1 - [[ ! -f ''${!outputMan:?}/share/man/man3/bar.3 ]] - - # bar.3 alone went into devman - cmp doc/bar.3 ''${!outputDevman:?}/share/man/man3/bar.3 - [[ ! -f ''${!outputDevman:?}/share/man/man1/foo.1 ]] - - touch $out - ''; - - # installShellCompletion - - install-completion = runTest "install-completion" {} '' - echo foo > foo - echo bar > bar - echo baz > baz - echo qux > qux.zsh - echo quux > quux - - installShellCompletion --bash foo bar --zsh baz qux.zsh --fish quux - - cmp foo $out/share/bash-completion/completions/foo - cmp bar $out/share/bash-completion/completions/bar - cmp baz $out/share/zsh/site-functions/_baz - cmp qux.zsh $out/share/zsh/site-functions/_qux - cmp quux $out/share/fish/vendor_completions.d/quux - ''; - install-completion-output = runTest "install-completion-output" { - outputs = [ "out" "bin" ]; - } '' - echo foo > foo - - installShellCompletion --bash foo - - # assert it didn't go into $out - [[ ! -f $out/share/bash-completion/completions/foo ]] - - cmp foo ''${!outputBin:?}/share/bash-completion/completions/foo - - touch $out - ''; - install-completion-name = runTest "install-completion-name" {} '' - echo foo > foo - echo bar > bar - echo baz > baz - - installShellCompletion --bash --name foobar.bash foo --zsh --name _foobar bar --fish baz - - cmp foo $out/share/bash-completion/completions/foobar.bash - cmp bar $out/share/zsh/site-functions/_foobar - cmp baz $out/share/fish/vendor_completions.d/baz - ''; - install-completion-inference = runTest "install-completion-inference" {} '' - echo foo > foo.bash - echo bar > bar.zsh - echo baz > baz.fish - - installShellCompletion foo.bash bar.zsh baz.fish - - cmp foo.bash $out/share/bash-completion/completions/foo.bash - cmp bar.zsh $out/share/zsh/site-functions/_bar - cmp baz.fish $out/share/fish/vendor_completions.d/baz.fish - ''; - install-completion-cmd = runTest "install-completion-cmd" {} '' - echo foo > foo.bash - echo bar > bar.zsh - echo baz > baz.fish - echo qux > qux.fish - - installShellCompletion --cmd foobar --bash foo.bash --zsh bar.zsh --fish baz.fish --name qux qux.fish - - cmp foo.bash $out/share/bash-completion/completions/foobar.bash - cmp bar.zsh $out/share/zsh/site-functions/_foobar - cmp baz.fish $out/share/fish/vendor_completions.d/foobar.fish - cmp qux.fish $out/share/fish/vendor_completions.d/qux - ''; - install-completion-fifo = runTest "install-completion-fifo" {} '' - installShellCompletion \ - --bash --name foo.bash <(echo foo) \ - --zsh --name _foo <(echo bar) \ - --fish --name foo.fish <(echo baz) - - [[ $(<$out/share/bash-completion/completions/foo.bash) == foo ]] || { echo "foo.bash comparison failed"; exit 1; } - [[ $(<$out/share/zsh/site-functions/_foo) == bar ]] || { echo "_foo comparison failed"; exit 1; } - [[ $(<$out/share/fish/vendor_completions.d/foo.fish) == baz ]] || { echo "foo.fish comparison failed"; exit 1; } - ''; -} +installShellFiles.tests From 8b674370c42fd5312d53edd2002af0978ff3f2b9 Mon Sep 17 00:00:00 2001 From: Anderson Torres Date: Wed, 14 Aug 2024 11:59:49 -0300 Subject: [PATCH 03/12] installShellFiles: nixfmt-rfc-style --- .../install-shell-files/default.nix | 3 +- .../install-shell-files/tests/default.nix | 100 +++++++++++------- 2 files changed, 62 insertions(+), 41 deletions(-) diff --git a/pkgs/build-support/install-shell-files/default.nix b/pkgs/build-support/install-shell-files/default.nix index 1b7351847258..12595850c393 100644 --- a/pkgs/build-support/install-shell-files/default.nix +++ b/pkgs/build-support/install-shell-files/default.nix @@ -4,9 +4,8 @@ let setupHook = makeSetupHook { name = "install-shell-files"; } ./setup-hook.sh; in - setupHook.overrideAttrs (oldAttrs: { - passthru = (oldAttrs.passthru or {}) // { + passthru = (oldAttrs.passthru or { }) // { tests = callPackage ./tests { }; }; }) diff --git a/pkgs/build-support/install-shell-files/tests/default.nix b/pkgs/build-support/install-shell-files/tests/default.nix index aef5acc1de6b..456edc5c6330 100644 --- a/pkgs/build-support/install-shell-files/tests/default.nix +++ b/pkgs/build-support/install-shell-files/tests/default.nix @@ -1,17 +1,26 @@ -{ lib, runCommandLocal, recurseIntoAttrs, installShellFiles }: +{ + lib, + runCommandLocal, + recurseIntoAttrs, + installShellFiles, +}: let - runTest = name: env: buildCommand: - runCommandLocal "install-shell-files--${name}" ({ - nativeBuildInputs = [ installShellFiles ]; - meta.platforms = lib.platforms.all; - } // env) buildCommand; + runTest = + name: env: buildCommand: + runCommandLocal "install-shell-files--${name}" ( + { + nativeBuildInputs = [ installShellFiles ]; + meta.platforms = lib.platforms.all; + } + // env + ) buildCommand; in recurseIntoAttrs { # installManPage - install-manpage = runTest "install-manpage" {} '' + install-manpage = runTest "install-manpage" { } '' mkdir -p doc echo foo > doc/foo.1 echo bar > doc/bar.2.gz @@ -23,32 +32,39 @@ recurseIntoAttrs { cmp doc/bar.2.gz $out/share/man/man2/bar.2.gz cmp doc/baz.3 $out/share/man/man3/baz.3 ''; - install-manpage-outputs = runTest "install-manpage-outputs" { - outputs = [ "out" "man" "devman" ]; - } '' - mkdir -p doc - echo foo > doc/foo.1 - echo bar > doc/bar.3 + install-manpage-outputs = + runTest "install-manpage-outputs" + { + outputs = [ + "out" + "man" + "devman" + ]; + } + '' + mkdir -p doc + echo foo > doc/foo.1 + echo bar > doc/bar.3 - installManPage doc/* + installManPage doc/* - # assert they didn't go into $out - [[ ! -f $out/share/man/man1/foo.1 && ! -f $out/share/man/man3/bar.3 ]] + # assert they didn't go into $out + [[ ! -f $out/share/man/man1/foo.1 && ! -f $out/share/man/man3/bar.3 ]] - # foo.1 alone went into man - cmp doc/foo.1 ''${!outputMan:?}/share/man/man1/foo.1 - [[ ! -f ''${!outputMan:?}/share/man/man3/bar.3 ]] + # foo.1 alone went into man + cmp doc/foo.1 ''${!outputMan:?}/share/man/man1/foo.1 + [[ ! -f ''${!outputMan:?}/share/man/man3/bar.3 ]] - # bar.3 alone went into devman - cmp doc/bar.3 ''${!outputDevman:?}/share/man/man3/bar.3 - [[ ! -f ''${!outputDevman:?}/share/man/man1/foo.1 ]] + # bar.3 alone went into devman + cmp doc/bar.3 ''${!outputDevman:?}/share/man/man3/bar.3 + [[ ! -f ''${!outputDevman:?}/share/man/man1/foo.1 ]] - touch $out - ''; + touch $out + ''; # installShellCompletion - install-completion = runTest "install-completion" {} '' + install-completion = runTest "install-completion" { } '' echo foo > foo echo bar > bar echo baz > baz @@ -63,21 +79,27 @@ recurseIntoAttrs { cmp qux.zsh $out/share/zsh/site-functions/_qux cmp quux $out/share/fish/vendor_completions.d/quux ''; - install-completion-output = runTest "install-completion-output" { - outputs = [ "out" "bin" ]; - } '' - echo foo > foo + install-completion-output = + runTest "install-completion-output" + { + outputs = [ + "out" + "bin" + ]; + } + '' + echo foo > foo - installShellCompletion --bash foo + installShellCompletion --bash foo - # assert it didn't go into $out - [[ ! -f $out/share/bash-completion/completions/foo ]] + # assert it didn't go into $out + [[ ! -f $out/share/bash-completion/completions/foo ]] - cmp foo ''${!outputBin:?}/share/bash-completion/completions/foo + cmp foo ''${!outputBin:?}/share/bash-completion/completions/foo - touch $out - ''; - install-completion-name = runTest "install-completion-name" {} '' + touch $out + ''; + install-completion-name = runTest "install-completion-name" { } '' echo foo > foo echo bar > bar echo baz > baz @@ -88,7 +110,7 @@ recurseIntoAttrs { cmp bar $out/share/zsh/site-functions/_foobar cmp baz $out/share/fish/vendor_completions.d/baz ''; - install-completion-inference = runTest "install-completion-inference" {} '' + install-completion-inference = runTest "install-completion-inference" { } '' echo foo > foo.bash echo bar > bar.zsh echo baz > baz.fish @@ -99,7 +121,7 @@ recurseIntoAttrs { cmp bar.zsh $out/share/zsh/site-functions/_bar cmp baz.fish $out/share/fish/vendor_completions.d/baz.fish ''; - install-completion-cmd = runTest "install-completion-cmd" {} '' + install-completion-cmd = runTest "install-completion-cmd" { } '' echo foo > foo.bash echo bar > bar.zsh echo baz > baz.fish @@ -112,7 +134,7 @@ recurseIntoAttrs { cmp baz.fish $out/share/fish/vendor_completions.d/foobar.fish cmp qux.fish $out/share/fish/vendor_completions.d/qux ''; - install-completion-fifo = runTest "install-completion-fifo" {} '' + install-completion-fifo = runTest "install-completion-fifo" { } '' installShellCompletion \ --bash --name foo.bash <(echo foo) \ --zsh --name _foo <(echo bar) \ From e548b3170836504cc2be8159c9aadccfbd63c469 Mon Sep 17 00:00:00 2001 From: Anderson Torres Date: Wed, 14 Aug 2024 12:12:18 -0300 Subject: [PATCH 04/12] installShellFiles: migrate to by-name --- .../default.nix => by-name/in/installShellFiles/package.nix} | 0 .../in/installShellFiles}/setup-hook.sh | 0 .../in/installShellFiles}/tests/default.nix | 0 pkgs/top-level/all-packages.nix | 2 -- 4 files changed, 2 deletions(-) rename pkgs/{build-support/install-shell-files/default.nix => by-name/in/installShellFiles/package.nix} (100%) rename pkgs/{build-support/install-shell-files => by-name/in/installShellFiles}/setup-hook.sh (100%) rename pkgs/{build-support/install-shell-files => by-name/in/installShellFiles}/tests/default.nix (100%) diff --git a/pkgs/build-support/install-shell-files/default.nix b/pkgs/by-name/in/installShellFiles/package.nix similarity index 100% rename from pkgs/build-support/install-shell-files/default.nix rename to pkgs/by-name/in/installShellFiles/package.nix diff --git a/pkgs/build-support/install-shell-files/setup-hook.sh b/pkgs/by-name/in/installShellFiles/setup-hook.sh similarity index 100% rename from pkgs/build-support/install-shell-files/setup-hook.sh rename to pkgs/by-name/in/installShellFiles/setup-hook.sh diff --git a/pkgs/build-support/install-shell-files/tests/default.nix b/pkgs/by-name/in/installShellFiles/tests/default.nix similarity index 100% rename from pkgs/build-support/install-shell-files/tests/default.nix rename to pkgs/by-name/in/installShellFiles/tests/default.nix diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 95a3f8e10570..f6e2250c6bc5 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -1204,8 +1204,6 @@ with pkgs; inherit url; }; - installShellFiles = callPackage ../build-support/install-shell-files { }; - lazydocker = callPackage ../tools/misc/lazydocker { }; ld-is-cc-hook = makeSetupHook { name = "ld-is-cc-hook"; } From 98e9fbb530d572f057d1b9ea787a5a67a1d3a24c Mon Sep 17 00:00:00 2001 From: Anderson Torres Date: Wed, 14 Aug 2024 13:06:30 -0300 Subject: [PATCH 05/12] installShellFiles: dismember tests into their own files It makes the maintenance and creation of tests more intuitive: just throw a Nix package under tests! --- pkgs/by-name/in/installShellFiles/package.nix | 11 +- .../in/installShellFiles/tests/default.nix | 147 ------------------ .../tests/install-completion-cmd.nix | 24 +++ .../tests/install-completion-fifo.nix | 21 +++ .../tests/install-completion-inference.nix | 22 +++ .../tests/install-completion-name.nix | 22 +++ .../tests/install-completion-output.nix | 27 ++++ .../tests/install-completion.nix | 26 ++++ .../tests/install-manpage-outputs.nix | 36 +++++ .../tests/install-manpage.nix | 23 +++ 10 files changed, 210 insertions(+), 149 deletions(-) delete mode 100644 pkgs/by-name/in/installShellFiles/tests/default.nix create mode 100644 pkgs/by-name/in/installShellFiles/tests/install-completion-cmd.nix create mode 100644 pkgs/by-name/in/installShellFiles/tests/install-completion-fifo.nix create mode 100644 pkgs/by-name/in/installShellFiles/tests/install-completion-inference.nix create mode 100644 pkgs/by-name/in/installShellFiles/tests/install-completion-name.nix create mode 100644 pkgs/by-name/in/installShellFiles/tests/install-completion-output.nix create mode 100644 pkgs/by-name/in/installShellFiles/tests/install-completion.nix create mode 100644 pkgs/by-name/in/installShellFiles/tests/install-manpage-outputs.nix create mode 100644 pkgs/by-name/in/installShellFiles/tests/install-manpage.nix diff --git a/pkgs/by-name/in/installShellFiles/package.nix b/pkgs/by-name/in/installShellFiles/package.nix index 12595850c393..87787ad872ee 100644 --- a/pkgs/by-name/in/installShellFiles/package.nix +++ b/pkgs/by-name/in/installShellFiles/package.nix @@ -1,4 +1,8 @@ -{ callPackage, makeSetupHook }: +{ + lib, + callPackage, + makeSetupHook, +}: # See the header comment in ./setup-hook.sh for example usage. let @@ -6,6 +10,9 @@ let in setupHook.overrideAttrs (oldAttrs: { passthru = (oldAttrs.passthru or { }) // { - tests = callPackage ./tests { }; + tests = lib.packagesFromDirectoryRecursive { + inherit callPackage; + directory = ./tests; + }; }; }) diff --git a/pkgs/by-name/in/installShellFiles/tests/default.nix b/pkgs/by-name/in/installShellFiles/tests/default.nix deleted file mode 100644 index 456edc5c6330..000000000000 --- a/pkgs/by-name/in/installShellFiles/tests/default.nix +++ /dev/null @@ -1,147 +0,0 @@ -{ - lib, - runCommandLocal, - recurseIntoAttrs, - installShellFiles, -}: - -let - runTest = - name: env: buildCommand: - runCommandLocal "install-shell-files--${name}" ( - { - nativeBuildInputs = [ installShellFiles ]; - meta.platforms = lib.platforms.all; - } - // env - ) buildCommand; -in - -recurseIntoAttrs { - # installManPage - - install-manpage = runTest "install-manpage" { } '' - mkdir -p doc - echo foo > doc/foo.1 - echo bar > doc/bar.2.gz - echo baz > doc/baz.3 - - installManPage doc/* - - cmp doc/foo.1 $out/share/man/man1/foo.1 - cmp doc/bar.2.gz $out/share/man/man2/bar.2.gz - cmp doc/baz.3 $out/share/man/man3/baz.3 - ''; - install-manpage-outputs = - runTest "install-manpage-outputs" - { - outputs = [ - "out" - "man" - "devman" - ]; - } - '' - mkdir -p doc - echo foo > doc/foo.1 - echo bar > doc/bar.3 - - installManPage doc/* - - # assert they didn't go into $out - [[ ! -f $out/share/man/man1/foo.1 && ! -f $out/share/man/man3/bar.3 ]] - - # foo.1 alone went into man - cmp doc/foo.1 ''${!outputMan:?}/share/man/man1/foo.1 - [[ ! -f ''${!outputMan:?}/share/man/man3/bar.3 ]] - - # bar.3 alone went into devman - cmp doc/bar.3 ''${!outputDevman:?}/share/man/man3/bar.3 - [[ ! -f ''${!outputDevman:?}/share/man/man1/foo.1 ]] - - touch $out - ''; - - # installShellCompletion - - install-completion = runTest "install-completion" { } '' - echo foo > foo - echo bar > bar - echo baz > baz - echo qux > qux.zsh - echo quux > quux - - installShellCompletion --bash foo bar --zsh baz qux.zsh --fish quux - - cmp foo $out/share/bash-completion/completions/foo - cmp bar $out/share/bash-completion/completions/bar - cmp baz $out/share/zsh/site-functions/_baz - cmp qux.zsh $out/share/zsh/site-functions/_qux - cmp quux $out/share/fish/vendor_completions.d/quux - ''; - install-completion-output = - runTest "install-completion-output" - { - outputs = [ - "out" - "bin" - ]; - } - '' - echo foo > foo - - installShellCompletion --bash foo - - # assert it didn't go into $out - [[ ! -f $out/share/bash-completion/completions/foo ]] - - cmp foo ''${!outputBin:?}/share/bash-completion/completions/foo - - touch $out - ''; - install-completion-name = runTest "install-completion-name" { } '' - echo foo > foo - echo bar > bar - echo baz > baz - - installShellCompletion --bash --name foobar.bash foo --zsh --name _foobar bar --fish baz - - cmp foo $out/share/bash-completion/completions/foobar.bash - cmp bar $out/share/zsh/site-functions/_foobar - cmp baz $out/share/fish/vendor_completions.d/baz - ''; - install-completion-inference = runTest "install-completion-inference" { } '' - echo foo > foo.bash - echo bar > bar.zsh - echo baz > baz.fish - - installShellCompletion foo.bash bar.zsh baz.fish - - cmp foo.bash $out/share/bash-completion/completions/foo.bash - cmp bar.zsh $out/share/zsh/site-functions/_bar - cmp baz.fish $out/share/fish/vendor_completions.d/baz.fish - ''; - install-completion-cmd = runTest "install-completion-cmd" { } '' - echo foo > foo.bash - echo bar > bar.zsh - echo baz > baz.fish - echo qux > qux.fish - - installShellCompletion --cmd foobar --bash foo.bash --zsh bar.zsh --fish baz.fish --name qux qux.fish - - cmp foo.bash $out/share/bash-completion/completions/foobar.bash - cmp bar.zsh $out/share/zsh/site-functions/_foobar - cmp baz.fish $out/share/fish/vendor_completions.d/foobar.fish - cmp qux.fish $out/share/fish/vendor_completions.d/qux - ''; - install-completion-fifo = runTest "install-completion-fifo" { } '' - installShellCompletion \ - --bash --name foo.bash <(echo foo) \ - --zsh --name _foo <(echo bar) \ - --fish --name foo.fish <(echo baz) - - [[ $(<$out/share/bash-completion/completions/foo.bash) == foo ]] || { echo "foo.bash comparison failed"; exit 1; } - [[ $(<$out/share/zsh/site-functions/_foo) == bar ]] || { echo "_foo comparison failed"; exit 1; } - [[ $(<$out/share/fish/vendor_completions.d/foo.fish) == baz ]] || { echo "foo.fish comparison failed"; exit 1; } - ''; -} diff --git a/pkgs/by-name/in/installShellFiles/tests/install-completion-cmd.nix b/pkgs/by-name/in/installShellFiles/tests/install-completion-cmd.nix new file mode 100644 index 000000000000..a8687ccc2c7d --- /dev/null +++ b/pkgs/by-name/in/installShellFiles/tests/install-completion-cmd.nix @@ -0,0 +1,24 @@ +{ + lib, + installShellFiles, + runCommandLocal, +}: + +runCommandLocal "install-shell-files--install-completion-cmd" + { + nativeBuildInputs = [ installShellFiles ]; + meta.platforms = lib.platforms.all; + } + '' + echo foo > foo.bash + echo bar > bar.zsh + echo baz > baz.fish + echo qux > qux.fish + + installShellCompletion --cmd foobar --bash foo.bash --zsh bar.zsh --fish baz.fish --name qux qux.fish + + cmp foo.bash $out/share/bash-completion/completions/foobar.bash + cmp bar.zsh $out/share/zsh/site-functions/_foobar + cmp baz.fish $out/share/fish/vendor_completions.d/foobar.fish + cmp qux.fish $out/share/fish/vendor_completions.d/qux + '' diff --git a/pkgs/by-name/in/installShellFiles/tests/install-completion-fifo.nix b/pkgs/by-name/in/installShellFiles/tests/install-completion-fifo.nix new file mode 100644 index 000000000000..2c777f0fb68a --- /dev/null +++ b/pkgs/by-name/in/installShellFiles/tests/install-completion-fifo.nix @@ -0,0 +1,21 @@ +{ + lib, + installShellFiles, + runCommandLocal, +}: + +runCommandLocal "install-shell-files--install-completion-fifo" + { + nativeBuildInputs = [ installShellFiles ]; + meta.platforms = lib.platforms.all; + } + '' + installShellCompletion \ + --bash --name foo.bash <(echo foo) \ + --zsh --name _foo <(echo bar) \ + --fish --name foo.fish <(echo baz) + + [[ $(<$out/share/bash-completion/completions/foo.bash) == foo ]] || { echo "foo.bash comparison failed"; exit 1; } + [[ $(<$out/share/zsh/site-functions/_foo) == bar ]] || { echo "_foo comparison failed"; exit 1; } + [[ $(<$out/share/fish/vendor_completions.d/foo.fish) == baz ]] || { echo "foo.fish comparison failed"; exit 1; } + '' diff --git a/pkgs/by-name/in/installShellFiles/tests/install-completion-inference.nix b/pkgs/by-name/in/installShellFiles/tests/install-completion-inference.nix new file mode 100644 index 000000000000..9a51965ccecb --- /dev/null +++ b/pkgs/by-name/in/installShellFiles/tests/install-completion-inference.nix @@ -0,0 +1,22 @@ +{ + lib, + installShellFiles, + runCommandLocal, +}: + +runCommandLocal "install-shell-files--install-completion-inference" + { + nativeBuildInputs = [ installShellFiles ]; + meta.platforms = lib.platforms.all; + } + '' + echo foo > foo.bash + echo bar > bar.zsh + echo baz > baz.fish + + installShellCompletion foo.bash bar.zsh baz.fish + + cmp foo.bash $out/share/bash-completion/completions/foo.bash + cmp bar.zsh $out/share/zsh/site-functions/_bar + cmp baz.fish $out/share/fish/vendor_completions.d/baz.fish + '' diff --git a/pkgs/by-name/in/installShellFiles/tests/install-completion-name.nix b/pkgs/by-name/in/installShellFiles/tests/install-completion-name.nix new file mode 100644 index 000000000000..2473318dee2c --- /dev/null +++ b/pkgs/by-name/in/installShellFiles/tests/install-completion-name.nix @@ -0,0 +1,22 @@ +{ + lib, + installShellFiles, + runCommandLocal, +}: + +runCommandLocal "install-shell-files--install-completion-name" + { + nativeBuildInputs = [ installShellFiles ]; + meta.platforms = lib.platforms.all; + } + '' + echo foo > foo + echo bar > bar + echo baz > baz + + installShellCompletion --bash --name foobar.bash foo --zsh --name _foobar bar --fish baz + + cmp foo $out/share/bash-completion/completions/foobar.bash + cmp bar $out/share/zsh/site-functions/_foobar + cmp baz $out/share/fish/vendor_completions.d/baz + '' diff --git a/pkgs/by-name/in/installShellFiles/tests/install-completion-output.nix b/pkgs/by-name/in/installShellFiles/tests/install-completion-output.nix new file mode 100644 index 000000000000..380b241e4f01 --- /dev/null +++ b/pkgs/by-name/in/installShellFiles/tests/install-completion-output.nix @@ -0,0 +1,27 @@ +{ + lib, + installShellFiles, + runCommandLocal, +}: + +runCommandLocal "install-shell-files--install-completion-output" + { + outputs = [ + "out" + "bin" + ]; + nativeBuildInputs = [ installShellFiles ]; + meta.platforms = lib.platforms.all; + } + '' + echo foo > foo + + installShellCompletion --bash foo + + # assert it didn't go into $out + [[ ! -f $out/share/bash-completion/completions/foo ]] + + cmp foo ''${!outputBin:?}/share/bash-completion/completions/foo + + touch $out + '' diff --git a/pkgs/by-name/in/installShellFiles/tests/install-completion.nix b/pkgs/by-name/in/installShellFiles/tests/install-completion.nix new file mode 100644 index 000000000000..2738dd647f56 --- /dev/null +++ b/pkgs/by-name/in/installShellFiles/tests/install-completion.nix @@ -0,0 +1,26 @@ +{ + lib, + installShellFiles, + runCommandLocal, +}: + +runCommandLocal "install-shell-files--install-completion" + { + nativeBuildInputs = [ installShellFiles ]; + meta.platforms = lib.platforms.all; + } + '' + echo foo > foo + echo bar > bar + echo baz > baz + echo qux > qux.zsh + echo quux > quux + + installShellCompletion --bash foo bar --zsh baz qux.zsh --fish quux + + cmp foo $out/share/bash-completion/completions/foo + cmp bar $out/share/bash-completion/completions/bar + cmp baz $out/share/zsh/site-functions/_baz + cmp qux.zsh $out/share/zsh/site-functions/_qux + cmp quux $out/share/fish/vendor_completions.d/quux + '' diff --git a/pkgs/by-name/in/installShellFiles/tests/install-manpage-outputs.nix b/pkgs/by-name/in/installShellFiles/tests/install-manpage-outputs.nix new file mode 100644 index 000000000000..4e249a9e5061 --- /dev/null +++ b/pkgs/by-name/in/installShellFiles/tests/install-manpage-outputs.nix @@ -0,0 +1,36 @@ +{ + lib, + installShellFiles, + runCommandLocal, +}: + +runCommandLocal "install-shell-files--install-manpage-outputs" + { + outputs = [ + "out" + "man" + "devman" + ]; + nativeBuildInputs = [ installShellFiles ]; + meta.platforms = lib.platforms.all; + } + '' + mkdir -p doc + echo foo > doc/foo.1 + echo bar > doc/bar.3 + + installManPage doc/* + + # assert they didn't go into $out + [[ ! -f $out/share/man/man1/foo.1 && ! -f $out/share/man/man3/bar.3 ]] + + # foo.1 alone went into man + cmp doc/foo.1 ''${!outputMan:?}/share/man/man1/foo.1 + [[ ! -f ''${!outputMan:?}/share/man/man3/bar.3 ]] + + # bar.3 alone went into devman + cmp doc/bar.3 ''${!outputDevman:?}/share/man/man3/bar.3 + [[ ! -f ''${!outputDevman:?}/share/man/man1/foo.1 ]] + + touch $out + '' diff --git a/pkgs/by-name/in/installShellFiles/tests/install-manpage.nix b/pkgs/by-name/in/installShellFiles/tests/install-manpage.nix new file mode 100644 index 000000000000..7b67d0aed94c --- /dev/null +++ b/pkgs/by-name/in/installShellFiles/tests/install-manpage.nix @@ -0,0 +1,23 @@ +{ + lib, + installShellFiles, + runCommandLocal, +}: + +runCommandLocal "install-shell-files--install-manpage" + { + nativeBuildInputs = [ installShellFiles ]; + meta.platforms = lib.platforms.all; + } + '' + mkdir -p doc + echo foo > doc/foo.1 + echo bar > doc/bar.2.gz + echo baz > doc/baz.3 + + installManPage doc/* + + cmp doc/foo.1 $out/share/man/man1/foo.1 + cmp doc/bar.2.gz $out/share/man/man2/bar.2.gz + cmp doc/baz.3 $out/share/man/man3/baz.3 + '' From 1c9d4799c297aa0a2c8292d8d4b97992aa7bdd7d Mon Sep 17 00:00:00 2001 From: Anderson Torres Date: Wed, 14 Aug 2024 13:16:44 -0300 Subject: [PATCH 06/12] installShellFiles: add new function installBin --- .../in/installShellFiles/setup-hook.sh | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pkgs/by-name/in/installShellFiles/setup-hook.sh b/pkgs/by-name/in/installShellFiles/setup-hook.sh index 4f4e215da4df..f51733e5f11f 100644 --- a/pkgs/by-name/in/installShellFiles/setup-hook.sh +++ b/pkgs/by-name/in/installShellFiles/setup-hook.sh @@ -233,3 +233,27 @@ installShellCompletion() { fi return $retval } + +# installBin [...] +# +# Install each argument to $outputBin +installBin() { + local path + for path in "$@"; do + if (( "${NIX_DEBUG:-0}" >= 1 )); then + echo "installBin: installing $path" + fi + if test -z "$path"; then + echo "installBin: error: path cannot be empty" >&2 + return 1 + fi + local basename + # use stripHash in case it's a nix store path + basename=$(stripHash "$path") + + local outRoot + outRoot=${!outputBin:?} + + install -D --mode=755 --no-target-directory "$path" "${outRoot}/bin/$basename" || return + done +} From 507416c3115ee4b2c26b49ad4c1f2b2f014ef7ae Mon Sep 17 00:00:00 2001 From: Anderson Torres Date: Wed, 14 Aug 2024 13:20:51 -0300 Subject: [PATCH 07/12] installShellFiles: add new tests install-bin and install-bin-output --- .../tests/install-bin-output.nix | 31 +++++++++++++++++++ .../installShellFiles/tests/install-bin.nix | 21 +++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 pkgs/by-name/in/installShellFiles/tests/install-bin-output.nix create mode 100644 pkgs/by-name/in/installShellFiles/tests/install-bin.nix diff --git a/pkgs/by-name/in/installShellFiles/tests/install-bin-output.nix b/pkgs/by-name/in/installShellFiles/tests/install-bin-output.nix new file mode 100644 index 000000000000..900f1eaa7e71 --- /dev/null +++ b/pkgs/by-name/in/installShellFiles/tests/install-bin-output.nix @@ -0,0 +1,31 @@ +{ + lib, + installShellFiles, + runCommandLocal, +}: + +runCommandLocal "install-shell-files--install-bin-output" + { + outputs = [ + "out" + "bin" + ]; + nativeBuildInputs = [ installShellFiles ]; + meta.platforms = lib.platforms.all; + } + '' + mkdir -p bin + echo "echo hello za warudo" > bin/hello + echo "echo amigo me gusta mucho" > bin/amigo + + installBin bin/* + + # assert it didn't go into $out + [[ ! -f $out/bin/amigo ]] + [[ ! -f $out/bin/hello ]] + + cmp bin/amigo ''${!outputBin}/bin/amigo + cmp bin/hello ''${!outputBin}/bin/hello + + touch $out + '' diff --git a/pkgs/by-name/in/installShellFiles/tests/install-bin.nix b/pkgs/by-name/in/installShellFiles/tests/install-bin.nix new file mode 100644 index 000000000000..ba00c59b21be --- /dev/null +++ b/pkgs/by-name/in/installShellFiles/tests/install-bin.nix @@ -0,0 +1,21 @@ +{ + lib, + installShellFiles, + runCommandLocal, +}: + +runCommandLocal "install-shell-files--install-bin" + { + nativeBuildInputs = [ installShellFiles ]; + meta.platforms = lib.platforms.all; + } + '' + mkdir -p bin + echo "echo hello za warudo" > bin/hello + echo "echo amigo me gusta mucho" > bin/amigo + + installBin bin/* + + cmp bin/amigo $out/bin/amigo + cmp bin/hello $out/bin/hello + '' From bb5aa086d69be1bfe5c3777210edb748d10e31d2 Mon Sep 17 00:00:00 2001 From: Anderson Torres Date: Fri, 23 Aug 2024 22:15:25 -0300 Subject: [PATCH 08/12] installShellFiles: rewrite functions - Use FUNCNAME to track the name of function being called - use long options for install commands - use nix*Log functions for logging, instead of custom echoes - remove silent error construction `|| return` --- .../in/installShellFiles/setup-hook.sh | 53 +++++++++---------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/pkgs/by-name/in/installShellFiles/setup-hook.sh b/pkgs/by-name/in/installShellFiles/setup-hook.sh index f51733e5f11f..b34893916541 100644 --- a/pkgs/by-name/in/installShellFiles/setup-hook.sh +++ b/pkgs/by-name/in/installShellFiles/setup-hook.sh @@ -24,19 +24,17 @@ installManPage() { local path for path in "$@"; do - if (( "${NIX_DEBUG:-0}" >= 1 )); then - echo "installManPage: installing $path" - fi if test -z "$path"; then - echo "installManPage: error: path cannot be empty" >&2 + nixErrorLog "${FUNCNAME[0]}: path cannot be empty" return 1 fi + nixInfoLog "${FUNCNAME[0]}: installing $path" local basename basename=$(stripHash "$path") # use stripHash in case it's a nix store path local trimmed=${basename%.gz} # don't get fooled by compressed manpages local suffix=${trimmed##*.} if test -z "$suffix" -o "$suffix" = "$trimmed"; then - echo "installManPage: error: path missing manpage section suffix: $path" >&2 + nixErrorLog "${FUNCNAME[0]}: path missing manpage section suffix: $path" return 1 fi local outRoot @@ -45,7 +43,8 @@ installManPage() { else outRoot=${!outputMan:?} fi - install -Dm644 -T "$path" "${outRoot}/share/man/man$suffix/$basename" || return + local outPath="${outRoot}/share/man/man$suffix/$basename" + install -D --mode=644 --no-target-directory "$path" "$outPath" done } @@ -107,7 +106,7 @@ installShellCompletion() { --name) name=$1 shift || { - echo 'installShellCompletion: error: --name flag expected an argument' >&2 + nixErrorLog "${FUNCNAME[0]}: --name flag expected an argument" return 1 } continue;; @@ -118,7 +117,7 @@ installShellCompletion() { --cmd) cmdname=$1 shift || { - echo 'installShellCompletion: error: --cmd flag expected an argument' >&2 + nixErrorLog "${FUNCNAME[0]}: --cmd flag expected an argument" return 1 } continue;; @@ -127,7 +126,7 @@ installShellCompletion() { cmdname=${arg#--cmd=} continue;; --?*) - echo "installShellCompletion: warning: unknown flag ${arg%%=*}" >&2 + nixWarnLog "${FUNCNAME[0]}: unknown flag ${arg%%=*}" retval=2 continue;; --) @@ -136,23 +135,21 @@ installShellCompletion() { continue;; esac fi - if (( "${NIX_DEBUG:-0}" >= 1 )); then - echo "installShellCompletion: installing $arg${name:+ as $name}" - fi + nixInfoLog "${FUNCNAME[0]}: installing $arg${name:+ as $name}" # if we get here, this is a path or named pipe # Identify shell and output name local curShell=$shell local outName='' if [[ -z "$arg" ]]; then - echo "installShellCompletion: error: empty path is not allowed" >&2 + nixErrorLog "${FUNCNAME[0]}: empty path is not allowed" return 1 elif [[ -p "$arg" ]]; then # this is a named fd or fifo if [[ -z "$curShell" ]]; then - echo "installShellCompletion: error: named pipe requires one of --bash, --fish, or --zsh" >&2 + nixErrorLog "${FUNCNAME[0]}: named pipe requires one of --bash, --fish, or --zsh" return 1 elif [[ -z "$name" && -z "$cmdname" ]]; then - echo "installShellCompletion: error: named pipe requires one of --cmd or --name" >&2 + nixErrorLog "${FUNCNAME[0]}: named pipe requires one of --cmd or --name" return 1 fi else @@ -168,10 +165,10 @@ installShellCompletion() { *) if [[ "$argbase" = _* && "$argbase" != *.* ]]; then # probably zsh - echo "installShellCompletion: warning: assuming path \`$arg' is zsh; please specify with --zsh" >&2 + nixWarnLog "${FUNCNAME[0]}: assuming path \`$arg' is zsh; please specify with --zsh" curShell=zsh else - echo "installShellCompletion: warning: unknown shell for path: $arg" >&2 + nixWarnLog "${FUNCNAME[0]}: unknown shell for path: $arg" >&2 retval=2 continue fi;; @@ -188,7 +185,7 @@ installShellCompletion() { zsh) outName=_$cmdname;; *) # Our list of shells is out of sync with the flags we accept or extensions we detect. - echo 'installShellCompletion: internal error' >&2 + nixErrorLog "${FUNCNAME[0]}: internal: shell $curShell not recognized" return 1;; esac fi @@ -206,7 +203,7 @@ installShellCompletion() { fi;; *) # Our list of shells is out of sync with the flags we accept or extensions we detect. - echo 'installShellCompletion: internal error' >&2 + nixErrorLog "${FUNCNAME[0]}: internal: shell $curShell not recognized" return 1;; esac # Install file @@ -217,18 +214,18 @@ installShellCompletion() { mkdir -p "$outDir" \ && cat "$arg" > "$outPath" else - install -Dm644 -T "$arg" "$outPath" - fi || return + install -D --mode=644 --no-target-directory "$arg" "$outPath" + fi if [ ! -s "$outPath" ]; then - echo "installShellCompletion: error: installed shell completion file \`$outPath' does not exist or has zero size" >&2 + nixErrorLog "${FUNCNAME[0]}: installed shell completion file \`$outPath' does not exist or has zero size" return 1 fi # Clear the per-path flags name= done if [[ -n "$name" ]]; then - echo 'installShellCompletion: error: --name flag given with no path' >&2 + nixErrorLog "${FUNCNAME[0]}: --name flag given with no path" >&2 return 1 fi return $retval @@ -240,13 +237,12 @@ installShellCompletion() { installBin() { local path for path in "$@"; do - if (( "${NIX_DEBUG:-0}" >= 1 )); then - echo "installBin: installing $path" - fi if test -z "$path"; then - echo "installBin: error: path cannot be empty" >&2 + nixErrorLog "${FUNCNAME[0]}: path cannot be empty" return 1 fi + nixInfoLog "${FUNCNAME[0]}: installing $path" + local basename # use stripHash in case it's a nix store path basename=$(stripHash "$path") @@ -254,6 +250,7 @@ installBin() { local outRoot outRoot=${!outputBin:?} - install -D --mode=755 --no-target-directory "$path" "${outRoot}/bin/$basename" || return + local outPath="${outRoot}/bin/$basename" + install -D --mode=755 --no-target-directory "$path" "${outRoot}/bin/$basename" done } From 56ff39832db97b06ab3abc658a4569a30c6449f6 Mon Sep 17 00:00:00 2001 From: Anderson Torres Date: Fri, 23 Aug 2024 23:11:50 -0300 Subject: [PATCH 09/12] installShellFiles: set passthru directly instead of overriding it --- pkgs/by-name/in/installShellFiles/package.nix | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pkgs/by-name/in/installShellFiles/package.nix b/pkgs/by-name/in/installShellFiles/package.nix index 87787ad872ee..f1cf436a9b79 100644 --- a/pkgs/by-name/in/installShellFiles/package.nix +++ b/pkgs/by-name/in/installShellFiles/package.nix @@ -5,14 +5,12 @@ }: # See the header comment in ./setup-hook.sh for example usage. -let - setupHook = makeSetupHook { name = "install-shell-files"; } ./setup-hook.sh; -in -setupHook.overrideAttrs (oldAttrs: { - passthru = (oldAttrs.passthru or { }) // { +makeSetupHook { + name = "install-shell-files"; + passthru = { tests = lib.packagesFromDirectoryRecursive { inherit callPackage; directory = ./tests; }; }; -}) +} ./setup-hook.sh From 1fc77a5ce2a6884e8cc69fc59986a08648f4eb83 Mon Sep 17 00:00:00 2001 From: Anderson Torres Date: Tue, 6 Aug 2024 22:12:58 -0300 Subject: [PATCH 10/12] doc: rewrite installShellFiles --- doc/hooks/installShellFiles.section.md | 83 ++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 6 deletions(-) diff --git a/doc/hooks/installShellFiles.section.md b/doc/hooks/installShellFiles.section.md index 9be67d57bfc6..edaea5895a3b 100644 --- a/doc/hooks/installShellFiles.section.md +++ b/doc/hooks/installShellFiles.section.md @@ -1,16 +1,79 @@ # `installShellFiles` {#installshellfiles} -This hook helps with installing manpages and shell completion files. It exposes 2 shell functions `installManPage` and `installShellCompletion` that can be used from your `postInstall` hook. +This hook adds helpers that install artifacts like executable files, manpages +and shell completions. -The `installManPage` function takes one or more paths to manpages to install. The manpages must have a section suffix, and may optionally be compressed (with `.gz` suffix). This function will place them into the correct `share/man/man
/` directory, in [`outputMan`](#outputman). +It exposes the following functions that can be used from your `postInstall` +hook: -The `installShellCompletion` function takes one or more paths to shell completion files. By default it will autodetect the shell type from the completion file extension, but you may also specify it by passing one of `--bash`, `--fish`, or `--zsh`. These flags apply to all paths listed after them (up until another shell flag is given). Each path may also have a custom installation name provided by providing a flag `--name NAME` before the path. If this flag is not provided, zsh completions will be renamed automatically such that `foobar.zsh` becomes `_foobar`. A root name may be provided for all paths using the flag `--cmd NAME`; this synthesizes the appropriate name depending on the shell (e.g. `--cmd foo` will synthesize the name `foo.bash` for bash and `_foo` for zsh). +## `installBin` {#installshellfiles-installbin} + +The `installBin` function takes one or more paths to files to install as +executable files. + +This function will place them into [`outputBin`](#outputbin). + +### Example Usage {#installshellfiles-installbin-exampleusage} + +```nix +{ + nativeBuildInputs = [ installShellFiles ]; + + # Sometimes the file has an undersirable name. It should be renamed before + # being installed via installBin + postInstall = '' + mv a.out delmar + installBin foobar delmar + ''; +} +``` + +## `installManPage` {#installshellfiles-installmanpage} + +The `installManPage` function takes one or more paths to manpages to install. + +The manpages must have a section suffix, and may optionally be compressed (with +`.gz` suffix). This function will place them into the correct +`share/man/man
/` directory in [`outputMan`](#outputman). + +### Example Usage {#installshellfiles-installmanpage-exampleusage} + +```nix +{ + nativeBuildInputs = [ installShellFiles ]; + + # Sometimes the manpage file has an undersirable name; e.g. it conflicts with + # another software with an equal name. It should be renamed before being + # installed via installManPage + postInstall = '' + mv fromsea.3 delmar.3 + installManPage foobar.1 delmar.3 + ''; +} +``` + +## `installShellCompletion` {#installshellfiles-installshellcompletion} + +The `installShellCompletion` function takes one or more paths to shell +completion files. + +By default it will autodetect the shell type from the completion file extension, +but you may also specify it by passing one of `--bash`, `--fish`, or +`--zsh`. These flags apply to all paths listed after them (up until another +shell flag is given). Each path may also have a custom installation name +provided by providing a flag `--name NAME` before the path. If this flag is not +provided, zsh completions will be renamed automatically such that `foobar.zsh` +becomes `_foobar`. A root name may be provided for all paths using the flag +`--cmd NAME`; this synthesizes the appropriate name depending on the shell +(e.g. `--cmd foo` will synthesize the name `foo.bash` for bash and `_foo` for +zsh). + +### Example Usage {#installshellfiles-installshellcompletion-exampleusage} ```nix { nativeBuildInputs = [ installShellFiles ]; postInstall = '' - installManPage doc/foobar.1 doc/barfoo.3 # explicit behavior installShellCompletion --bash --name foobar.bash share/completions.bash installShellCompletion --fish --name foobar.fish share/completions.fish @@ -21,9 +84,17 @@ The `installShellCompletion` function takes one or more paths to shell completio } ``` -The path may also be a fifo or named fd (such as produced by `<(cmd)`), in which case the shell and name must be provided (see below). +The path may also be a fifo or named fd (such as produced by `<(cmd)`), in which +case the shell and name must be provided (see below). -If the destination shell completion file is not actually present or consists of zero bytes after calling `installShellCompletion` this is treated as a build failure. In particular, if completion files are not vendored but are generated by running an executable, this is likely to fail in cross compilation scenarios. The result will be a zero byte completion file and hence a build failure. To prevent this, guard the completion commands against this, e.g. +If the destination shell completion file is not actually present or consists of +zero bytes after calling `installShellCompletion` this is treated as a build +failure. In particular, if completion files are not vendored but are generated +by running an executable, this is likely to fail in cross compilation +scenarios. The result will be a zero byte completion file and hence a build +failure. To prevent this, guard the completion generation commands. + +### Example Usage {#installshellfiles-installshellcompletion-exampleusage-guarded} ```nix { From 32897dce904cb05328940293f289d82d9b413bcb Mon Sep 17 00:00:00 2001 From: Anderson Torres Date: Mon, 5 Aug 2024 22:20:38 -0300 Subject: [PATCH 11/12] CODEOWNERS: update ownership for installShellFiles Since Ericson2314 is the original codeowner of the files. --- .github/CODEOWNERS | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index e138cd66152a..22728d6a0b1a 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -389,3 +389,8 @@ pkgs/by-name/lx/lxc* @adamcstephens /pkgs/os-specific/linux/checkpolicy @RossComputerGuy /pkgs/os-specific/linux/libselinux @RossComputerGuy /pkgs/os-specific/linux/libsepol @RossComputerGuy + +# installShellFiles +/pkgs/by-name/in/installShellFiles/* @Ericson2314 +/pkgs/test/install-shell-files/* @Ericson2314 +/doc/hooks/installShellFiles.section.md @Ericson2314 From 618cffa8e16a5c3182602841d848e7fcbc3c14ca Mon Sep 17 00:00:00 2001 From: Anderson Torres Date: Fri, 23 Aug 2024 23:05:28 -0300 Subject: [PATCH 12/12] nawk: uses installBin to install the binary --- pkgs/by-name/na/nawk/package.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/na/nawk/package.nix b/pkgs/by-name/na/nawk/package.nix index cb8766c8c6b0..d2132c25f277 100644 --- a/pkgs/by-name/na/nawk/package.nix +++ b/pkgs/by-name/na/nawk/package.nix @@ -34,7 +34,8 @@ stdenv.mkDerivation (finalAttrs: { installPhase = '' runHook preInstall - install -Dm755 a.out "$out/bin/nawk" + mv a.out nawk + installBin nawk mv awk.1 nawk.1 installManPage nawk.1 runHook postInstall