diff --git a/README.md b/README.md index 904658a..3d83687 100644 --- a/README.md +++ b/README.md @@ -101,12 +101,11 @@ in ## Refreshing hashes -Checksums of the `sha256sums` files on downloads.openwrt.org are add -to this repository for a few recent releases. For updating, modify -`release` in `generate-hashes.nix`, then run: +Checksums of the `sha256sums` files on downloads.openwrt.org are added +to this repository for a few recent releases. To update them, run: ```bash nix-shell -p nixFlakes -nix run .#generate-hashes +nix run .#generate-hashes 21.02.3 # for example git add hashes/*.nix ``` diff --git a/flake.nix b/flake.nix index 14b324e..9c62352 100644 --- a/flake.nix +++ b/flake.nix @@ -32,7 +32,6 @@ # `nix run .#generate-hashes` packages.x86_64-linux.generate-hashes = import ./generate-hashes.nix { pkgs = nixpkgs.legacyPackages.x86_64-linux; - inherit openwrt; }; packages.x86_64-linux.example-image = import ./example.nix { diff --git a/generate-hashes.nix b/generate-hashes.nix index 7381fbd..ce5af16 100644 --- a/generate-hashes.nix +++ b/generate-hashes.nix @@ -1,52 +1,24 @@ -{ pkgs ? import {} -, openwrt -}: - +{ pkgs ? import {} }: with pkgs; - -let - release = "21.02.3"; - - linuxTargets = builtins.attrNames ( - lib.filterAttrs (name: type: type == "directory" && name != "generic") ( - builtins.readDir (openwrt + "/target/linux") - ) - ); - - linuxTargetDefs = builtins.foldl' (linuxTargetDefs: target: - linuxTargetDefs // { - "${target}" = - builtins.foldl' (targetDefs: line: - let - m = builtins.match "([[:upper:]]+)[[:space:]]*:=[[:space:]]*(.+)" line; - in - if builtins.isList m && builtins.length m == 2 - then targetDefs // { - ${builtins.elemAt m 0} = builtins.elemAt m 1; - } - else targetDefs - ) {} ( - lib.splitString "\n" ( - builtins.replaceStrings [ "\\\n" ] [ "" ] ( - builtins.readFile (openwrt + "/target/linux/${target}/Makefile") - ) - ) - ); - } - ) {} linuxTargets; - - defaultFeeds = [ "base" "packages" "routing" "telephony" ]; -in - writeScriptBin "generate-hashes" '' #! ${runtimeShell} PATH=${lib.makeBinPath [ jq curl nix ]}:$PATH +RELEASE=21.02.3 +FEEDS="base packages routing telephony" + +if [ $# -gt 0 ]; then + RELEASE=$1 +fi + +UPSTREAM_URL=https://downloads.openwrt.org +RELEASE_URL=$UPSTREAM_URL/releases/$RELEASE + hash() { TARGET=$1 VARIANT=$2 - BASEURL=https://downloads.openwrt.org/releases/${release}/targets/$TARGET/$VARIANT + BASEURL=$RELEASE_URL/targets/$TARGET/$VARIANT SUM=$(nix-prefetch-url --type sha256 $BASEURL/sha256sums 2>/dev/null) if [ -n "$SUM" ]; then echo " \"$TARGET\".\"$VARIANT\" = {" @@ -54,8 +26,8 @@ hash() { ARCH=$(curl -s $BASEURL/profiles.json | jq -r .arch_packages) [ $? -ne 0 ] && echo "failed to fetch or parse $BASEURL/profiles.json" > /dev/stderr if [ -n "$ARCH" ]; then - for FEED in ${lib.escapeShellArgs defaultFeeds}; do - PACKAGES=$(nix-prefetch-url --type sha256 https://downloads.openwrt.org/releases/${release}/packages/$ARCH/$FEED/Packages 2>/dev/null) + for FEED in $FEEDS; do + PACKAGES=$(nix-prefetch-url --type sha256 $RELEASE_URL/packages/$ARCH/$FEED/Packages 2>/dev/null) echo " feedsSha256.$FEED = \"$PACKAGES\";" done fi @@ -67,12 +39,9 @@ mkdir -p hashes ( echo "{" - ${lib.concatMapStrings (target: - lib.concatMapStrings (variant: '' - hash ${target} ${variant} - '') - (lib.splitString " " (linuxTargetDefs.${target}.SUBTARGETS or "generic")) - ) linuxTargets} + curl -s $RELEASE_URL/targets/?json-targets | jq -r .[] | while IFS=/ read TARGET VARIANT; do + hash $TARGET $VARIANT + done echo "}" -) > hashes/${release}.nix +) > hashes/$RELEASE.nix ''