about summary refs log tree commit diff
path: root/nixpkgs/pkgs/os-specific/linux/firmware/linux-firmware/update.sh
blob: 1fccc03e86be21bbef23fa7decdeb77852609f95 (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
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$(readlink -f "$0")")" || exit

repo="https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git"

# step 1: figure out the latest version from the tags
if [ -z "$1" ]; then
  version="$(git ls-remote --refs --tags --sort refname "$repo" | tail -n1 | cut -f2 | cut -d '/' -f3)"
else
  version=$1
fi

# step 2: prefetch the source tarball
snapshotUrl="$repo/snapshot/linux-firmware-$version.tar.gz"
hash="$(nix-prefetch-url --unpack "$snapshotUrl")"
sriHash="$(nix --experimental-features nix-command hash to-sri "sha256:$hash")"

# step 3: rebuild as a non-FO derivation to get the right hash
cat > source.nix << EOF
{
  version = "$version";
  sourceHash = "$sriHash";
  outputHash = null;
}
EOF

outPath="$(nix --experimental-features "nix-command flakes" build ".#linux-firmware" --no-link --print-out-paths)"
outHash="$(nix --experimental-features nix-command hash path "$outPath")"

# step 4: generate the final file
cat > source.nix << EOF
# This file is autogenerated! Run ./update.sh to regenerate.
{
  version = "$version";
  sourceHash = "$sriHash";
  outputHash = "$outHash";
}
EOF