about summary refs log tree commit diff
path: root/pkgs/build-support/vm/rpm/rpm-list-to-nix.pl
blob: c625cce2fd9e1fc3942ee7312144c90e4b325401 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#! /usr/bin/perl -w

use strict;

my $list = shift;
my $expr = shift;

open LIST, "<$list";
open NEW, ">$list.tmp";
open EXPR, ">$expr";

print EXPR "{fetchurl}: [\n";

my $baseURL;

while (<LIST>) {

    if (/^\s*baseURL\s+(\S+)\s*$/) {
        $baseURL = $1;
        print NEW "baseURL $baseURL\n";
    } 
    
    elsif (/^\s*(\S+)(\s+([a-f0-9]+))?\s*$/) {
        my $pkgName = $1;
        my $url = "$baseURL/$pkgName";
        my $hash = $3;
        if (!defined $hash) {
            $hash = `nix-prefetch-url '$url'`;
            die "fetch of `$url' failed" if ($? != 0);
            chomp $hash;
        }
        print NEW "$pkgName $hash\n";
        print EXPR "  (fetchurl {url=$url; md5=\"$hash\";})\n";
    }

    else {
        die "invalid line"
    }
}

print EXPR "]\n";

close LIST;
close NEW;
close EXPR;

rename "$list\.tmp", "$list" or die "cannot rename";