From a93d66c9d50b33959fac7e37b030f283efb32681 Mon Sep 17 00:00:00 2001 From: wxt <3264117476@qq.com> Date: Sun, 29 Sep 2024 17:00:10 +0800 Subject: [PATCH 1/2] garble: move to by-name; nixfmt --- .../default.nix => by-name/ga/garble/package.nix} | 13 +++++++------ pkgs/top-level/all-packages.nix | 2 -- 2 files changed, 7 insertions(+), 8 deletions(-) rename pkgs/{development/tools/garble/default.nix => by-name/ga/garble/package.nix} (90%) diff --git a/pkgs/development/tools/garble/default.nix b/pkgs/by-name/ga/garble/package.nix similarity index 90% rename from pkgs/development/tools/garble/default.nix rename to pkgs/by-name/ga/garble/package.nix index 0735e283d6db2..c469c0e01caf5 100644 --- a/pkgs/development/tools/garble/default.nix +++ b/pkgs/by-name/ga/garble/package.nix @@ -1,8 +1,9 @@ -{ stdenv -, buildGoModule -, fetchFromGitHub -, lib -, git +{ + stdenv, + buildGoModule, + fetchFromGitHub, + lib, + git, }: buildGoModule rec { pname = "garble"; @@ -18,7 +19,7 @@ buildGoModule rec { vendorHash = "sha256-SOdIlu0QrQokl9j9Ff594+1K6twU1mCuECFQaVKaPV4="; # Used for some of the tests. - nativeCheckInputs = [git]; + nativeCheckInputs = [ git ]; preBuild = lib.optionalString (!stdenv.hostPlatform.isx86_64) '' # The test assumex amd64 assembly diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 0f17b22d30239..fcc1a43d90763 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -19450,8 +19450,6 @@ with pkgs; ganv = callPackage ../development/libraries/ganv { }; - garble = callPackage ../development/tools/garble { }; - gcab = callPackage ../development/libraries/gcab { }; gcovr = with python3Packages; toPythonApplication gcovr; From a5b0e0634daab3bb60ae221e4793bb8c5f093af8 Mon Sep 17 00:00:00 2001 From: wxt <3264117476@qq.com> Date: Sun, 29 Sep 2024 17:06:23 +0800 Subject: [PATCH 2/2] garble: add passthru.updateScript; 0.8.0 -> 0.13.0; add bot-wxt1221 as maintainers --- .../ga/garble/0001-Add-version-info.patch | 38 +++++++++++ pkgs/by-name/ga/garble/package.nix | 65 +++++++++++++++---- 2 files changed, 91 insertions(+), 12 deletions(-) create mode 100644 pkgs/by-name/ga/garble/0001-Add-version-info.patch diff --git a/pkgs/by-name/ga/garble/0001-Add-version-info.patch b/pkgs/by-name/ga/garble/0001-Add-version-info.patch new file mode 100644 index 0000000000000..153ab8f4bf6d6 --- /dev/null +++ b/pkgs/by-name/ga/garble/0001-Add-version-info.patch @@ -0,0 +1,38 @@ +From e46a41faac008ede4acbeb18db5b3076eb206de5 Mon Sep 17 00:00:00 2001 +From: wxt <3264117476@qq.com> +Date: Sun, 3 Nov 2024 15:11:49 +0800 +Subject: [PATCH] Add version info + +--- + main.go | 1 + + testdata/script/help.txtar | 2 +- + 2 files changed, 2 insertions(+), 1 deletion(-) + +diff --git a/main.go b/main.go +index 0de5a2f..1c830b1 100644 +--- a/main.go ++++ b/main.go +@@ -362,6 +362,7 @@ func mainErr(args []string) error { + // manually construct something like a pseudo-version. + // TODO: remove when this code is dead, hopefully in Go 1.22. + if mod.Version == "(devel)" { ++ mod.Version = "@version@" + var vcsTime time.Time + var vcsRevision string + for _, setting := range info.Settings { +diff --git a/testdata/script/help.txtar b/testdata/script/help.txtar +index 8f25260..859f492 100644 +--- a/testdata/script/help.txtar ++++ b/testdata/script/help.txtar +@@ -91,7 +91,7 @@ stderr 'directory not found' + # and to be able to use static VCS info, use an environment variable. + # First, test without the information, and then with it. + exec garble version +-stdout -count=1 'mvdan.cc/garble \(devel\)' ++stdout -count=1 'mvdan.cc/garble @version@' + stdout -count=1 'Build settings' + stdout -count=3 '-compiler|GOOS|GOARCH' + ! stdout 'vcs' +-- +2.46.1 + diff --git a/pkgs/by-name/ga/garble/package.nix b/pkgs/by-name/ga/garble/package.nix index c469c0e01caf5..a9f2c711cb663 100644 --- a/pkgs/by-name/ga/garble/package.nix +++ b/pkgs/by-name/ga/garble/package.nix @@ -1,36 +1,77 @@ { + lib, stdenv, buildGoModule, fetchFromGitHub, - lib, + diffoscope, git, + versionCheckHook, + replaceVars, + nix-update-script, }: + buildGoModule rec { pname = "garble"; - version = "0.8.0"; + version = "0.13.0"; src = fetchFromGitHub { owner = "burrowers"; - repo = pname; - rev = "v${version}"; - sha256 = "sha256-f7coWG1CS4UL8GGqwADx5CvIk2sPONPlWW+JgRhFsb8="; + repo = "garble"; + rev = "refs/tags/v${version}"; + hash = "sha256-FtI5lAeqjRPN47iC46bcEsRLQb7mItw4svsnLkRpNxY="; }; - vendorHash = "sha256-SOdIlu0QrQokl9j9Ff594+1K6twU1mCuECFQaVKaPV4="; + __darwinAllowLocalNetworking = true; + + ldflags = [ + "-buildid=00000000000000000000" # length=20 + ]; + + patches = [ + (replaceVars ./0001-Add-version-info.patch { + inherit version; + }) + ]; + + checkFlags = [ + "-skip" + "TestScript/gogarble" + ]; + + vendorHash = "sha256-mSdajYiMEg2ik0ocfmHK+XddEss1qLu6rDwzjocaaW0="; # Used for some of the tests. - nativeCheckInputs = [ git ]; + nativeCheckInputs = [ + diffoscope + git + versionCheckHook + ]; - preBuild = lib.optionalString (!stdenv.hostPlatform.isx86_64) '' - # The test assumex amd64 assembly - rm testdata/script/asm.txtar + preCheck = '' + export HOME=$(mktemp -d) + export WORK=$(mktemp -d) ''; + # Several tests fail with + # FAIL: testdata/script/goenv.txtar:27: "$WORK/.temp 'quotes' and spaces" matches "garble|importcfg|cache\\.gob|\\.go" + doCheck = !stdenv.hostPlatform.isDarwin; + + nativeInstallCheckInputs = [ + versionCheckHook + ]; + versionCheckProgramArg = [ "version" ]; + doInstallCheck = false; + + passthru.updateScript = nix-update-script { }; + meta = { description = "Obfuscate Go code by wrapping the Go toolchain"; homepage = "https://github.com/burrowers/garble/"; - maintainers = with lib.maintainers; [ davhau ]; + maintainers = with lib.maintainers; [ + davhau + bot-wxt1221 + ]; license = lib.licenses.bsd3; - broken = stdenv.hostPlatform.isDarwin; # never built on Hydra https://hydra.nixos.org/job/nixpkgs/trunk/garble.x86_64-darwin + mainProgram = "garble"; }; }