From 704aa9566a4bc7394ea9cb3dab89a2fdf7512f88 Mon Sep 17 00:00:00 2001 From: adisbladis Date: Wed, 24 Aug 2022 11:49:11 +0800 Subject: [PATCH 1/3] Add buildGoApplication and mkGoEnv parameters to gomod2nix expression This is so nixpkgs can inject it from another location. --- generic.nix | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/generic.nix b/generic.nix index 92de832..ca3f547 100644 --- a/generic.nix +++ b/generic.nix @@ -9,13 +9,11 @@ , makeWrapper , installShellFiles , fetchFromGitHub +, buildGoApplication ? (callPackage ./builder { }).buildGoApplication +, mkGoEnv ? (callPackage ./builder { }).buildGoApplication }: -let - builder = callPackage ./builder { }; - -in -builder.buildGoApplication { +buildGoApplication { pname = "gomod2nix"; inherit version modules src go; @@ -25,7 +23,9 @@ builder.buildGoApplication { nativeBuildInputs = [ makeWrapper installShellFiles ]; - passthru = builder; + passthru = { + inherit buildGoApplication mkGoEnv; + }; postInstall = lib.optionalString (stdenv.buildPlatform == stdenv.targetPlatform) '' $out/bin/gomod2nix completion bash > gomod2nix.bash From 055777bf88154469b16238f52136b33388f29311 Mon Sep 17 00:00:00 2001 From: adisbladis Date: Wed, 24 Aug 2022 11:50:44 +0800 Subject: [PATCH 2/3] Generate shell completions using process substitution Practically this makes no difference but it's slightly more elegant. --- generic.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/generic.nix b/generic.nix index ca3f547..1af764b 100644 --- a/generic.nix +++ b/generic.nix @@ -28,10 +28,10 @@ buildGoApplication { }; postInstall = lib.optionalString (stdenv.buildPlatform == stdenv.targetPlatform) '' - $out/bin/gomod2nix completion bash > gomod2nix.bash - $out/bin/gomod2nix completion fish > gomod2nix.fish - $out/bin/gomod2nix completion zsh > _gomod2nix - installShellCompletion gomod2nix.{bash,fish} _gomod2nix + installShellCompletion --cmd gomod2nix \ + --bash <($out/bin/gomod2nix completion bash) \ + --fish <($out/bin/gomod2nix completion fish) \ + --zsh <($out/bin/gomod2nix completion zsh) '' + '' wrapProgram $out/bin/gomod2nix --prefix PATH : ${lib.makeBinPath [ go ]} ''; From 5149c67e6e8150c6beed511181e30d54b2057e72 Mon Sep 17 00:00:00 2001 From: adisbladis Date: Wed, 24 Aug 2022 11:56:19 +0800 Subject: [PATCH 3/3] Enable Cgo by default To be in line with the behaviour of buildGoModule since https://github.com/NixOS/nixpkgs/pull/177594. --- builder/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/builder/default.nix b/builder/default.nix index 90ef1d0..7ce54a3 100644 --- a/builder/default.nix +++ b/builder/default.nix @@ -172,6 +172,8 @@ let dontConfigure = true; dontInstall = true; + CGO_ENABLED = attrs.CGO_ENABLED or go.CGO_ENABLED; + propagatedBuildInputs = [ go ]; GO_NO_VENDOR_CHECKS = "1"; @@ -253,6 +255,7 @@ let inherit (go) GOOS GOARCH; GO_NO_VENDOR_CHECKS = "1"; + CGO_ENABLED = attrs.CGO_ENABLED or go.CGO_ENABLED; GO111MODULE = "on"; GOFLAGS = [ "-mod=vendor" ] ++ lib.optionals (!allowGoReference) [ "-trimpath" ];