1#! /bin/sh
2
3name="$1"
4
5[ -z "$NIX_LISP_PACKAGES_DEFINED_LIST" ] && export NIX_LISP_PACKAGES_DEFINED_LIST="$(mktemp)"
6
7if [ -n "$NIX_LISP_UPDATE_PACKAGE" ] || [ -n "$NIX_LISP_UPDATE_PACKAGES" ]; then
8 export NIX_LISP_UPDATE_PACKAGE=
9else
10 nix-instantiate "$(dirname "$0")"/../../../../ -A "lispPackages.$name" > /dev/null && exit
11fi
12grep "^$name\$" "$NIX_LISP_PACKAGES_DEFINED_LIST" > /dev/null && exit
13
14echo "$name" >> "$NIX_LISP_PACKAGES_DEFINED_LIST"
15
16[ -z "$NIX_QUICKLISP_DIR" ] && {
17 export NIX_QUICKLISP_DIR="$(mktemp -d --tmpdir nix-quicklisp.XXXXXX)"
18}
19
20[ -f "$NIX_QUICKLISP_DIR/setup.lisp" ] || {
21 "$(dirname "$0")/quicklisp-beta-env.sh" "$NIX_QUICKLISP_DIR" &> /dev/null < /dev/null
22}
23
24description="$("$(dirname "$0")/asdf-description.sh" "$name")"
25[ -z "$description" ] && {
26 description="$(curl -L https://github.com/quicklisp/quicklisp-projects/raw/master/"$name"/description.txt)"
27 [ "$(echo "$description" | wc -l)" -gt 10 ] && description=""
28}
29
30dependencies="$("$(dirname "$0")/quicklisp-dependencies.sh" "$name" | xargs)"
31ql_src="$(curl -L https://github.com/quicklisp/quicklisp-projects/raw/master/"$name"/source.txt)"
32ql_src_type="${ql_src%% *}"
33url="${ql_src##* }"
34
35[ "$ql_src_type" = "kmr-git" ] && {
36 ql_src_type=git
37 url="http://git.kpe.io/$url.git"
38 export NIX_PREFETCH_GIT_DEEP_CLONE=1
39}
40
41[ "$ql_src_type" = ediware-http ] && {
42 ql_src_type=github
43 url="edicl/$url";
44}
45
46[ "$ql_src_type" = xach-http ] && {
47 ql_src_type=github
48 url="xach/$url";
49}
50
51[ "$ql_src_type" = github ] && {
52 ql_src_type=git
53 url="https://github.com/$url";
54 version="$("$(dirname "$0")/urls-from-page.sh" "$url/releases/" | grep /tag/ | head -n 1 | xargs -l1 basename)"
55 rev="refs/tags/$version";
56}
57
58[ "$ql_src_type" = git ] && {
59 fetcher="pkgs.fetchgit"
60 ( [ "${url#git://github.com/}" != "$url" ] ||
61 [ "${url#https://github.com/}" != "$url" ]
62 ) && {
63 url="${url/git:/https:}"
64 url="${url%.git}"
65 [ -z "$rev" ] && rev=$("$(dirname "$0")/urls-from-page.sh" "$url/commits" | grep /commit/ | head -n 1 | xargs basename)
66 hash=$("$(dirname "$0")/../../../build-support/fetchgit/nix-prefetch-git" "$url" "$rev" | grep . | tail -n 1)
67 [ -z "$version" ] && version="git-$(date +%Y%m%d)";
68 }
69 [ "${url#git://common-lisp.net/}" != "$url" ] && {
70 http_repo_url="$url"
71 http_repo_url="${http_repo_url/git:/http:}"
72 http_repo_url="${http_repo_url/\/projects\// /r/projects/}"
73 http_repo_head="$http_repo_url/refs/heads/master"
74 echo "$http_repo_head" >&2
75 [ -z "$rev" ] && rev=$(curl -L "$http_repo_head");
76 hash=$("$(dirname "$0")/../../../build-support/fetchgit/nix-prefetch-git" "$url" "$rev")
77 [ -z "$version" ] && version="git-$(date +%Y%m%d)";
78 }
79 [ "${url#http://git.b9.com/}" != "$url" ] && {
80 http_repo_url="$url"
81 http_repo_url="${http_repo_url/git:/http:}"
82 http_repo_head="$http_repo_url/refs/heads/master"
83 echo "$http_repo_head" >&2
84 rev=$(curl -L "$http_repo_head");
85 hash=$("$(dirname "$0")/../../../build-support/fetchgit/nix-prefetch-git" "$url" "$rev" | tail -n 1)
86 version="git-$(date +%Y%m%d)";
87 }
88 [ "${url#http://common-lisp.net/}" != "$url" ] && {
89 http_repo_url="$url"
90 http_repo_url="${http_repo_url/git:/http:}"
91 http_repo_head="$http_repo_url/refs/heads/master"
92 echo "$http_repo_head" >&2
93 rev=$(curl -L "$http_repo_head");
94 hash=$("$(dirname "$0")/../../../build-support/fetchgit/nix-prefetch-git" "$url" "$rev" | tail -n 1)
95 version="git-$(date +%Y%m%d)";
96 }
97}
98
99[ "$ql_src_type" = cvs ] && {
100 fetcher="pkgs.fetchcvs"
101 date="$(date -d yesterday +%Y-%m-%d)"
102 version="cvs-$date"
103 module="${module:-$name}"
104 hash=$(USE_DATE=1 "$(dirname "$0")/../../../build-support/fetchcvs/nix-prefetch-cvs" "$url" "$module" "$date")
105 cvsRoot="$url"
106 unset url
107}
108
109[ "$ql_src_type" = clnet-darcs ] && {
110 ql_src_type=darcs
111 url="http://common-lisp.net/project/$url/darcs/$url/"
112}
113
114[ "$ql_src_type" = darcs ] && {
115 fetcher="pkgs.fetchdarcs"
116 [ -z "$version" ] &&
117 version="$(curl "$url/_darcs/inventory" | grep '\[TAG ' | tail -n 1 | sed -e 's/.* //')"
118 [ -z "$version" ] &&
119 version="$(curl "$url/_darcs/hashed_inventory" | grep '\[TAG ' | tail -n 1 | sed -e 's/.* //')"
120 rev="$version";
121 hash=$(echo "
122 with (import <nixpkgs> {});
123 fetchdarcs {
124 url=''$url'';
125 rev=''$version'';
126 sha256=''0000000000000000000000000000000000000000000000000000000000000000'';
127 }" | nix-instantiate - | tail -n 1 |
128 xargs nix-store -r 2>&1 | tee /dev/stderr | grep 'instead has' | tail -n 1 |
129 sed -e 's/.* instead has .//;s/[^0-9a-z].*//')
130}
131
132[ "$ql_src_type" = froydware-http ] && {
133 dirurl="http://method-combination.net/lisp/files/";
134 url="$("$(dirname "$0")/urls-from-page.sh" "$dirurl" |
135 grep "/${url}_" | grep -v "[.]asc\$" | tail -n 1)"
136 ql_src_type=http
137}
138
139[ "$ql_src_type" = http ] && {
140 fetcher="pkgs.fetchurl";
141 version="$(echo "$url" | sed -re 's@.*[-_]([0-9.]+)[-._].*@\1@')"
142 hash="$(nix-prefetch-url "$url" | grep . | tail -n 1)"
143}
144
145[ "$ql_src_type" = https ] && {
146 fetcher="pkgs.fetchurl";
147 version="$(echo "$url" | sed -re 's@.*[-_]([0-9.]+)[-._].*@\1@')"
148 hash="$(nix-prefetch-url "$url" | grep . | tail -n 1)"
149}
150
151if [ "$ql_src" = '{"error":"Not Found"}' ]; then
152 echo "# $name: not found"
153else
154cat << EOF | grep -Ev '^[ ]+$'
155
156 $name = buildLispPackage rec {
157 baseName = "$name";
158 version = "${version:-\${Set me //}";
159 description = "$description";
160 deps = [$dependencies];
161 # Source type: $ql_src_type
162 src = ${fetcher:-pkgs.fetchurl} {
163 ${url:+url = ''$url'';}
164 sha256 = "${hash:-0000000000000000000000000000000000000000000000000000000000000000}";
165 ${rev:+rev = ''$rev'';}
166 ${date:+date = ''$date'';}
167 ${module:+module = ''$module'';}
168 ${cvsRoot:+cvsRoot = ''$cvsRoot'';}
169 };
170 };
171EOF
172fi
173
174for i in $dependencies; do "$0" "$i"; done