From 29142da5a2c38becc78fadfcceca644386e5c738 Mon Sep 17 00:00:00 2001 From: Marc Esquerra Date: Fri, 28 Jun 2024 14:16:31 +0100 Subject: [PATCH 1/6] Preparatory work --- .envrc | 4 ++++ flake.nix | 3 ++- gohip.vendor.hash.nix | 1 + shell.nix | 11 ++++++++--- 4 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 gohip.vendor.hash.nix diff --git a/.envrc b/.envrc index 3c109b4..e6090cc 100644 --- a/.envrc +++ b/.envrc @@ -4,4 +4,8 @@ if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs=" fi +nix_direnv_watch_file ./shell.nix +nix_direnv_watch_file ./flake.nix +nix_direnv_watch_file ./gohip.vendor.hash.nix + use flake diff --git a/flake.nix b/flake.nix index f4e0e9d..57f5527 100644 --- a/flake.nix +++ b/flake.nix @@ -11,12 +11,13 @@ pkgs = import nixpkgs { inherit system overlays; }; + gohip-vendor-hash = import ./gohip.vendor.hash.nix; gohip-package = (pkgs.buildGoModule { name = "gohip"; pname = "gohip"; src = ./.; - vendorHash = "sha256-jZcR+OMiGplA5yVMpQT4qNKH+tyFp7PXQVoG+oghBLs="; + vendorHash = gohip-vendor-hash pkgs; proxyVendor = true; excludedPackages = ["osdata" "others" "systemd" "types"]; }); diff --git a/gohip.vendor.hash.nix b/gohip.vendor.hash.nix new file mode 100644 index 0000000..9ea0ade --- /dev/null +++ b/gohip.vendor.hash.nix @@ -0,0 +1 @@ +pkgs : "sha256-jZcR+OMiGplA5yVMpQT4qNKH+tyFp7PXQVoG+oghBLs=" diff --git a/shell.nix b/shell.nix index 3c3f160..c9c8021 100644 --- a/shell.nix +++ b/shell.nix @@ -1,5 +1,10 @@ pkgs : -pkgs.mkShell { - buildInputs = [ pkgs.go ]; -} +let + upgrade-nix-gohip = pkgs.writeShellScriptBin "upgrade-nix-gohip" '' + echo "UPGRADING" + ''; +in + pkgs.mkShell { + buildInputs = [ pkgs.go upgrade-nix-gohip ]; + } From 1110bb2baf45546ce8026fea0681c4987fd3b7fa Mon Sep 17 00:00:00 2001 From: Marc Esquerra Date: Fri, 28 Jun 2024 14:27:09 +0100 Subject: [PATCH 2/6] Finish upgrade script --- .envrc | 4 +++- shell.nix | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.envrc b/.envrc index e6090cc..6c8cf5c 100644 --- a/.envrc +++ b/.envrc @@ -4,8 +4,10 @@ if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs=" fi +export WORKSPACE="${PWD}" + nix_direnv_watch_file ./shell.nix nix_direnv_watch_file ./flake.nix -nix_direnv_watch_file ./gohip.vendor.hash.nix +# nix_direnv_watch_file ./gohip.vendor.hash.nix use flake diff --git a/shell.nix b/shell.nix index c9c8021..7dc4977 100644 --- a/shell.nix +++ b/shell.nix @@ -3,6 +3,10 @@ pkgs : let upgrade-nix-gohip = pkgs.writeShellScriptBin "upgrade-nix-gohip" '' echo "UPGRADING" + echo "pkgs : pkgs.lib.fakeHash" > $WORKSPACE/gohip.vendor.hash.nix + NEW_HASH=`nix build .#default 2>&1 | grep " got: " | awk '{print $2}'` + echo "pkgs : \"$NEW_HASH\"" > $WORKSPACE/gohip.vendor.hash.nix + ''; in pkgs.mkShell { From 86915da66788d9a95551ce77a40b3e4538c26b95 Mon Sep 17 00:00:00 2001 From: Marc Esquerra Date: Fri, 28 Jun 2024 15:00:00 +0100 Subject: [PATCH 3/6] This should update the hash every release --- .envrc | 1 - .github/workflows/release.yml | 19 +++++++++++++++++++ flake.nix | 14 +++++++++++++- shell.nix | 11 ++--------- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/.envrc b/.envrc index 6c8cf5c..88ce07d 100644 --- a/.envrc +++ b/.envrc @@ -8,6 +8,5 @@ export WORKSPACE="${PWD}" nix_direnv_watch_file ./shell.nix nix_direnv_watch_file ./flake.nix -# nix_direnv_watch_file ./gohip.vendor.hash.nix use flake diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 127bab1..c5c3cc6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -130,3 +130,22 @@ jobs: files: | build-aux/arch/gohip-bin/gohip-bin-*-1-x86_64.pkg.tar.zst build-aux/arch/gohip-bin/gohip-bin-*-1-x86_64.pkg.tar.zst.md5sum + + nix: + needs: [ build ] # Technically doesn't relly need build, but don't want to try and update this if the `build` step + # doesn't work + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - uses: cachix/install-nix-action@v27 + with: + github_access_token: ${{ secrets.GITHUB_TOKEN }} + - run: | + export WORKSPACE="${PWD}" + nix run .#upgrade-nix-gohip + git config --global user.name 'jgarcia' + git config --global user.email 'garciaj.uk@gmail.com' + git commit -am "Automated nix hash update" + git push diff --git a/flake.nix b/flake.nix index 57f5527..a3897cc 100644 --- a/flake.nix +++ b/flake.nix @@ -22,10 +22,18 @@ excludedPackages = ["osdata" "others" "systemd" "types"]; }); + upgrade-nix-gohip-package = pkgs.writeShellScriptBin "upgrade-nix-gohip" '' + echo "UPGRADING" + echo "pkgs : pkgs.lib.fakeHash" > $WORKSPACE/gohip.vendor.hash.nix + NEW_HASH=`nix build .#default 2>&1 | grep " got: " | awk '{print $2}'` + echo "pkgs : \"$NEW_HASH\"" > $WORKSPACE/gohip.vendor.hash.nix + ''; + custom-packages = {upgrade-nix-gohip = upgrade-nix-gohip-package;}; + in with pkgs; { - devShells.default = (import ./shell.nix) pkgs; + devShells.default = (import ./shell.nix) pkgs custom-packages; apps = rec { gohip = flake-utils.lib.mkApp { drv = pkgs.writeShellScriptBin "gohip" '' @@ -33,10 +41,14 @@ "${gohip-package}"/bin/gohip ''; }; + upgrade-nix-gohip = flake-utils.lib.mkApp { + drv = upgrade-nix-gohip-package; + }; default = gohip; }; packages = rec { gohip = gohip-package; + upgrade-nix-gohip = upgrade-nix-gohip-package; default = gohip; }; } diff --git a/shell.nix b/shell.nix index 7dc4977..99d2a7f 100644 --- a/shell.nix +++ b/shell.nix @@ -1,14 +1,7 @@ -pkgs : +pkgs : custom-packages : let - upgrade-nix-gohip = pkgs.writeShellScriptBin "upgrade-nix-gohip" '' - echo "UPGRADING" - echo "pkgs : pkgs.lib.fakeHash" > $WORKSPACE/gohip.vendor.hash.nix - NEW_HASH=`nix build .#default 2>&1 | grep " got: " | awk '{print $2}'` - echo "pkgs : \"$NEW_HASH\"" > $WORKSPACE/gohip.vendor.hash.nix - - ''; in pkgs.mkShell { - buildInputs = [ pkgs.go upgrade-nix-gohip ]; + buildInputs = [ pkgs.go custom-packages.upgrade-nix-gohip ]; } From fd75cde93c788f5b8df2b34dca3c0a7779b60822 Mon Sep 17 00:00:00 2001 From: Marc Esquerra Date: Fri, 28 Jun 2024 15:08:44 +0100 Subject: [PATCH 4/6] Address PR comments --- .github/workflows/nix.yml | 23 +++++++++++++++++++++++ .github/workflows/release.yml | 19 ------------------- gohip.vendor.hash.nix | 2 +- 3 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/nix.yml diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml new file mode 100644 index 0000000..1314c2a --- /dev/null +++ b/.github/workflows/nix.yml @@ -0,0 +1,23 @@ +name: Update nix config + +on: + push: + branches: + - main + +jobs: + nix: + steps: + - name: Checkout + uses: actions/checkout@v3 + + - uses: cachix/install-nix-action@v27 + with: + github_access_token: ${{ secrets.GITHUB_TOKEN }} + - run: | + export WORKSPACE="${PWD}" + nix run .#upgrade-nix-gohip + git config --global user.name 'jgarcia' + git config --global user.email 'garciaj.uk@gmail.com' + git commit -am "Automated nix hash update" + git push diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c5c3cc6..127bab1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -130,22 +130,3 @@ jobs: files: | build-aux/arch/gohip-bin/gohip-bin-*-1-x86_64.pkg.tar.zst build-aux/arch/gohip-bin/gohip-bin-*-1-x86_64.pkg.tar.zst.md5sum - - nix: - needs: [ build ] # Technically doesn't relly need build, but don't want to try and update this if the `build` step - # doesn't work - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - uses: cachix/install-nix-action@v27 - with: - github_access_token: ${{ secrets.GITHUB_TOKEN }} - - run: | - export WORKSPACE="${PWD}" - nix run .#upgrade-nix-gohip - git config --global user.name 'jgarcia' - git config --global user.email 'garciaj.uk@gmail.com' - git commit -am "Automated nix hash update" - git push diff --git a/gohip.vendor.hash.nix b/gohip.vendor.hash.nix index 9ea0ade..9759243 100644 --- a/gohip.vendor.hash.nix +++ b/gohip.vendor.hash.nix @@ -1 +1 @@ -pkgs : "sha256-jZcR+OMiGplA5yVMpQT4qNKH+tyFp7PXQVoG+oghBLs=" +pkgs : "sha256-6+n1rLcpWI553EUl98UVRCu/nK8+dw9cLJqmpA3LTsw=" From 49ef80669355d6e123443d3cb52a34ecc185f506 Mon Sep 17 00:00:00 2001 From: Marc Esquerra Date: Fri, 28 Jun 2024 15:48:33 +0100 Subject: [PATCH 5/6] Address PR comments --- .github/workflows/nix.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index 1314c2a..2729077 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -17,7 +17,7 @@ jobs: - run: | export WORKSPACE="${PWD}" nix run .#upgrade-nix-gohip - git config --global user.name 'jgarcia' - git config --global user.email 'garciaj.uk@gmail.com' + git config --global user.name 'autobot' + git config --global user.email 'gohip.nix@github.com' git commit -am "Automated nix hash update" git push From 8dca887ec1297d075a93c76432c96ae5c4c52a07 Mon Sep 17 00:00:00 2001 From: Marc Esquerra Date: Fri, 28 Jun 2024 16:08:30 +0100 Subject: [PATCH 6/6] Ensure hash updating commits do not trigger github actions --- .github/workflows/nix.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index 2729077..968862f 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -19,5 +19,5 @@ jobs: nix run .#upgrade-nix-gohip git config --global user.name 'autobot' git config --global user.email 'gohip.nix@github.com' - git commit -am "Automated nix hash update" + git commit -am "[skip ci] Automated nix hash update" git push