-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move
NIX_BIN_DIR
and all logic using it to the Nix executable itself
This is because with the split packages of the Meson build, we simply have no idea what directory the binaries will be installed in when we build the library. In the process of doing so, consolidate and make more sophisticated the logic to cope with a few corner cases (e.g. `NIX_BIN_DIR` exists, but no binaries are inside it).
- Loading branch information
1 parent
1216778
commit d6af41a
Showing
21 changed files
with
222 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
synopsis: The "build-hook" setting" default is less useful when using `libnixstore` as a library | ||
prs: | ||
- 11178 | ||
--- | ||
|
||
*This is an obscure issue just affecting uses of `libnixstore` the library outside of the Nix executable.* | ||
|
||
As part the ongoing [rewrite of the build system](https://github.com/NixOS/nix/issues/2503) to use [Meson](https://mesonbuild.com/), we are also switching to packaging individual Nix components separately (and building them in separate derivations). | ||
This means that when building `libnixstore` we do not know where the Nix binaries will be installed --- `libnixstore` doesn't know about downstream consumers like the Nix binaries at all. | ||
This has a small adverse affect on remote building --- the `build-remote` executable that is specified from the `build-hook` setting will not be gotten from the (presumed) installation location, but instead looked up on the `PATH`. | ||
This means that other applications linking `libnixstore` that wish to use remote building must arrange for the `nix` command to be on the PATH (or manually overriding the setting) in order for that to work. | ||
|
||
Long term we don't envision this being a downside, because we plan to [get rid of `build-remote` and the build hook setting entirely](https://github.com/NixOS/nix/issues/1221). | ||
There is simply no need to add a second layer of remote-procedure-calling when we want to connect to a remote builder. | ||
When the build hook protocol did in principle support custom ways of remote building, that can also be accomplished with a customer service for the ssh or daemon/ssh-ng protocols, or with a custom store class. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "current-process.hh" | ||
#include "file-system.hh" | ||
#include "globals.hh" | ||
#include "bin-dir.hh" | ||
|
||
namespace nix { | ||
|
||
namespace fs = std::filesystem; | ||
|
||
fs::path getNixBin(std::optional<std::string_view> binaryNameOpt) | ||
{ | ||
auto getBinaryName = [&] { return binaryNameOpt ? *binaryNameOpt : "nix"; }; | ||
|
||
// If the environment variable is set, use it unconditionally | ||
if (auto envOpt = getEnvNonEmpty("NIX_BIN_DIR")) | ||
return fs::path{*envOpt} / std::string{getBinaryName()}; | ||
|
||
// Use some-times avaiable OS tricks to get to the path of this Nix, and try that | ||
if (auto selfOpt = getSelfExe()) { | ||
fs::path path{*selfOpt}; | ||
if (binaryNameOpt) | ||
path = path.parent_path() / std::string{*binaryNameOpt}; | ||
if (fs::exists(path)) | ||
return path; | ||
} | ||
|
||
// If `nix` exists at the hardcoded fallback path, use it. | ||
{ | ||
auto path = fs::path{NIX_BIN_DIR} / std::string{getBinaryName()}; | ||
if (fs::exists(path)) | ||
return path; | ||
} | ||
|
||
// return just the name, hoping the exe is on the `PATH` | ||
return getBinaryName(); | ||
} | ||
|
||
} |
Oops, something went wrong.