From mboxrd@z Thu Jan 1 00:00:00 1970 From: clement@lassieur.org (=?utf-8?Q?Cl=C3=A9ment?= Lassieur) Subject: Re: Why is the default $HOME /homeless-shelter? Date: Mon, 18 Nov 2019 13:15:24 +0100 Message-ID: <87imnhl6sj.fsf@lassieur.org> References: <87h832i3n3.fsf@gnu.org> <7321d3a52b24c3b44dd5c1241afffc0992192a88.camel@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:56719) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iWfwI-0006d7-8Z for guix-devel@gnu.org; Mon, 18 Nov 2019 07:15:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iWfwG-0006UJ-VW for guix-devel@gnu.org; Mon, 18 Nov 2019 07:15:30 -0500 In-Reply-To: <7321d3a52b24c3b44dd5c1241afffc0992192a88.camel@gmail.com> (Jesse Gibbons's message of "Sun, 17 Nov 2019 15:58:47 -0700") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Jesse Gibbons Cc: guix-devel@gnu.org Hi Jesse, Jesse Gibbons writes: > On Sun, 2019-11-17 at 22:39 +0100, Ludovic Court=C3=A8s wrote: >> Hi! >>=20 >> Because it=E2=80=99s always been this way! :-) >>=20 >> This is inherited from Nix. The rationale is that there=E2=80=99s no ho= me >> directory in build environments, and perhaps Eelco Dolstra and others >> back then found that setting =E2=80=98HOME=E2=80=99 to a non-existing di= rectory broke >> fewer builds that leaving it unset. >>=20 >> HTH, >> Ludo=E2=80=99. > Is this documented or speculation? What packages could break if $HOME is = set > to somewhere in /tmp? > > Considering these packages are usually written without knowing GuixSD > exists, if a package install script depends on HOME I would think it would > try to use $HOME as a directory expecting it to exist. Since it is > /homeless-shelter by default, and /homeless-shelter does not exist on a > default GuixSD install, we observe that most of the packages that depend = on > HOME need to be modified to set HOME, and the location of the new HOME is > often inconsistently decided. > > If it is documented, I will admit defeat. > > If the reason Nix doesn't set HOME isn't documented, I think I will try > setting HOME to a subdirectory of /tmp taking the target's hash and name > into account. If that doesn't break anything, I think I will send a patch > for core-updates. I would expect the patch to trigger a mass rebuild of > every package. Hopefully that can be tested rigorously before core-updates > is merged into master, and we will no longer need to change HOME when an > install script depends on it. > > If anyone objects, please respond sooner rather than later. It is documented there: https://nixos.org/nix/manual/#ssec-derivation --8<---------------cut here---------------start------------->8--- HOME is set to /homeless-shelter to prevent programs from using /etc/passwd or the like to find the user's home directory, which could cause impurity. Usually, when HOME is set, it is used as the location of the home directory, even if it points to a non-existent path. --8<---------------cut here---------------end--------------->8--- and there: https://nixos.org/nixos/nix-pills/working-derivation.html#idm140737316220720 --8<---------------cut here---------------start------------->8--- $HOME is not your home directory, and /homeless-shelter doesn't exist at all. We force packages not to depend on $HOME during the build process. --8<---------------cut here---------------end--------------->8--- and there: https://github.com/NixOS/nix/blob/258897c265a6d6575f1669a896ab6f5ab92337c3/= src/libstore/build.cc#L1694 --8<---------------cut here---------------start------------->8--- Set HOME to a non-existing path to prevent certain programs from using /etc/passwd (or NIS, or whatever) to locate the home directory (for example, wget looks for ~/.wgetrc). I.e., these tools use /etc/passwd if HOME is not set, but they will just assume that the settings file they are looking for does not exist if HOME is set but points to some non-existing path. --8<---------------cut here---------------end--------------->8--- There's even a commit to complain if that directory exists: https://github.com/NixOS/nix/commit/258897c265a6d6575f1669a896ab6f5ab92337c= 3#diff-267a6391980cbd9a743958945ff44ef9 --8<---------------cut here---------------start------------->8--- if (pathExists(homeDir)) throw Error(format("directory `%1%' exists; please remove it") % homeDi= r); --8<---------------cut here---------------end--------------->8--- Cl=C3=A9ment