Skip to content

Commit

Permalink
switch to gomod2nix
Browse files Browse the repository at this point in the history
This hopefully merges better and is faster to compute
  • Loading branch information
Mic92 authored and mergify[bot] committed Sep 12, 2023
1 parent 4e74337 commit 6a51c12
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 259 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ jobs:
- uses: cachix/install-nix-action@v23

- name: Build
run: nix-build
run: nix build

# Run the more comprehensive test suite with nix because we have
# access to all the build dependencies.
- name: Test
run: NIX_PATH=nixpkgs=$PWD/nix nix-shell --pure --run "make test"
run: nix develop --ignore-environment -c make test

# Test that the release generation works
- name: Test Dist
run: NIX_PATH=nixpkgs=$PWD/nix nix-shell --pure --run "make dist"
run: nix develop --ignore-environment -c make dist
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Update vendorHash
name: Update gomod2nix
on: pull_request

permissions:
Expand All @@ -20,12 +20,12 @@ jobs:
nix_path: nixpkgs=channel:nixos-unstable
- name: Update checksum
run: |
./script/update-vendor-hash
./script/update-gomod2nix
# git push if we have a diff
if [[ -n $(git diff) ]]; then
git add default.nix
git config --global user.email "<49699333+dependabot[bot]@users.noreply.github.com>"
git config --global user.name "dependabot[bot]"
git commit -m "update vendorHash"
git commit -m "update gomod2nix"
git push origin HEAD:${{ github.head_ref }}
fi
24 changes: 9 additions & 15 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
{ pkgs ? import ./nix { }, vendorHash ? "sha256-UsdVGKIoiI3nJgbIdSg+BIDInoUODFjfyvoTdxg2a8Q=" }:
let
inherit (pkgs)
bash
buildGoModule
lib
stdenv
;
in
buildGoModule rec {
name = "direnv-${version}";
{ buildGoApplication, lib, stdenv, bash }:
buildGoApplication {
pname = "direnv";
version = lib.fileContents ./version.txt;
subPackages = [ "." ];

inherit vendorHash;

src = builtins.fetchGit ./.;
src = ./.;
pwd = ./.;
modules = ./gomod2nix.toml;

# we have no bash at the moment for windows
BASH_PATH =
lib.optionalString (!stdenv.hostPlatform.isWindows)
"${bash}/bin/bash";
"${bash}/bin/bash";

# replace the build phase to use the GNUMakefile instead
buildPhase = ''
ls -la ./vendor
make BASH_PATH=$BASH_PATH
'';

installPhase = ''
echo $GOCACHE
make install PREFIX=$out
'';

Expand Down
85 changes: 85 additions & 0 deletions flake.lock

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

33 changes: 33 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
description = "A basic gomod2nix flake";

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.gomod2nix.url = "github:nix-community/gomod2nix";
inputs.gomod2nix.inputs.nixpkgs.follows = "nixpkgs";
inputs.gomod2nix.inputs.utils.follows = "flake-utils";

outputs = { self, nixpkgs, flake-utils, gomod2nix }:
(flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
callPackage = pkgs.darwin.apple_sdk_11_0.callPackage or pkgs.callPackage;

gomod2nixBuilder = callPackage "${gomod2nix}/builder" {
gomod2nix = gomod2nix';
};
gomod2nix' = callPackage "${gomod2nix}/default.nix" {
inherit (gomod2nixBuilder) mkGoEnv buildGoApplication;
};
in
{
packages.default = callPackage ./. {
inherit (gomod2nixBuilder) buildGoApplication;
};
devShells.default = callPackage ./shell.nix {
inherit (gomod2nixBuilder) mkGoEnv;
gomod2nix = gomod2nix';
};
}));
}
39 changes: 39 additions & 0 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
schema = 3

[mod]
[mod."github.com/BurntSushi/toml"]
version = "v1.3.2"
hash = "sha256-FIwyH67KryRWI9Bk4R8s1zFP0IgKR4L66wNQJYQZLeg="
[mod."github.com/mattn/go-isatty"]
version = "v0.0.14"
hash = "sha256-e8zn5eCVh/B1HOP1PGXeXH0bGkIV0vKYP9KLwZni5as="
[mod."github.com/yuin/goldmark"]
version = "v1.4.13"
hash = "sha256-GVwFKZY6moIS6I0ZGuio/WtDif+lkZRfqWS6b4AAJyI="
[mod."golang.org/x/crypto"]
version = "v0.0.0-20210921155107-089bfa567519"
hash = "sha256-62Qtoqu7AxoxpZFd+75qXC0naixAct3rWsJd0nSgMCU="
[mod."golang.org/x/mod"]
version = "v0.12.0"
hash = "sha256-M/oXnzm7odpJdQzEnG6W0pNYtl0uhOM/l7qgfGVpU2M="
[mod."golang.org/x/net"]
version = "v0.0.0-20220722155237-a158d28d115b"
hash = "sha256-TccMT2GgC1qKp8Yxk1zShJVvr29GemCqKSNJeYkjLo4="
[mod."golang.org/x/sync"]
version = "v0.0.0-20220722155255-886fb9371eb4"
hash = "sha256-ZZyIlxh+nqsOiWHstW7eHXN7RhHnbSL2eDIzcve07Q0="
[mod."golang.org/x/sys"]
version = "v0.0.0-20220722155257-8c9f86f7a55f"
hash = "sha256-mXgFTb2vfUEjTPA6PX7CZTvKGJWaxoU2QplyI1GjC+w="
[mod."golang.org/x/term"]
version = "v0.0.0-20210927222741-03fcf44c2211"
hash = "sha256-DsX2xay7Y/0/bikp4vU8ArF0B6KHyqEc37PwgvmjhSs="
[mod."golang.org/x/text"]
version = "v0.3.7"
hash = "sha256-XH2pUzzQx95O0rak00grQvfACfL+EmZiV7ZzJBkX+XY="
[mod."golang.org/x/tools"]
version = "v0.1.12"
hash = "sha256-D0kGneGMt+LFbdUDo9Axd0yB0a5t3Z0YKVAnJDDaBo8="
[mod."golang.org/x/xerrors"]
version = "v0.0.0-20190717185122-a985d3407aa7"
hash = "sha256-kj2qs47n+a4gtKXHJN3U9gcSQ3BozjzYu7EphXjJnwM="
5 changes: 0 additions & 5 deletions nix/default.nix

This file was deleted.

15 changes: 0 additions & 15 deletions nix/sources.json

This file was deleted.

Loading

0 comments on commit 6a51c12

Please sign in to comment.