build-support: add writableTmpDirAsHomeHook hook

This commit is contained in:
Pol Dellaiera 2024-12-18 18:02:37 +01:00
parent 87521c59b6
commit f8110737ae
4 changed files with 36 additions and 0 deletions

View File

@ -830,6 +830,9 @@
"add-bin-to-path.sh": [
"index.html#add-bin-to-path.sh"
],
"writable-tmpdir-as-home.sh": [
"index.html#writable-tmpdir-as-home.sh"
],
"bintools-wrapper": [
"index.html#bintools-wrapper"
],

View File

@ -1389,6 +1389,17 @@ work as intended in cases with multiple outputs or when binaries are located in
directories like `sbin/`. These caveats should be considered when using this
hook, as they might introduce unexpected behavior in some specific cases.
### `writable-tmpdir-as-home.sh` {#writable-tmpdir-as-home.sh}
This setup hook ensures that the directory specified by the `HOME` environment
variable is writable. If it is not, the hook assigns `HOME` to a writable
directory (in `.home` in `$NIX_BUILD_TOP`). This adjustment is necessary for
certain packages that require write access to a home directory. This hook can
be added to any phase.
By setting `HOME` to a writable directory, this setup hook prevents failures in
packages that attempt to write to the home directory.
### Bintools Wrapper and hook {#bintools-wrapper}
The Bintools Wrapper wraps the binary utilities for a bunch of miscellaneous purposes. These are GNU Binutils when targeting Linux, and a mix of cctools and GNU binutils for Darwin. \[The “Bintools” name is supposed to be a compromise between “Binutils” and “cctools” not denoting any specific implementation.\] Specifically, the underlying bintools package, and a C standard library (glibc or Darwins libSystem, just for the dynamic loader) are all fed in, and dependency finding, hardening (see below), and purity checks for each are handled by the Bintools Wrapper. Packages typically depend on CC Wrapper, which in turn (at run time) depends on the Bintools Wrapper.

View File

@ -0,0 +1,15 @@
# shellcheck shell=bash
# This setup hook set the HOME environment variable to a writable directory.
export HOME
writableTmpDirAsHome () {
if [ ! -w "$HOME" ]; then
HOME="$NIX_BUILD_TOP/.home"
mkdir -p "$HOME"
export HOME
fi
}
# shellcheck disable=SC2154
addEnvHooks "$targetOffset" writableTmpDirAsHome

View File

@ -868,6 +868,13 @@ with pkgs;
name = "setup-debug-info-dirs-hook";
} ../build-support/setup-hooks/setup-debug-info-dirs.sh;
writableTmpDirAsHomeHook = callPackage (
{ makeSetupHook }:
makeSetupHook {
name = "writable-tmpdir-as-home-hook";
} ../build-support/setup-hooks/writable-tmpdir-as-home.sh
) { };
useOldCXXAbi = makeSetupHook {
name = "use-old-cxx-abi-hook";
} ../build-support/setup-hooks/use-old-cxx-abi.sh;