You've already forked goreleaser
							
							
				mirror of
				https://github.com/goreleaser/goreleaser.git
				synced 2025-10-30 23:58:09 +02:00 
			
		
		
		
	feat(nix): extraInstall
This commit is contained in:
		| @@ -435,18 +435,29 @@ func installs(ctx *context.Context, nix config.Nix, art *artifact.Artifact) ([]s | ||||
| 	} | ||||
|  | ||||
| 	result := []string{"mkdir -p $out/bin"} | ||||
| 	binInstall := binInstallStr(nix) | ||||
| 	binInstallFormat := binInstallFormats(nix) | ||||
| 	for _, bin := range artifact.ExtraOr(*art, artifact.ExtraBinaries, []string{}) { | ||||
| 		result = append(result, fmt.Sprintf(binInstall, bin)) | ||||
| 		for _, format := range binInstallFormat { | ||||
| 			result = append(result, fmt.Sprintf(format, bin)) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	log.WithField("install", result).Warnf("guessing install") | ||||
|  | ||||
| 	applied, err = tmpl.New(ctx).WithArtifact(art).Apply(nix.ExtraInstall) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	if applied != "" { | ||||
| 		result = append(result, split(applied)...) | ||||
| 	} | ||||
| 	return result, nil | ||||
| } | ||||
|  | ||||
| func binInstallStr(nix config.Nix) string { | ||||
| func binInstallFormats(nix config.Nix) []string { | ||||
| 	formats := []string{"cp -vr ./%[1]s $out/bin/%[1]s"} | ||||
| 	if len(nix.Dependencies) == 0 { | ||||
| 		return "cp -vr ./%s $out/bin/%[1]s" | ||||
| 		return formats | ||||
| 	} | ||||
| 	var deps, linuxDeps, darwinDeps []string | ||||
|  | ||||
| @@ -474,7 +485,10 @@ func binInstallStr(nix config.Nix) string { | ||||
| 	} | ||||
|  | ||||
| 	depString := strings.Join(depStrings, " ++ ") | ||||
| 	return "wrapProgram $out/bin/%[1]s --prefix PATH : ${lib.makeBinPath (" + depString + ")}" | ||||
| 	return append( | ||||
| 		formats, | ||||
| 		"wrapProgram $out/bin/%[1]s --prefix PATH : ${lib.makeBinPath ("+depString+")}", | ||||
| 	) | ||||
| } | ||||
|  | ||||
| func split(s string) []string { | ||||
|   | ||||
| @@ -108,6 +108,22 @@ func TestRunPipe(t *testing.T) { | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 		{ | ||||
| 			name: "extra-install", | ||||
| 			nix: config.Nix{ | ||||
| 				Repository: config.RepoRef{ | ||||
| 					Owner: "foo", | ||||
| 					Name:  "bar", | ||||
| 				}, | ||||
| 				Dependencies: []config.NixDependency{ | ||||
| 					{Name: "fish"}, | ||||
| 					{Name: "bash"}, | ||||
| 					linuxDep("ttyd"), | ||||
| 					darwinDep("chromium"), | ||||
| 				}, | ||||
| 				ExtraInstall: "installManPage ./manpages/foo.1.gz", | ||||
| 			}, | ||||
| 		}, | ||||
| 		{ | ||||
| 			name: "open-pr", | ||||
| 			nix: config.Nix{ | ||||
| @@ -476,43 +492,58 @@ func TestDependencies(t *testing.T) { | ||||
| 	require.Equal(t, []string{"nix-prefetch-url"}, Pipe{}.Dependencies(nil)) | ||||
| } | ||||
|  | ||||
| func TestBinInstallStr(t *testing.T) { | ||||
| func TestBinInstallFormats(t *testing.T) { | ||||
| 	t.Run("no-deps", func(t *testing.T) { | ||||
| 		golden.RequireEqual(t, []byte(binInstallStr(config.Nix{}))) | ||||
| 		golden.RequireEqual(t, []byte(strings.Join( | ||||
| 			binInstallFormats(config.Nix{}), | ||||
| 			"\n", | ||||
| 		))) | ||||
| 	}) | ||||
| 	t.Run("deps", func(t *testing.T) { | ||||
| 		golden.RequireEqual(t, []byte(binInstallStr(config.Nix{ | ||||
| 			Dependencies: []config.NixDependency{ | ||||
| 				{Name: "fish"}, | ||||
| 				{Name: "bash"}, | ||||
| 				{Name: "zsh"}, | ||||
| 			}, | ||||
| 		}))) | ||||
| 		golden.RequireEqual(t, []byte(strings.Join( | ||||
| 			binInstallFormats(config.Nix{ | ||||
| 				Dependencies: []config.NixDependency{ | ||||
| 					{Name: "fish"}, | ||||
| 					{Name: "bash"}, | ||||
| 					{Name: "zsh"}, | ||||
| 				}, | ||||
| 			}), | ||||
| 			"\n", | ||||
| 		))) | ||||
| 	}) | ||||
| 	t.Run("linux-only-deps", func(t *testing.T) { | ||||
| 		golden.RequireEqual(t, []byte(binInstallStr(config.Nix{ | ||||
| 			Dependencies: []config.NixDependency{ | ||||
| 				linuxDep("foo"), | ||||
| 				linuxDep("bar"), | ||||
| 			}, | ||||
| 		}))) | ||||
| 		golden.RequireEqual(t, []byte(strings.Join( | ||||
| 			binInstallFormats(config.Nix{ | ||||
| 				Dependencies: []config.NixDependency{ | ||||
| 					linuxDep("foo"), | ||||
| 					linuxDep("bar"), | ||||
| 				}, | ||||
| 			}), | ||||
| 			"\n", | ||||
| 		))) | ||||
| 	}) | ||||
| 	t.Run("darwin-only-deps", func(t *testing.T) { | ||||
| 		golden.RequireEqual(t, []byte(binInstallStr(config.Nix{ | ||||
| 			Dependencies: []config.NixDependency{ | ||||
| 				darwinDep("foo"), | ||||
| 				darwinDep("bar"), | ||||
| 			}, | ||||
| 		}))) | ||||
| 		golden.RequireEqual(t, []byte(strings.Join( | ||||
| 			binInstallFormats(config.Nix{ | ||||
| 				Dependencies: []config.NixDependency{ | ||||
| 					darwinDep("foo"), | ||||
| 					darwinDep("bar"), | ||||
| 				}, | ||||
| 			}), | ||||
| 			"\n", | ||||
| 		))) | ||||
| 	}) | ||||
| 	t.Run("mixed-deps", func(t *testing.T) { | ||||
| 		golden.RequireEqual(t, []byte(binInstallStr(config.Nix{ | ||||
| 			Dependencies: []config.NixDependency{ | ||||
| 				{Name: "fish"}, | ||||
| 				linuxDep("foo"), | ||||
| 				darwinDep("bar"), | ||||
| 			}, | ||||
| 		}))) | ||||
| 		golden.RequireEqual(t, []byte(strings.Join( | ||||
| 			binInstallFormats(config.Nix{ | ||||
| 				Dependencies: []config.NixDependency{ | ||||
| 					{Name: "fish"}, | ||||
| 					linuxDep("foo"), | ||||
| 					darwinDep("bar"), | ||||
| 				}, | ||||
| 			}), | ||||
| 			"\n", | ||||
| 		))) | ||||
| 	}) | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -1 +1,2 @@ | ||||
| cp -vr ./%[1]s $out/bin/%[1]s | ||||
| wrapProgram $out/bin/%[1]s --prefix PATH : ${lib.makeBinPath (lib.optionals stdenv.isDarwin [ foo bar ])} | ||||
| @@ -1 +1,2 @@ | ||||
| cp -vr ./%[1]s $out/bin/%[1]s | ||||
| wrapProgram $out/bin/%[1]s --prefix PATH : ${lib.makeBinPath ([ fish bash zsh ])} | ||||
| @@ -1 +1,2 @@ | ||||
| cp -vr ./%[1]s $out/bin/%[1]s | ||||
| wrapProgram $out/bin/%[1]s --prefix PATH : ${lib.makeBinPath (lib.optionals stdenv.isLinux [ foo bar ])} | ||||
| @@ -1 +1,2 @@ | ||||
| cp -vr ./%[1]s $out/bin/%[1]s | ||||
| wrapProgram $out/bin/%[1]s --prefix PATH : ${lib.makeBinPath (lib.optionals stdenv.isDarwin [ bar ] ++ lib.optionals stdenv.isLinux [ foo ] ++ [ fish ])} | ||||
							
								
								
									
										1
									
								
								internal/pipe/nix/testdata/TestBinInstallFormats/no-deps.golden
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								internal/pipe/nix/testdata/TestBinInstallFormats/no-deps.golden
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| cp -vr ./%[1]s $out/bin/%[1]s | ||||
| @@ -1 +0,0 @@ | ||||
| cp -vr ./%s $out/bin/%[1]s | ||||
| @@ -47,6 +47,7 @@ in pkgs.stdenv.mkDerivation { | ||||
|  | ||||
|   installPhase = '' | ||||
|     mkdir -p $out/bin | ||||
|     cp -vr ./foo $out/bin/foo | ||||
|     wrapProgram $out/bin/foo --prefix PATH : ${lib.makeBinPath (lib.optionals stdenv.isDarwin [ chromium ] ++ lib.optionals stdenv.isLinux [ ttyd ] ++ [ fish bash ])} | ||||
|   ''; | ||||
|  | ||||
|   | ||||
| @@ -46,6 +46,7 @@ in pkgs.stdenv.mkDerivation { | ||||
|  | ||||
|   installPhase = '' | ||||
|     mkdir -p $out/bin | ||||
|     cp -vr ./foo $out/bin/foo | ||||
|     wrapProgram $out/bin/foo --prefix PATH : ${lib.makeBinPath (lib.optionals stdenv.isDarwin [ chromium ] ++ lib.optionals stdenv.isLinux [ ttyd ] ++ [ fish bash ])} | ||||
|   ''; | ||||
|  | ||||
|   | ||||
							
								
								
									
										69
									
								
								internal/pipe/nix/testdata/TestRunPipe/extra-install_build.nix.golden
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								internal/pipe/nix/testdata/TestRunPipe/extra-install_build.nix.golden
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,69 @@ | ||||
| # This file was generated by GoReleaser. DO NOT EDIT. | ||||
| # vim: set ft=nix ts=2 sw=2 sts=2 et sta | ||||
| { | ||||
|   system ? builtins.currentSystem | ||||
|   , pkgs | ||||
|   , lib | ||||
|   , fetchurl | ||||
|   , installShellFiles | ||||
|   , makeWrapper | ||||
|   , stdenv | ||||
|   , fish | ||||
|   , bash | ||||
|   , ttyd | ||||
|   , chromium | ||||
| }: | ||||
| let | ||||
|   shaMap = { | ||||
|     i686-linux = "0000000000000000000000000000000000000000000000000000"; | ||||
|     x86_64-linux = "0000000000000000000000000000000000000000000000000000"; | ||||
|     armv6l-linux = "0000000000000000000000000000000000000000000000000000"; | ||||
|     armv7l-linux = "0000000000000000000000000000000000000000000000000000"; | ||||
|     aarch64-linux = "0000000000000000000000000000000000000000000000000000"; | ||||
|     x86_64-darwin = "0000000000000000000000000000000000000000000000000000"; | ||||
|     aarch64-darwin = "0000000000000000000000000000000000000000000000000000"; | ||||
|   }; | ||||
|  | ||||
|   urlMap = { | ||||
|     i686-linux = "https://dummyhost/download/v1.2.1/foo_linux_386.tar.gz"; | ||||
|     x86_64-linux = "https://dummyhost/download/v1.2.1/foo_linux_amd64v1.tar.gz"; | ||||
|     armv6l-linux = "https://dummyhost/download/v1.2.1/foo_linux_arm6.tar.gz"; | ||||
|     armv7l-linux = "https://dummyhost/download/v1.2.1/foo_linux_arm7.tar.gz"; | ||||
|     aarch64-linux = "https://dummyhost/download/v1.2.1/foo_linux_arm64.tar.gz"; | ||||
|     x86_64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_amd64v1.tar.gz"; | ||||
|     aarch64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_arm64.tar.gz"; | ||||
|   }; | ||||
| in pkgs.stdenv.mkDerivation { | ||||
|   pname = "foo"; | ||||
|   version = "1.2.1"; | ||||
|   src = fetchurl { | ||||
|     url = urlMap.${system}; | ||||
|     sha256 = shaMap.${system}; | ||||
|   }; | ||||
|  | ||||
|   sourceRoot = "."; | ||||
|  | ||||
|   nativeBuildInputs = [ installShellFiles makeWrapper ]; | ||||
|  | ||||
|   installPhase = '' | ||||
|     mkdir -p $out/bin | ||||
|     cp -vr ./foo $out/bin/foo | ||||
|     wrapProgram $out/bin/foo --prefix PATH : ${lib.makeBinPath (lib.optionals stdenv.isDarwin [ chromium ] ++ lib.optionals stdenv.isLinux [ ttyd ] ++ [ fish bash ])} | ||||
|     installManPage ./manpages/foo.1.gz | ||||
|   ''; | ||||
|  | ||||
|   system = system; | ||||
|  | ||||
|   meta = with lib; { | ||||
|  | ||||
|     platforms = [ | ||||
|       "aarch64-darwin" | ||||
|       "aarch64-linux" | ||||
|       "armv6l-linux" | ||||
|       "armv7l-linux" | ||||
|       "i686-linux" | ||||
|       "x86_64-darwin" | ||||
|       "x86_64-linux" | ||||
|     ]; | ||||
|   }; | ||||
| } | ||||
							
								
								
									
										68
									
								
								internal/pipe/nix/testdata/TestRunPipe/extra-install_publish.nix.golden
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								internal/pipe/nix/testdata/TestRunPipe/extra-install_publish.nix.golden
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,68 @@ | ||||
| # This file was generated by GoReleaser. DO NOT EDIT. | ||||
| # vim: set ft=nix ts=2 sw=2 sts=2 et sta | ||||
| { | ||||
|   system ? builtins.currentSystem | ||||
|   , pkgs | ||||
|   , lib | ||||
|   , fetchurl | ||||
|   , installShellFiles | ||||
|   , makeWrapper | ||||
|   , stdenv | ||||
|   , fish | ||||
|   , bash | ||||
|   , ttyd | ||||
|   , chromium | ||||
| }: | ||||
| let | ||||
|   shaMap = { | ||||
|     x86_64-linux = "sha1"; | ||||
|     armv6l-linux = "sha6"; | ||||
|     armv7l-linux = "sha7"; | ||||
|     aarch64-linux = "sha2"; | ||||
|     x86_64-darwin = "sha3"; | ||||
|     aarch64-darwin = "sha4"; | ||||
|   }; | ||||
|  | ||||
|   urlMap = { | ||||
|     i686-linux = "https://dummyhost/download/v1.2.1/foo_linux_386.tar.gz"; | ||||
|     x86_64-linux = "https://dummyhost/download/v1.2.1/foo_linux_amd64v1.tar.gz"; | ||||
|     armv6l-linux = "https://dummyhost/download/v1.2.1/foo_linux_arm6.tar.gz"; | ||||
|     armv7l-linux = "https://dummyhost/download/v1.2.1/foo_linux_arm7.tar.gz"; | ||||
|     aarch64-linux = "https://dummyhost/download/v1.2.1/foo_linux_arm64.tar.gz"; | ||||
|     x86_64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_amd64v1.tar.gz"; | ||||
|     aarch64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_arm64.tar.gz"; | ||||
|   }; | ||||
| in pkgs.stdenv.mkDerivation { | ||||
|   pname = "foo"; | ||||
|   version = "1.2.1"; | ||||
|   src = fetchurl { | ||||
|     url = urlMap.${system}; | ||||
|     sha256 = shaMap.${system}; | ||||
|   }; | ||||
|  | ||||
|   sourceRoot = "."; | ||||
|  | ||||
|   nativeBuildInputs = [ installShellFiles makeWrapper ]; | ||||
|  | ||||
|   installPhase = '' | ||||
|     mkdir -p $out/bin | ||||
|     cp -vr ./foo $out/bin/foo | ||||
|     wrapProgram $out/bin/foo --prefix PATH : ${lib.makeBinPath (lib.optionals stdenv.isDarwin [ chromium ] ++ lib.optionals stdenv.isLinux [ ttyd ] ++ [ fish bash ])} | ||||
|     installManPage ./manpages/foo.1.gz | ||||
|   ''; | ||||
|  | ||||
|   system = system; | ||||
|  | ||||
|   meta = with lib; { | ||||
|  | ||||
|     platforms = [ | ||||
|       "aarch64-darwin" | ||||
|       "aarch64-linux" | ||||
|       "armv6l-linux" | ||||
|       "armv7l-linux" | ||||
|       "i686-linux" | ||||
|       "x86_64-darwin" | ||||
|       "x86_64-linux" | ||||
|     ]; | ||||
|   }; | ||||
| } | ||||
| @@ -255,6 +255,7 @@ type Nix struct { | ||||
| 	SkipUpload            string       `yaml:"skip_upload,omitempty" json:"skip_upload,omitempty" jsonschema:"oneof_type=string;boolean"` | ||||
| 	URLTemplate           string       `yaml:"url_template,omitempty" json:"url_template,omitempty"` | ||||
| 	Install               string       `yaml:"install,omitempty" json:"install,omitempty"` | ||||
| 	ExtraInstall          string       `yaml:"extra_install,omitempty" json:"extra_install,omitempty"` | ||||
| 	PostInstall           string       `yaml:"post_install,omitempty" json:"post_install,omitempty"` | ||||
| 	Description           string       `yaml:"description,omitempty" json:"description,omitempty"` | ||||
| 	Homepage              string       `yaml:"homepage,omitempty" json:"homepage,omitempty"` | ||||
|   | ||||
| @@ -87,11 +87,20 @@ nix: | ||||
|  | ||||
|     # Custom install script. | ||||
|     # | ||||
|     # Default: 'mkdir -p $out/bin; cp -vr $binary $out/bin/$binary' | ||||
|     # Default: 'mkdir -p $out/bin; cp -vr $binary $out/bin/$binary', and | ||||
|     #   `makeWrapper` if `dependencies` were provided. | ||||
|     # Templates: allowed | ||||
|     install: | | ||||
|       mkdir -p $out/bin | ||||
|       cp -vr ./foo $out/bin/foo | ||||
|  | ||||
|     # Custom additional install instructions. | ||||
|     # This has the advantage of preventing you to rewrite the `install` script | ||||
|     # if the defaults work for you. | ||||
|     # | ||||
|     # Since: v1.20 | ||||
|     # Templates: allowed | ||||
|     extra_install: | | ||||
|       installManPage ./manpages/foo.1.gz | ||||
|  | ||||
|     # Custom post_install script. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user