forked from nix-community/nixpkgs-wayland
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·162 lines (132 loc) · 6.05 KB
/
update.sh
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
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
set -euo pipefail
set -x
unset NIX_PATH
# build up commit msg
defaultcommitmsg="auto-updates:"
commitmsg="${defaultcommitmsg}";
# keep track of what we build for the README
pkgentries=(); nixpkgentries=();
cache="nixpkgs-wayland";
build_attr="${1:-"waylandPkgs"}"
function update() {
set +x
typ="${1}"
pkg="${2}"
echo "============================================================================"
echo "${pkg}: checking"
metadata="${pkg}/metadata.nix"
pkgname="$(basename "${pkg}")"
# TODO: nix2json, update in parallel
# TODO: aka, not in bash
branch="$(nix-instantiate "${metadata}" --eval --json -A branch 2>/dev/null | jq -r .)"
rev="$(nix-instantiate "${metadata}" --eval --json -A rev 2>/dev/null | jq -r .)"
sha256="$(nix-instantiate "${metadata}" --eval --json -A sha256 2>/dev/null | jq -r .)"
upattr="$(nix-instantiate "${metadata}" --eval --json -A upattr 2>/dev/null | jq -r . || echo "${pkgname}")"
url="$(nix-instantiate "${metadata}" --eval --json -A url 2>/dev/null | jq -r . || echo "missing_url")"
cargoSha256="$(nix-instantiate "${metadata}" --eval --json -A cargoSha256 2>/dev/null | jq -r . || echo "missing_cargoSha256")"
vendorSha256="$(nix-instantiate "${metadata}" --eval --json -A vendorSha256 2>/dev/null | jq -r . || echo "missing_vendorSha256")"
skip="$(nix-instantiate "${metadata}" --eval --json -A skip 2>/dev/null | jq -r . || echo "false")"
if [[ "${skip}" != "true" ]]; then
# Determine RepoTyp (git/hg)
if nix-instantiate "${metadata}" --eval --json -A repo_git &>/dev/null; then repotyp="git";
elif nix-instantiate "${metadata}" --eval --json -A repo_hg &>/dev/null; then repotyp="hg";
else echo "unknown repo_typ" && exit 1;
fi
# Update Rev
if [[ "${repotyp}" == "git" ]]; then
repo="$(nix-instantiate "${metadata}" --eval --json -A repo_git | jq -r .)"
newrev="$(git ls-remote "${repo}" "${branch}" | awk '{ print $1}')"
elif [[ "${repotyp}" == "hg" ]]; then
repo="$(nix-instantiate "${metadata}" --eval --json -A repo_hg | jq -r .)"
newrev="$(hg identify "${repo}" -r "${branch}")"
fi
if [[ "${rev}" != "${newrev}" ]]; then
commitmsg="${commitmsg} ${pkgname},"
echo "${pkg}: ${rev} => ${newrev}"
set -x
# Update Sha256
if [[ "${typ}" == "pkgs" ]]; then
newsha256="$(NIX_PATH="nixpkgs=https://github.com/nixos/nixpkgs/archive/nixos-unstable.tar.gz" \
nix-prefetch --output raw \
-E "(import ./packages.nix).${upattr}" \
--rev "${newrev}")"
elif [[ "${typ}" == "nixpkgs" ]]; then
newsha256="$(NIX_PATH="${tmpnixpath}" nix-prefetch-url --unpack "${url}" 2>/dev/null)"
fi
# TODO: do this with nix instead of sed?
sed -i "s/${rev}/${newrev}/" "${metadata}"
sed -i "s|${sha256}|${newsha256}|" "${metadata}"
# CargoSha256 has to happen AFTER the other rev/sha256 bump
if [[ "${cargoSha256}" != "missing_cargoSha256" ]]; then
newcargoSha256="$(NIX_PATH="nixpkgs=https://github.com/nixos/nixpkgs/archive/nixos-unstable.tar.gz" \
nix-prefetch \
"{ sha256 }: let p=(import ./packages.nix).${upattr}; in p.cargoDeps.overrideAttrs (_: { cargoSha256 = sha256; })")"
sed -i "s|${cargoSha256}|${newcargoSha256}|" "${metadata}"
fi
# VendorSha256 has to happen AFTER the other rev/sha256 bump
if [[ "${vendorSha256}" != "missing_vendorSha256" ]]; then
newvendorSha256="$(NIX_PATH="nixpkgs=https://github.com/nixos/nixpkgs/archive/nixos-unstable.tar.gz" \
nix-prefetch \
"{ sha256 }: let p=(import ./packages.nix).${upattr}; in p.go-modules.overrideAttrs (_: { vendorSha256 = sha256; })")"
sed -i "s|${vendorSha256}|${newvendorSha256}|" "${metadata}"
fi
set +x
fi
fi
if [[ "${typ}" == "pkgs" ]]; then
desc="$(nix-instantiate --eval -E "(import ./packages.nix).${upattr}.meta.description" | jq -r .)"
home="$(nix-instantiate --eval -E "(import ./packages.nix).${upattr}.meta.homepage" | jq -r .)"
pkgentries=("${pkgentries[@]}" "| [${pkgname}](${home}) | ${desc} |");
elif [[ "${typ}" == "nixpkgs" ]]; then
nixpkgentries=("${nixpkgentries[@]}" "| ${pkgname} |");
fi
}
function update_readme() {
set +x
replace="$(printf "<!--pkgs-->")"
replace="$(printf "%s\n| Package | Description |" "${replace}")"
replace="$(printf "%s\n| ------- | ----------- |" "${replace}")"
for p in "${pkgentries[@]}"; do
replace="$(printf "%s\n%s\n" "${replace}" "${p}")"
done
replace="$(printf "%s\n<!--pkgs-->" "${replace}")"
rg --multiline '(?s)(.*)<!--pkgs-->(.*)<!--pkgs-->(.*)' "README.md" \
--replace "\$1${replace}\$3" \
> README2.md; mv README2.md README.md
}
# update flake inputs
nix --experimental-features 'nix-command flakes' \
flake update \
--update-input master \
--update-input nixpkgs \
--update-input cachixpkgs \
--update-input flake-utils
# update our package sources/sha256s
for p in `ls -d -- pkgs/*/`; do
update "pkgs" "${p}"
done
update_readme
set -x
out="$(mktemp -d)"
nix-build-uncached -build-flags "--out-link '${out}/result' \
--option 'extra-binary-caches' 'https://cache.nixos.org https://nixpkgs-wayland.cachix.org' \
--option 'trusted-public-keys' 'cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= nixpkgs-wayland.cachix.org-1:3lwxaILxMRkVhehr5StQprHdEo4IrE8sRho9R9HOLYA=' \
--option 'build-cores' '0' \
--option 'narinfo-cache-negative-ttl' '0'" \
packages.nix
if find ${out} | grep result; then
nix --experimental-features 'nix-command flakes' \
path-info --json -r ${out}/result* > ${out}/path-info.json
jq -r 'map(select(.ca == null and .signatures == null)) | map(.path) | .[]' < "${out}/path-info.json" > "${out}/paths"
cachix push "${cache}" < "${out}/paths"
fi
if [[ "${JOB_ID:-""}" != "" ]]; then
git status
git add -A .
git status
git diff-index --cached --quiet HEAD || git commit -m "${commitmsg}"
echo "we're building on sr.ht, pushing..."
git push origin HEAD
fi