Created
October 5, 2024 18:53
-
-
Save cristianoliveira/ebe252285a2b297b60756b8052f980cb to your computer and use it in GitHub Desktop.
bash script generate nix package hashes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# First get version from the latest git tag | |
VERSION="$(git describe --tags --abbrev=0)" | |
NIX_FILE="nix/package.nix" | |
echo "Bumping version to $VERSION" | |
# replace version = "local-2024-09-16"; within "$NIX_FILE" | |
sed -i "s/version = \".*\";/version = \"$VERSION\";/" "$NIX_FILE" | |
sed -i 's/sha256-.*=//g' "$NIX_FILE" | |
## nix build and pipe the error to a build.log file | |
rm -f build.log | |
nix build . 2> build.log | |
# format | |
# specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= | |
# got: sha256-crOHNrO4KkHn3kKGlwitirBpsgtAGXpDKBORmpVUKFs= | |
SHA256=$(grep "got:" build.log | grep -o "sha256-.*=" | cut -d'-' -f2) | |
echo "git hash SHA256: $SHA256" | |
sed -i "s# hash = \".*\";# hash = \"sha256-$SHA256\";#" "$NIX_FILE" | |
nix build . 2> build.log | |
SHA256=$(grep "got:" build.log | grep -o "sha256-.*=" | cut -d'-' -f2) | |
echo "cargo hash SHA256: $SHA256" | |
sed -i "s#cargoHash = \".*\";#cargoHash = \"sha256-$SHA256\";#" "$NIX_FILE" | |
echo "Building nix derivation" | |
nix build . | |
rm -f build.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment