guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: guix-shell?


From: David Thompson
Subject: Re: guix-shell?
Date: Tue, 26 Aug 2014 08:14:38 -0400
User-agent: Notmuch/0.18.1 (http://notmuchmail.org) Emacs/24.3.1 (x86_64-pc-linux-gnu)

Ludovic Courtès <address@hidden> writes:

> "Thompson, David" <address@hidden> 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 != 1;
    my $drvPath = $drvPaths[0];
    $drvPath = (split '!',$drvPath)[0];
    $drvPath = readlink $drvPath or die "cannot read symlink ‘$drvPath’" if -l 
$drvPath;
    my $drv = derivationFromPath($drvPath);

    # Build or fetch all dependencies of the derivation.
    my @inputDrvs = grep { my $x = $_; (grep { $x =~ $_ } @envExclude) == 0 } 
@{$drv->{inputDrvs}};
    system("$Nix::Config::binDir/nix-store", "-r", "--no-output", 
"--no-gc-warning", @buildArgs, @inputDrvs, @{$drv->{inputSrcs}}) == 0
        or die "$0: failed to build all dependencies\n";

    # Set the environment.
    my $tmp = $ENV{"TMPDIR"} // $ENV{"XDG_RUNTIME_DIR"} // "/tmp";
    if ($pure) {
        foreach my $name (keys %ENV) {
            next if grep { $_ eq $name } ("HOME", "USER", "LOGNAME", "DISPLAY", 
"PATH", "TERM", "IN_NIX_SHELL", "TZ", "PAGER");
            delete $ENV{$name};
        }
        # NixOS hack: prevent /etc/bashrc from sourcing /etc/profile.
        $ENV{'__ETC_PROFILE_SOURCED'} = 1;
    }
    $ENV{'NIX_BUILD_TOP'} = $ENV{'TMPDIR'} = $ENV{'TEMPDIR'} = $ENV{'TMP'} = 
$ENV{'TEMP'} = $tmp;
    $ENV{'NIX_STORE'} = $Nix::Config::storeDir;
    $ENV{$_} = $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 = "$tmpDir/rc";
    writeFile(
        $rcfile,
        "rm -rf '$tmpDir'; " .
        'unset BASH_ENV; ' .
        '[ -n "$PS1" ] && [ -e ~/.bashrc ] && source ~/.bashrc; ' .
        ($pure ? '' : 'p=$PATH; ' ) .
        'dontAddDisableDepTrack=1; ' .
        '[ -e $stdenv/setup ] && source $stdenv/setup; ' .
        'if [ "$(type -t runHook)" = function ]; then runHook shellHook; fi; ' .
        ($pure ? '' : 'PATH=$PATH:$p; unset p; ') .
        'set +e; ' .
        '[ -n "$PS1" ] && PS1="\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='${ENV{'TZ'}}'; " : '') 
.
        $envCommand);
    $ENV{BASH_ENV} = $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!

-- 
David Thompson
Web Developer - Free Software Foundation - http://fsf.org
GPG Key: 0FF1D807
Support the FSF: https://fsf.org/donate



reply via email to

[Prev in Thread] Current Thread [Next in Thread]