* rpm-closure.pl: add possibility to use multiple repositories

* default.nix: do not assume fixed filesystem type when mounting, to allow using other filesystems


svn path=/nixpkgs/trunk/; revision=29757
This commit is contained in:
Rob Vermaas 2011-10-11 13:22:09 +00:00
parent a1f9b6f7b6
commit 40f1e4e289
2 changed files with 63 additions and 41 deletions

View File

@ -127,7 +127,7 @@ rec {
if test -z "$mountDisk"; then if test -z "$mountDisk"; then
mount -t tmpfs none /fs mount -t tmpfs none /fs
else else
mount -t ext2 /dev/${hd} /fs mount /dev/${hd} /fs
fi fi
mkdir -p /fs/dev mkdir -p /fs/dev
@ -166,7 +166,6 @@ rec {
halt -d -p -f halt -d -p -f
''; '';
initrd = makeInitrd { initrd = makeInitrd {
contents = [ contents = [
{ object = stage1Init; { object = stage1Init;
@ -303,7 +302,7 @@ rec {
''; '';
createRootFS = '' defaultCreateRootFS = ''
mkdir /mnt mkdir /mnt
${e2fsprogs}/sbin/mke2fs -F /dev/${hd} ${e2fsprogs}/sbin/mke2fs -F /dev/${hd}
${utillinux}/bin/mount -t ext2 /dev/${hd} /mnt ${utillinux}/bin/mount -t ext2 /dev/${hd} /mnt
@ -486,12 +485,12 @@ rec {
fillDiskWithRPMs = fillDiskWithRPMs =
{ size ? 4096, rpms, name, fullName, preInstall ? "", postInstall ? "" { size ? 4096, rpms, name, fullName, preInstall ? "", postInstall ? ""
, runScripts ? true , runScripts ? true, createRootFS ? defaultCreateRootFS
}: }:
runInLinuxVM (stdenv.mkDerivation { runInLinuxVM (stdenv.mkDerivation {
inherit name preInstall postInstall rpms; inherit name preInstall postInstall rpms;
memSize = 512;
preVM = createEmptyImage {inherit size fullName;}; preVM = createEmptyImage {inherit size fullName;};
buildCommand = '' buildCommand = ''
@ -526,10 +525,10 @@ rec {
eval "$postInstall" eval "$postInstall"
rm /mnt/.debug rm /mnt/.debug
${utillinux}/bin/umount /mnt/nix/store ${utillinux}/bin/umount /mnt/nix/store
${utillinux}/bin/umount /mnt/tmp ${utillinux}/bin/umount /mnt/tmp
${utillinux}/bin/umount /mnt ${utillinux}/bin/umount /mnt
''; '';
passthru = { inherit fullName; }; passthru = { inherit fullName; };
@ -631,7 +630,7 @@ rec {
strongly connected components. See deb/deb-closure.nix. */ strongly connected components. See deb/deb-closure.nix. */
fillDiskWithDebs = fillDiskWithDebs =
{ size ? 4096, debs, name, fullName, postInstall ? null }: { size ? 4096, debs, name, fullName, postInstall ? null, createRootFS ? defaultCreateRootFS }:
runInLinuxVM (stdenv.mkDerivation { runInLinuxVM (stdenv.mkDerivation {
inherit name postInstall; inherit name postInstall;
@ -712,12 +711,15 @@ rec {
`primary.xml.gz' file of a Fedora or openSUSE distribution. */ `primary.xml.gz' file of a Fedora or openSUSE distribution. */
rpmClosureGenerator = rpmClosureGenerator =
{name, packagesList, urlPrefix, packages, archs ? []}: {name, packagesLists, urlPrefixes, packages, archs ? []}:
assert (builtins.length packagesLists) == (builtins.length urlPrefixes) ;
runCommand "${name}.nix" {buildInputs = [perl perlPackages.XMLSimple]; inherit archs;} '' runCommand "${name}.nix" {buildInputs = [perl perlPackages.XMLSimple]; inherit archs;} ''
gunzip < ${packagesList} > ./packages.xml ${lib.concatImapStrings (i: pl: ''
gunzip < ${pl} > ./packages_${toString i}.xml
'') packagesLists}
perl -w ${rpm/rpm-closure.pl} \ perl -w ${rpm/rpm-closure.pl} \
./packages.xml ${urlPrefix} ${toString packages} > $out ${lib.concatImapStrings (i: pl: "./packages_${toString i}.xml ${pl.snd} " ) (lib.zipLists packagesLists urlPrefixes)} \
${toString packages} > $out
''; '';
@ -726,15 +728,17 @@ rec {
names. */ names. */
makeImageFromRPMDist = makeImageFromRPMDist =
{ name, fullName, size ? 4096, urlPrefix, packagesList { name, fullName, size ? 4096
, urlPrefix ? "", urlPrefixes ? [urlPrefix]
, packagesList ? "", packagesLists ? [packagesList]
, packages, extraPackages ? [] , packages, extraPackages ? []
, preInstall ? "", postInstall ? "", archs ? ["noarch" "i386"] , preInstall ? "", postInstall ? "", archs ? ["noarch" "i386"]
, runScripts ? true }: , runScripts ? true, createRootFS ? defaultCreateRootFS }:
fillDiskWithRPMs { fillDiskWithRPMs {
inherit name fullName size preInstall postInstall runScripts; inherit name fullName size preInstall postInstall runScripts createRootFS;
rpms = import (rpmClosureGenerator { rpms = import (rpmClosureGenerator {
inherit name packagesList urlPrefix archs; inherit name packagesLists urlPrefixes archs;
packages = packages ++ extraPackages; packages = packages ++ extraPackages;
}) { inherit fetchurl; }; }) { inherit fetchurl; };
}; };

View File

@ -1,34 +1,52 @@
use strict; use strict;
use XML::Simple; use XML::Simple;
my $packagesFile = shift @ARGV; my @packagesFiles = ();
my $urlPrefix = shift @ARGV; my @urlPrefixes = ();
# rpm-closure.pl (<package-file> <url-prefix>)+ <toplevel-pkg>+
while(-f $ARGV[0]) {
my $packagesFile = shift @ARGV;
my $urlPrefix = shift @ARGV;
push(@packagesFiles, $packagesFile);
push(@urlPrefixes, $urlPrefix);
}
my @toplevelPkgs = @ARGV; my @toplevelPkgs = @ARGV;
my @archs = split ' ', ($ENV{'archs'} or ""); my @archs = split ' ', ($ENV{'archs'} or "");
print STDERR "parsing packages...\n";
my $xml = XMLin($packagesFile, ForceArray => ['package', 'rpm:entry', 'file'], KeyAttr => []) or die;
print STDERR "file contains $xml->{packages} packages\n";
my %pkgs; my %pkgs;
foreach my $pkg (@{$xml->{'package'}}) { for (my $i = 0; $i < scalar(@packagesFiles); $i++) {
if (scalar @archs > 0) { my $packagesFile = $packagesFiles[$i];
my $arch = $pkg->{arch}; print STDERR "parsing packages in $packagesFile...\n";
my $found = 0;
foreach my $a (@archs) { $found = 1 if $arch eq $a; }
next if !$found;
}
if (defined $pkgs{$pkg->{name}}) {
print STDERR "WARNING: duplicate occurrence of package $pkg->{name}\n";
next;
}
$pkgs{$pkg->{name}} = $pkg;
}
my $xml = XMLin($packagesFile, ForceArray => ['package', 'rpm:entry', 'file'], KeyAttr => []) or die;
print STDERR "$packagesFile contains $xml->{packages} packages\n";
foreach my $pkg (@{$xml->{'package'}}) {
if (scalar @archs > 0) {
my $arch = $pkg->{arch};
my $found = 0;
foreach my $a (@archs) { $found = 1 if $arch eq $a; }
next if !$found;
}
if (defined $pkgs{$pkg->{name}}) {
my $earlierPkg = $pkgs{$pkg->{name}};
print STDERR "WARNING: duplicate occurrence of package $pkg->{name}\n";
if ($earlierPkg->{'time'}->{file} <= $pkg->{'time'}->{file}) {
print STDERR "WARNING: replaced package $pkg->{name} with newer one\n";
$pkg->{urlPrefix} = $urlPrefixes[$i];
$pkgs{$pkg->{name}} = $pkg;
}
next;
}
$pkg->{urlPrefix} = $urlPrefixes[$i];
$pkgs{$pkg->{name}} = $pkg;
}
}
my %provides; my %provides;
foreach my $pkgName (keys %pkgs) { foreach my $pkgName (keys %pkgs) {
@ -104,7 +122,7 @@ print "[\n\n";
foreach my $pkgName (@needed) { foreach my $pkgName (@needed) {
my $pkg = $pkgs{$pkgName}; my $pkg = $pkgs{$pkgName};
print " (fetchurl {\n"; print " (fetchurl {\n";
print " url = $urlPrefix/$pkg->{location}->{href};\n"; print " url = $pkg->{urlPrefix}/$pkg->{location}->{href};\n";
if ($pkg->{checksum}->{type} eq "sha") { if ($pkg->{checksum}->{type} eq "sha") {
print " sha1 = \"$pkg->{checksum}->{content}\";\n"; print " sha1 = \"$pkg->{checksum}->{content}\";\n";
} elsif ($pkg->{checksum}->{type} eq "sha256") { } elsif ($pkg->{checksum}->{type} eq "sha256") {