blob: 239f1a5935ee31a86929d53dc66ad591df7338ae (
about) (
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
#!/bin/sh
set -eu
TARBALL_TEMPLATE='https://git.euandreh.xyz/@NAME@/snapshot/@NAME@-@VERSION@.tar.gz'
tarball_url() {
NAME="$1"
VERSION="$2"
echo "$TARBALL_TEMPLATE" | \
sed -e "s/@NAME@/$NAME/g" \
-e "s/@VERSION@/$VERSION/g"
}
gen_guix() {
GUIX_OUT="$(mktemp)"
cat <<EOF >>"$GUIX_OUT"
(define-module (xyz euandreh packages)
#:use-module (json)
#:use-module ((ice-9 textual-ports) #:prefix textual-ports:)
#:use-module ((guix licenses) #:prefix license:)
#:use-module (gnu packages)
#:use-module (guix transformations)
#:use-module (guix gexp)
#:use-module (guix packages)
#:use-module (guix download)
#:use-module (guix git-download)
#:use-module (guix utils)
#:use-module (guix store)
#:use-module (guix build-system gnu))
EOF
for p in $(jq -r '.packages[] | @base64' < paku.json); do
NAME="$(echo "$p" | base64 --decode | jq -r '.name')"
VERSION="$(echo "$p" | base64 --decode | jq -r '.version')"
TARBALL="$(tarball_url "$NAME" "$VERSION")"
SHA256="$(guix download "$TARBALL" | tail -n 1)"
JSON_CHECK_INPUTS="$(echo "$p" | base64 --decode | jq -r '.check_inputs')"
if [ "$JSON_CHECK_INPUTS" = 'null' ]; then
CHECK_INPUTS=''
else
INPUTS=''
for check_input in $(echo "$JSON_CHECK_INPUTS" | jq -r '.[]'); do
if [ "$INPUTS" = '' ]; then
INPUTS="(\"$check_input\" ,(specification->package \"$check_input\"))"
else
INPUTS="$INPUTS
(\"$check_input\" ,(specification->package \"$check_input\"))"
fi
done
CHECK_INPUTS="
(inputs
\`($INPUTS))"
fi
cat <<EOF >>"$GUIX_OUT"
(define-public $NAME
(package
(name "$NAME")
(version "$VERSION")
(source (origin
(method url-fetch)
(uri (string-append
"https://git.euandreh.xyz/$NAME/snapshot/$NAME-"
version
".tar.gz"))
(sha256
(base32
"$SHA256"))))
(build-system gnu-build-system)$CHECK_INPUTS
(arguments \`(#:make-flags (list (string-append "CC=" ,(cc-for-target)))))
(synopsis (file-append source "/description"))
(description (file-append source "/long-description"))
(home-page (string-append "https://" name ".euandreh.xyz"))
(license license:agpl3+)))
EOF
done
printf '\n(list' >>"$GUIX_OUT"
for name in $(jq -r '.packages[].name' < paku.json); do
printf '\n %s' "$name" >>"$GUIX_OUT"
done
printf ')\n' >>"$GUIX_OUT"
mv "$GUIX_OUT" src/xyz/euandreh/packages.scm
}
gen_nix() {
NIX_OUT="$(mktemp)"
cat <<EOF >>"$NIX_OUT"
{ pkgs }:
self: super: {
xyz-euandreh = {
EOF
for p in $(jq -r '.packages[] | @base64' < paku.json); do
NAME="$(echo "$p" | base64 --decode | jq -r '.name')"
VERSION="$(echo "$p" | base64 --decode | jq -r '.version')"
TARBALL="$(tarball_url "$NAME" "$VERSION")"
SHA256="$(nix-prefetch-url --unpack "$TARBALL")"
JSON_CHECK_INPUTS="$(echo "$p" | base64 --decode | jq -r '.check_inputs')"
if [ "$JSON_CHECK_INPUTS" = 'null' ]; then
CHECK_INPUTS=''
else
INPUTS='['
for check_input in $(echo "$JSON_CHECK_INPUTS" | jq -r '.[]'); do
INPUTS="$INPUTS $check_input"
done
INPUTS="$INPUTS ]"
CHECK_INPUTS="
checkInputs = with pkgs; $INPUTS;"
fi
cat <<EOF >>"$NIX_OUT"
$NAME = pkgs.stdenv.mkDerivation rec {
name = "$NAME";
version = "$VERSION";
src = fetchTarball {
url =
"https://git.euandreh.xyz/\${name}/snapshot/\${name}-\${version}.tar.gz";
sha256 = "$SHA256";
};
makeFlags = [ "CC=cc" ];
$CHECK_INPUTS
doCheck = true;
meta = with pkgs.lib; {
description = readFile "\${src}/description";
longDescription = readFile "\${src}/long-description";
homepage = "https://\${name}.euandreh.xyz";
changelog = "https://\${name}.euandreh.xyz/CHANGELOG.html";
downloadPage = "https://\${name}.euandreh.xyz/#releases";
license = licenses.agpl3;
platforms = platforms.unix;
};
};
EOF
done
cat <<EOF >>"$NIX_OUT"
};
}
EOF
mv "$NIX_OUT" default.nix
}
refresh_packages() {
COUNT="$(jq -r '.packages[].name' < paku.json | wc -l)"
INDEXES="$(seq 0 "$((COUNT - 1))")"
for N in $INDEXES; do
NAME="$(jq -r ".packages[$N].name" < paku.json)"
cd "../$NAME/"
NEW_VERSION="$(git rev-parse HEAD)"
cd - >/dev/null
jq -r ".packages[$N].version = \"$NEW_VERSION\"" paku.json | sponge paku.json
done
}
while getopts 'gr' flag; do
case "$flag" in
g)
gen_guix
gen_nix
;;
r)
refresh_packages
;;
*)
printf 'Unrecognized flag "%s".\n' "$flag" >&2
;;
esac
done
|