From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Thompson Subject: Re: guix-shell? Date: Tue, 26 Aug 2014 08:14:38 -0400 Message-ID: <878umb30sx.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me> References: <87fvgo3mlx.fsf@gnu.org> <87zjesgqc5.fsf_-_@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60009) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMFeB-0002hL-2F for guix-devel@gnu.org; Tue, 26 Aug 2014 08:14:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XMFe5-0007KU-94 for guix-devel@gnu.org; Tue, 26 Aug 2014 08:14:47 -0400 Received: from na6sys009bog019.obsmtp.com ([74.125.150.78]:35150) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMFe5-0007KG-4P for guix-devel@gnu.org; Tue, 26 Aug 2014 08:14:41 -0400 Received: by mail-qg0-f48.google.com with SMTP id i50so14206352qgf.7 for ; Tue, 26 Aug 2014 05:14:40 -0700 (PDT) In-Reply-To: <87zjesgqc5.fsf_-_@gnu.org> 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-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: Ludovic =?utf-8?Q?Court=C3=A8s?= Cc: guix-devel Ludovic Court=C3=A8s writes: > "Thompson, David" skribis: > >> I hope we can make use of Nix's {pip,bower,node,...}2nix scripts and >> make Guix versions. But first, we need to write guix-shell! > > I think nix-shell is mostly equivalent to: > > eval `guix package --search-paths` > > Although maybe it would be better to have a command that does it without > actually having to create a profile. > > Thoughts? Okay, so after digging into nix's source code a bit, I've learned a few things. nix-shell is really just a symlink to nix-build, and it doesn't seem to use profiles at all! When nix-build is called as 'nix-shell', it's behavior changes. From the manual: "The command nix-shell will build the dependencies of the specified derivation, but not the derivation itself." I can see that the nix-build script exits before adding the derivation to the store when called as 'nix-shell'. Here's the relevant Perl source code: die "$0: a single derivation is required\n" if scalar @drvPaths !=3D 1; my $drvPath =3D $drvPaths[0]; $drvPath =3D (split '!',$drvPath)[0]; $drvPath =3D readlink $drvPath or die "cannot read symlink =E2=80=98$dr= vPath=E2=80=99" if -l $drvPath; my $drv =3D derivationFromPath($drvPath); # Build or fetch all dependencies of the derivation. my @inputDrvs =3D grep { my $x =3D $_; (grep { $x =3D~ $_ } @envExclude= ) =3D=3D 0 } @{$drv->{inputDrvs}}; system("$Nix::Config::binDir/nix-store", "-r", "--no-output", "--no-gc-= warning", @buildArgs, @inputDrvs, @{$drv->{inputSrcs}}) =3D=3D 0 or die "$0: failed to build all dependencies\n"; # Set the environment. my $tmp =3D $ENV{"TMPDIR"} // $ENV{"XDG_RUNTIME_DIR"} // "/tmp"; if ($pure) { foreach my $name (keys %ENV) { next if grep { $_ eq $name } ("HOME", "USER", "LOGNAME", "DISPL= AY", "PATH", "TERM", "IN_NIX_SHELL", "TZ", "PAGER"); delete $ENV{$name}; } # NixOS hack: prevent /etc/bashrc from sourcing /etc/profile. $ENV{'__ETC_PROFILE_SOURCED'} =3D 1; } $ENV{'NIX_BUILD_TOP'} =3D $ENV{'TMPDIR'} =3D $ENV{'TEMPDIR'} =3D $ENV{'= TMP'} =3D $ENV{'TEMP'} =3D $tmp; $ENV{'NIX_STORE'} =3D $Nix::Config::storeDir; $ENV{$_} =3D $drv->{env}->{$_} foreach keys %{$drv->{env}}; # Run a shell using the derivation's environment. For # convenience, source $stdenv/setup to setup additional # environment variables and shell functions. Also don't lose # the current $PATH directories. my $rcfile =3D "$tmpDir/rc"; writeFile( $rcfile, "rm -rf '$tmpDir'; " . 'unset BASH_ENV; ' . '[ -n "$PS1" ] && [ -e ~/.bashrc ] && source ~/.bashrc; ' . ($pure ? '' : 'p=3D$PATH; ' ) . 'dontAddDisableDepTrack=3D1; ' . '[ -e $stdenv/setup ] && source $stdenv/setup; ' . 'if [ "$(type -t runHook)" =3D function ]; then runHook shellHook; = fi; ' . ($pure ? '' : 'PATH=3D$PATH:$p; unset p; ') . 'set +e; ' . '[ -n "$PS1" ] && PS1=3D"\n\[\033[1;32m\][nix-shell:\w]$\[\033[0m\]= "; ' . 'unset NIX_ENFORCE_PURITY; ' . 'unset NIX_INDENT_MAKE; ' . 'shopt -u nullglob; ' . 'unset TZ; ' . (defined $ENV{'TZ'} ? "export TZ=3D'${ENV{'TZ'}}'; "= : '') . $envCommand); $ENV{BASH_ENV} =3D $rcfile; exec($ENV{NIX_BUILD_SHELL} // "bash", "--rcfile", $rcfile); die; (Thank you for choosing Scheme, btw) I found it confusing to have the build script also handle the shell via some conditional logic. I think Guix could do it better. I will implement 'guix shell' if I can get your opinion on the best approach to take. Would you tweak guix/scripts/build.scm to handle the special case or export the necessary procedures and create a guix/scripts/shell.scm module? Thanks! --=20 David Thompson Web Developer - Free Software Foundation - http://fsf.org GPG Key: 0FF1D807 Support the FSF: https://fsf.org/donate