mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-30 01:26:15 +02:00
nix-channel: Use binary caches advertised by channels
Channels can now advertise a binary cache by creating a file <channel-url>/binary-cache-url. The channel unpacker puts these in its "binary-caches" subdirectory. Thus, the URLS of the binary caches for the channels added by root appear in /nix/var/nix/profiles/per-user/eelco/channels/binary-caches/*. The binary cache substituter reads these and adds them to the list of binary caches.
This commit is contained in:
parent
79bba3782c
commit
5170c5691a
4 changed files with 49 additions and 20 deletions
|
@ -8,17 +8,21 @@ let
|
||||||
cd $out
|
cd $out
|
||||||
${bzip2} -d < $src | ${tar} xf - --warning=no-timestamp
|
${bzip2} -d < $src | ${tar} xf - --warning=no-timestamp
|
||||||
mv * $out/$channelName
|
mv * $out/$channelName
|
||||||
|
if [ -n "$binaryCacheURL" ]; then
|
||||||
|
mkdir $out/binary-caches
|
||||||
|
echo -n "$binaryCacheURL" > $out/binary-caches/$channelName
|
||||||
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
{ name, channelName, src }:
|
{ name, channelName, src, binaryCacheURL ? "" }:
|
||||||
|
|
||||||
derivation {
|
derivation {
|
||||||
system = builtins.currentSystem;
|
system = builtins.currentSystem;
|
||||||
builder = shell;
|
builder = shell;
|
||||||
args = [ "-e" builder ];
|
args = [ "-e" builder ];
|
||||||
inherit name channelName src;
|
inherit name channelName src binaryCacheURL;
|
||||||
|
|
||||||
PATH = "${nixBinDir}:${coreutils}";
|
PATH = "${nixBinDir}:${coreutils}";
|
||||||
|
|
||||||
|
|
|
@ -329,6 +329,18 @@ build-use-chroot = /dev /proc /bin</programlisting>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><literal>binary-caches-files</literal></term>
|
||||||
|
|
||||||
|
<listitem><para>A list of names of files that will be read to
|
||||||
|
obtain additional binary cache URLs. The default is
|
||||||
|
<literal>/nix/var/nix/profiles/per-user/root/channels/binary-caches/*</literal>,
|
||||||
|
which ensures that Nix will use the binary caches corresponding to
|
||||||
|
the channels installed by root. Do not set this option to read
|
||||||
|
files created by untrusted users!</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
<varlistentry><term><literal>trusted-binary-caches</literal></term>
|
<varlistentry><term><literal>trusted-binary-caches</literal></term>
|
||||||
|
|
||||||
<listitem><para>A list of URLs of binary caches, separated by
|
<listitem><para>A list of URLs of binary caches, separated by
|
||||||
|
|
|
@ -176,6 +176,16 @@ sub getAvailableCaches {
|
||||||
($Nix::Config::config{"binary-caches"}
|
($Nix::Config::config{"binary-caches"}
|
||||||
// ($Nix::Config::storeDir eq "/nix/store" ? "http://nixos.org/binary-cache" : ""));
|
// ($Nix::Config::storeDir eq "/nix/store" ? "http://nixos.org/binary-cache" : ""));
|
||||||
|
|
||||||
|
my $urlsFiles = $Nix::Config::config{"binary-cache-files"}
|
||||||
|
// "/nix/var/nix/profiles/per-user/root/channels/binary-caches/*";
|
||||||
|
foreach my $urlFile (glob $urlsFiles) {
|
||||||
|
next unless -f $urlFile;
|
||||||
|
open FILE, "<$urlFile" or die "cannot open ‘$urlFile’\n";
|
||||||
|
my $url = <FILE>; chomp $url;
|
||||||
|
close FILE;
|
||||||
|
push @urls, strToList($url);
|
||||||
|
}
|
||||||
|
|
||||||
# Allow Nix daemon users to override the binary caches to a subset
|
# Allow Nix daemon users to override the binary caches to a subset
|
||||||
# of those listed in the config file. Note that ‘untrusted-*’
|
# of those listed in the config file. Note that ‘untrusted-*’
|
||||||
# denotes options passed by the client.
|
# denotes options passed by the client.
|
||||||
|
|
|
@ -80,12 +80,6 @@ sub update {
|
||||||
|
|
||||||
readChannels;
|
readChannels;
|
||||||
|
|
||||||
# Create the manifests directory if it doesn't exist.
|
|
||||||
mkdir $manifestDir, 0755 unless -e $manifestDir;
|
|
||||||
|
|
||||||
# Do we have write permission to the manifests directory?
|
|
||||||
die "$0: you do not have write permission to `$manifestDir'!\n" unless -W $manifestDir;
|
|
||||||
|
|
||||||
# Download each channel.
|
# Download each channel.
|
||||||
my $exprs = "";
|
my $exprs = "";
|
||||||
foreach my $name (keys %channels) {
|
foreach my $name (keys %channels) {
|
||||||
|
@ -102,10 +96,19 @@ sub update {
|
||||||
$headers =~ s/\r//g;
|
$headers =~ s/\r//g;
|
||||||
$url = $1 if $headers =~ /^Location:\s*(.*)\s*$/m;
|
$url = $1 if $headers =~ /^Location:\s*(.*)\s*$/m;
|
||||||
|
|
||||||
# Pull the channel manifest.
|
# Check if the channel advertises a binary cache.
|
||||||
$ENV{'NIX_ORIG_URL'} = $origUrl;
|
my $binaryCacheURL = `$Nix::Config::curl --silent '$url'/binary-cache-url`;
|
||||||
system("$Nix::Config::binDir/nix-pull", "--skip-wrong-store", "$url/MANIFEST") == 0
|
my $extraAttrs = "";
|
||||||
or die "cannot pull manifest from `$url'\n";
|
if ($? == 0 && $binaryCacheURL ne "") {
|
||||||
|
$extraAttrs .= "binaryCacheURL = \"$binaryCacheURL\"; ";
|
||||||
|
} else {
|
||||||
|
# No binary cache, so pull the channel manifest.
|
||||||
|
mkdir $manifestDir, 0755 unless -e $manifestDir;
|
||||||
|
die "$0: you do not have write permission to `$manifestDir'!\n" unless -W $manifestDir;
|
||||||
|
$ENV{'NIX_ORIG_URL'} = $origUrl;
|
||||||
|
system("$Nix::Config::binDir/nix-pull", "--skip-wrong-store", "$url/MANIFEST") == 0
|
||||||
|
or die "cannot pull manifest from `$url'\n";
|
||||||
|
}
|
||||||
|
|
||||||
# Download the channel tarball.
|
# Download the channel tarball.
|
||||||
my $fullURL = "$url/nixexprs.tar.bz2";
|
my $fullURL = "$url/nixexprs.tar.bz2";
|
||||||
|
@ -120,7 +123,7 @@ sub update {
|
||||||
my $cname = $name;
|
my $cname = $name;
|
||||||
$cname .= $1 if basename($url) =~ /(-\d.*)$/;
|
$cname .= $1 if basename($url) =~ /(-\d.*)$/;
|
||||||
|
|
||||||
$exprs .= "'f: f { name = \"$cname\"; channelName = \"$name\"; src = builtins.storePath \"$path\"; }' ";
|
$exprs .= "'f: f { name = \"$cname\"; channelName = \"$name\"; src = builtins.storePath \"$path\"; $extraAttrs }' ";
|
||||||
}
|
}
|
||||||
|
|
||||||
# Unpack the channel tarballs into the Nix store and install them
|
# Unpack the channel tarballs into the Nix store and install them
|
||||||
|
|
Loading…
Reference in a new issue