nix build: add --print-out-paths flag
has the same functionality as default nix-build $ nix-build . -A "bash" -A "bash.dev" -A "tinycc" /nix/store/4nmqxajzaf60yjribkgvj5j54x9yvr1r-bash-5.1-p12 /nix/store/c49i1ggnr5cc8gxmk9xm0cn961z104dn-bash-5.1-p12-dev /nix/store/dbapb08862ajgaax3621fz8hly9fdah3-tcc-0.9.27+date=2022-01-11 $ nix-build . -A "bash" /nix/store/4nmqxajzaf60yjribkgvj5j54x9yvr1r-bash-5.1-p12 $ $HOME/nixgits/nix/result/bin/nix build "nixpkgs#bash" "nixpkgs#bash.dev" "nixpkgs#tinycc" --print-out-paths /nix/store/4nmqxajzaf60yjribkgvj5j54x9yvr1r-bash-5.1-p12 /nix/store/c49i1ggnr5cc8gxmk9xm0cn961z104dn-bash-5.1-p12-dev /nix/store/dbapb08862ajgaax3621fz8hly9fdah3-tcc-0.9.27+date=2022-01-11 $ $HOME/nixgits/nix/result/bin/nix build "nixpkgs#bash" --print-out-paths /nix/store/4nmqxajzaf60yjribkgvj5j54x9yvr1r-bash-5.1-p12
This commit is contained in:
parent
2ffc5a4542
commit
51cfea8bb0
4 changed files with 42 additions and 0 deletions
|
@ -2,3 +2,6 @@
|
|||
|
||||
* `nix repl` has a new build-'n-link (`:bl`) command that builds a derivation
|
||||
while creating GC root symlinks.
|
||||
|
||||
* `nix build` has a new `--print-out-paths` flag to print the resulting output paths.
|
||||
This matches the default behaviour of `nix-build`.
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "shared.hh"
|
||||
#include "store-api.hh"
|
||||
#include "local-fs-store.hh"
|
||||
#include "progress-bar.hh"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
|
@ -12,6 +13,7 @@ using namespace nix;
|
|||
struct CmdBuild : InstallablesCommand, MixDryRun, MixJSON, MixProfile
|
||||
{
|
||||
Path outLink = "result";
|
||||
bool printOutputPaths = false;
|
||||
BuildMode buildMode = bmNormal;
|
||||
|
||||
CmdBuild()
|
||||
|
@ -31,6 +33,12 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixJSON, MixProfile
|
|||
.handler = {&outLink, Path("")},
|
||||
});
|
||||
|
||||
addFlag({
|
||||
.longName = "print-out-paths",
|
||||
.description = "Print the resulting output paths",
|
||||
.handler = {&printOutputPaths, true},
|
||||
});
|
||||
|
||||
addFlag({
|
||||
.longName = "rebuild",
|
||||
.description = "Rebuild an already built package and compare the result to the existing store paths.",
|
||||
|
@ -93,6 +101,22 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixJSON, MixProfile
|
|||
}, buildable.raw());
|
||||
}
|
||||
|
||||
if (printOutputPaths) {
|
||||
stopProgressBar();
|
||||
for (auto & buildable : buildables) {
|
||||
std::visit(overloaded {
|
||||
[&](const BuiltPath::Opaque & bo) {
|
||||
std::cout << store->printStorePath(bo.path) << std::endl;
|
||||
},
|
||||
[&](const BuiltPath::Built & bfd) {
|
||||
for (auto & output : bfd.outputs) {
|
||||
std::cout << store->printStorePath(output.second) << std::endl;
|
||||
}
|
||||
},
|
||||
}, buildable.raw());
|
||||
}
|
||||
}
|
||||
|
||||
updateProfile(buildables);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -25,6 +25,13 @@ R""(
|
|||
lrwxrwxrwx 1 … result-1 -> /nix/store/rkfrm0z6x6jmi7d3gsmma4j53h15mg33-cowsay-3.03+dfsg2
|
||||
```
|
||||
|
||||
* Build GNU Hello and print the resulting store path.
|
||||
|
||||
```console
|
||||
# nix build nixpkgs#hello --print-out-paths
|
||||
/nix/store/v5sv61sszx301i0x6xysaqzla09nksnd-hello-2.10
|
||||
```
|
||||
|
||||
* Build a specific output:
|
||||
|
||||
```console
|
||||
|
|
|
@ -34,6 +34,14 @@ outPath=$(readlink -f $TEST_ROOT/result)
|
|||
|
||||
grep 'FOO BAR BAZ' $TEST_ROOT/machine0/$outPath
|
||||
|
||||
testPrintOutPath=$(nix build -L -v -f $file --print-out-paths --max-jobs 0 \
|
||||
--arg busybox $busybox \
|
||||
--store $TEST_ROOT/machine0 \
|
||||
--builders "$(join_by '; ' "${builders[@]}")"
|
||||
)
|
||||
|
||||
[[ $testPrintOutPath =~ store.*build-remote ]]
|
||||
|
||||
set -o pipefail
|
||||
|
||||
# Ensure that input1 was built on store1 due to the required feature.
|
||||
|
|
Loading…
Reference in a new issue