Skip to content

Commit

Permalink
Merge pull request bechampion#15 from marcesquerra/AutoUpdateNix
Browse files Browse the repository at this point in the history
Auto update nix
  • Loading branch information
gr211 authored Jun 30, 2024
2 parents 6548800 + 8dca887 commit 562e688
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ 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

use flake
23 changes: 23 additions & 0 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
@@ -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 'autobot'
git config --global user.email '[email protected]'
git commit -am "[skip ci] Automated nix hash update"
git push
17 changes: 15 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,44 @@
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"];
});

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" ''
cd `mktemp -d`
"${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;
};
}
Expand Down
1 change: 1 addition & 0 deletions gohip.vendor.hash.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pkgs : "sha256-6+n1rLcpWI553EUl98UVRCu/nK8+dw9cLJqmpA3LTsw="
10 changes: 6 additions & 4 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pkgs :
pkgs : custom-packages :

pkgs.mkShell {
buildInputs = [ pkgs.go ];
}
let
in
pkgs.mkShell {
buildInputs = [ pkgs.go custom-packages.upgrade-nix-gohip ];
}

0 comments on commit 562e688

Please sign in to comment.