NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.07k stars 14.13k forks source link

treewide: unify `export HOME=<writable_dir>` #181428

Open smancill opened 2 years ago

smancill commented 2 years ago

Describe the bug

Multiple derivations need to set HOME to a temporary directory for write access, but there is no agreement on a standard way to do it, so a quick search shows:

Expected behavior

It should be one standard way to do it.

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-darwin"`
 - host os: `Darwin 20.6.0, macOS 10.16`
 - multi-user?: `no`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.8.1`
 - channels(smancill): `"darwin, nixpkgs-22.05pre381443.299dbf37b0d, unstable-22.11pre389849.c9ad20e7ebb, home-manager-21.05"`
 - channels(root): `"darwin, nixpkgs-21.05pre295749.02ee434b10e, unstable-21.11pre333180.98747f27ecf"`
 - nixpkgs: `/Users/smancill/.nix-defexpr/channels/nixpkgs`
symphorien commented 2 years ago

or maybe stdenv/setup.sh could do it systematically

symphorien commented 2 years ago

or maybe stdenv/setup.sh could do it systematically

dev:nixos.org does not think it's a good idea. build systems should not use $HOME

trofi commented 2 years ago

Random factoid: Gentoo uses HOME=$TMP for builders.

Sometimes tools are very keen on creating something at $HOME and either fail or have a graceful fallback. I don't think there would be one-size-fits-all path. I'd say it's fine to leave the way to handle it to individual packages.

mkg20001 commented 2 years ago

A function setupHome as part of stdenv that packages can just call could do the trick?

Artturin commented 2 years ago

A function setupHome as part of stdenv that packages can just call could do the trick?

We should avoid expanding stdenv and instead use hooks

SuperSandro2000 commented 2 years ago

export HOME=/Users/$(whoami)

This should be removed immediately because it only works on darwin and pollutes your home directory if the sandbox is not enabled.

smancill commented 2 years ago

export HOME=/Users/$(whoami)

This should be removed immediately because it only works on darwin and pollutes your home directory if the sandbox is not enabled.

It is from https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/mobile/xcodeenv/build-app.nix, I don't feel like touching that derivation blindly.

Looks like @svanderburg is the code owner.

SuperSandro2000 commented 2 years ago

Thats scary. Not touching that either...