Skip to content

Commit

Permalink
Remove gomod2nix and update Go build configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Baillie <[email protected]>
  • Loading branch information
martinbaillie committed Jan 18, 2025
1 parent 1c11fa8 commit f55e704
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 352 deletions.
4 changes: 3 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
report_sizes: false

builds:
- goos:
- env:
- CGO_ENABLED=0
goos:
- darwin
- windows
- linux
Expand Down
55 changes: 0 additions & 55 deletions flake.lock

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

26 changes: 6 additions & 20 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
inputs.nixpkgs.follows = "nixpkgs";
};

gomod2nix = {
url = "github:nix-community/gomod2nix";
inputs.nixpkgs.follows = "nixpkgs";
};

gitignore = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
Expand All @@ -27,7 +22,6 @@
nixpkgs,
flake-parts,
devshell,
gomod2nix,
gitignore,
...
}:
Expand All @@ -52,33 +46,27 @@
rev = self.rev or "dirty";
ver = if self ? "dirtyRev" then self.dirtyShortRev else self.shortRev;
date = self.lastModifiedDate or "19700101";
go = pkgs.go_1_22;
in
{
_module.args.pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true; # BSL2... Hashicorp...
overlays = [
devshell.overlays.default
gomod2nix.overlays.default
];
};

packages.default = gomod2nix.legacyPackages.${system}.buildGoApplication {
inherit name go;
packages.default = pkgs.buildGo123Module {
inherit name;
src = gitignore.lib.gitignoreSource ./.;
# Must be added due to bug:
# https://github.com/nix-community/gomod2nix/issues/120
pwd = ./.;
modules = ./gomod2nix.toml;
env.CGO_ENABLED = 0;
vendorHash = "sha256-hscwOZhaVL17HPUGfs8uYSQt80D4HK4W6kNdkSmsQdA=";
flags = [ "-trimpath" ];
# CGO_ENABLED = 0;
ldflags = [
"-s"
"-w"
"-extld ld"
"-extldflags"
"-static"
"-extldflags -static"
"-X ${package}/github.projectName=${name}"
"-X ${package}/github.projectDocs=https://${package}"
"-X github.com/prometheus/common/version.BuildDate=${date}"
Expand All @@ -88,7 +76,6 @@
"-X github.com/prometheus/common/version.Branch=main"
"-X github.com/prometheus/common/version.BuildUser=nix"
];
doCheck = false;
};

devShells.default = pkgs.devshell.mkShell rec {
Expand All @@ -112,7 +99,6 @@
gnugrep
go
golangci-lint
gomod2nix.legacyPackages.${system}.gomod2nix
goreleaser
syft
vault-bin
Expand Down Expand Up @@ -161,7 +147,7 @@
prjRoot
+ ''
echo >&2 "==> Tidying modules"
go mod tidy && gomod2nix
go mod tidy
'';
help = "clean transient files";
}
Expand Down
Loading

0 comments on commit f55e704

Please sign in to comment.