Skip to content

Commit

Permalink
Problem: gomod2nix don't use the same golang version as project (#853)
Browse files Browse the repository at this point in the history
* Problem: gomod2nix don't use the same golang version as project

Solution:
- build updateScript in nix expression.
- add workflow to check gomod2nix.toml up to date.

* tweag -> nix-community
  • Loading branch information
yihuang authored and tomtau committed Sep 23, 2022
1 parent 2e4e046 commit a8d5592
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 29 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,32 @@ jobs:
❌ `/runsim` simulation test has failed 😅
Can further check [here](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

gomod2nix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- id: changed-files
uses: tj-actions/[email protected]
with:
files: |
go.mod
go.sum
- uses: cachix/install-nix-action@v15
if: steps.changed-files.outputs.any_changed == 'true'
- name: update gomod2nix
run: nix run .#update-gomod2nix
if: steps.changed-files.outputs.any_changed == 'true'
- name: check working directory is clean
id: changes
run: |
set +e
(git diff --no-ext-diff --exit-code)
echo ::set-output name=changed::$?
- uses: actions/upload-artifact@v2
if: steps.changes.outputs.changed == 1
with:
name: gomod2nix.toml
path: ./gomod2nix.toml
- if: steps.changes.outputs.changed == 1
run: echo "Working directory is dirty" && exit 1
12 changes: 12 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
, buildGoApplication
, nix-gitignore
, go_1_18
, writeShellScript
, gomod2nix
, rocksdb ? null
, network ? "mainnet" # mainnet|testnet
, rev ? "dirty"
Expand Down Expand Up @@ -76,6 +78,16 @@ buildGoApplication rec {
find $instrumented/bin/ -type f 2>/dev/null | xargs -r remove-references-to -t ${go} || true
'';

passthru = {
# update script use the same golang version as the project
updateScript =
let helper = gomod2nix.override { inherit go; };
in
writeShellScript "${pname}-updater" ''
exec ${helper}/bin/gomod2nix
'';
};

meta = with lib; {
description = "Official implementation of the Crypto.org blockchain protocol";
homepage = "https://crypto.org/";
Expand Down
28 changes: 5 additions & 23 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
flake = false;
};
gomod2nix = {
url = "github:yihuang/gomod2nix";
url = "github:nix-community/gomod2nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.utils.follows = "flake-utils";
};
Expand Down Expand Up @@ -42,6 +42,10 @@
apps = {
chain-maind = mkApp packages.chain-maind;
chain-maind-testnet = mkApp packages.chain-maind-testnet;
update-gomod2nix = {
type = "app";
program = "${packages.chain-maind.updateScript}";
};
};
defaultPackage = packages.chain-maind;
defaultApp = apps.chain-maind;
Expand Down
1 change: 0 additions & 1 deletion integration_tests/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pkgs.mkShell {
buildInputs = with pkgs; [
# build tools
go_1_18
gomod2nix
rocksdb

# lint tools
Expand Down
8 changes: 4 additions & 4 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"branch": "master",
"description": "Convert applications using Go modules to Nix expressions",
"homepage": null,
"owner": "yihuang",
"owner": "nix-community",
"repo": "gomod2nix",
"rev": "2be74ae9177c9c897c3924a984cf8e85159832ce",
"sha256": "1rzc0dw0kcav0034y39qrwmvj9w127raq0x5rscz97mwcyjz3sp5",
"rev": "cc75990c60d01d9eedcf32ff4bf0055dd49c3ea1",
"sha256": "1s9m70q2jsr75hynx7q4brgbf22n1lfw5hc45mc3x4r9g4m8qrdz",
"type": "tarball",
"url": "https://github.com/yihuang/gomod2nix/archive/2be74ae9177c9c897c3924a984cf8e85159832ce.tar.gz",
"url": "https://github.com/nix-community/gomod2nix/archive/cc75990c60d01d9eedcf32ff4bf0055dd49c3ea1.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"ibc-rs": {
Expand Down

0 comments on commit a8d5592

Please sign in to comment.