This repository has no description
2.5 kB
67 lines
1{ ... }:
2{
3 perSystem =
4 { pkgs, ... }:
5 {
6 # update-pkgs [attr...] (no attrs: every package with an updateScript)
7 #
8 # Runs passthru.updateScript the way nixpkgs' maintainers/scripts/update.py
9 # does (UPDATE_NIX_ATTR_PATH/PNAME/OLD_VERSION/NAME, cwd = flake root),
10 # for this flake's packages. Packages missing from the host's package set
11 # (linux-only ones on darwin) are taken from x86_64-linux; nix-update in
12 # their command is swapped for the host's, the rest of the command stays.
13 packages.update-pkgs =
14 (pkgs.writeShellApplication {
15 name = "update-pkgs";
16 runtimeInputs = [
17 pkgs.git
18 pkgs.jq
19 pkgs.nix-update
20 ];
21 text = ''
22 root=$(git rev-parse --show-toplevel)
23 cd "$root"
24 host=$(nix eval --raw --impure --expr builtins.currentSystem)
25 all=$(nix eval --json --impure --expr "import ${./scripts.nix} { flake = \"$root\"; host = \"$host\"; }")
26
27 if [ "''${1:-}" = --list ]; then
28 jq -r 'to_entries[] | "\(.key)\t\(.value.cmd | join(" "))"' <<<"$all"
29 exit 0
30 fi
31 if [ $# -gt 0 ]; then
32 attrs=("$@")
33 else
34 mapfile -t attrs < <(jq -r 'keys[]' <<<"$all")
35 fi
36
37 failed=()
38 for attr in "''${attrs[@]}"; do
39 entry=$(jq -c --arg a "$attr" '.[$a] // empty' <<<"$all")
40 if [ -z "$entry" ]; then
41 echo "update-pkgs: $attr has no updateScript" >&2
42 failed+=("$attr")
43 continue
44 fi
45 mapfile -t cmd < <(jq -r '.cmd[]' <<<"$entry")
46 case "''${cmd[0]}" in
47 */bin/nix-update) cmd[0]=nix-update ;;
48 esac
49 printf '\n\033[1m== %s\033[0m\n' "$attr" >&2
50 if ! UPDATE_NIX_ATTR_PATH=$attr \
51 UPDATE_NIX_PNAME=$(jq -r .pname <<<"$entry") \
52 UPDATE_NIX_OLD_VERSION=$(jq -r .version <<<"$entry") \
53 UPDATE_NIX_NAME=$(jq -r .name <<<"$entry") \
54 "''${cmd[@]}"; then
55 failed+=("$attr")
56 fi
57 done
58
59 if [ ''${#failed[@]} -gt 0 ]; then
60 echo "update-pkgs: failed: ''${failed[*]}" >&2
61 exit 1
62 fi
63 '';
64 }).overrideAttrs
65 { passthru.usage = builtins.readFile ./usage.kdl; };
66 };
67}