From e672699b0a9c63ca439a254eb63db6dac28c2f21 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 26 Jul 2023 12:38:53 +0000 Subject: [PATCH] feat(nix): runtime dependencies Signed-off-by: Carlos Alexandro Becker --- internal/pipe/nix/nix.go | 72 ++++++++++++++++--- internal/pipe/nix/nix_test.go | 69 ++++++++++++++++++ internal/pipe/nix/template.go | 22 +++--- .../TestBinInstallStr/darwin-only-deps.golden | 1 + .../testdata/TestBinInstallStr/deps.golden | 1 + .../TestBinInstallStr/linux-only-deps.golden | 1 + .../TestBinInstallStr/mixed-deps.golden | 1 + .../testdata/TestBinInstallStr/no-deps.golden | 1 + .../TestRunPipe/deps_build.nix.golden | 67 +++++++++++++++++ .../TestRunPipe/deps_publish.nix.golden | 66 +++++++++++++++++ .../TestRunPipe/minimal_build.nix.golden | 8 ++- .../TestRunPipe/minimal_publish.nix.golden | 8 ++- .../TestRunPipe/open-pr_build.nix.golden | 8 ++- .../TestRunPipe/open-pr_publish.nix.golden | 8 ++- .../TestRunPipe/partial_build.nix.golden | 8 ++- .../TestRunPipe/partial_publish.nix.golden | 8 ++- .../skip-upload-auto_build.nix.golden | 8 ++- .../TestRunPipe/skip-upload_build.nix.golden | 8 ++- .../unibin-replaces_build.nix.golden | 8 ++- .../unibin-replaces_publish.nix.golden | 8 ++- .../TestRunPipe/unibin_build.nix.golden | 8 ++- .../TestRunPipe/unibin_publish.nix.golden | 8 ++- .../wrapped-in-dir_build.nix.golden | 8 ++- .../wrapped-in-dir_publish.nix.golden | 8 ++- internal/pipe/nix/tmpl.nix | 17 ++++- pkg/config/config.go | 42 +++++++++++ www/docs/customization/nix.md | 11 +++ www/docs/static/schema.json | 34 +++++++++ 28 files changed, 480 insertions(+), 37 deletions(-) create mode 100644 internal/pipe/nix/testdata/TestBinInstallStr/darwin-only-deps.golden create mode 100644 internal/pipe/nix/testdata/TestBinInstallStr/deps.golden create mode 100644 internal/pipe/nix/testdata/TestBinInstallStr/linux-only-deps.golden create mode 100644 internal/pipe/nix/testdata/TestBinInstallStr/mixed-deps.golden create mode 100644 internal/pipe/nix/testdata/TestBinInstallStr/no-deps.golden create mode 100644 internal/pipe/nix/testdata/TestRunPipe/deps_build.nix.golden create mode 100644 internal/pipe/nix/testdata/TestRunPipe/deps_publish.nix.golden diff --git a/internal/pipe/nix/nix.go b/internal/pipe/nix/nix.go index 31d86f5cf..53161d538 100644 --- a/internal/pipe/nix/nix.go +++ b/internal/pipe/nix/nix.go @@ -247,17 +247,25 @@ func preparePkg( folder = "." } - data := templateData{ - Name: nix.Name, - Version: ctx.Version, - Install: installs, - PostInstall: postInstall, - Archives: map[string]Archive{}, - SourceRoot: folder, - Description: nix.Description, - Homepage: nix.Homepage, - License: nix.License, + inputs := []string{"installShellFiles"} + if len(nix.Dependencies) > 0 { + inputs = append(inputs, "makeWrapper") } + + data := templateData{ + Name: nix.Name, + Version: ctx.Version, + Install: installs, + PostInstall: postInstall, + Archives: map[string]Archive{}, + SourceRoot: folder, + Description: nix.Description, + Homepage: nix.Homepage, + License: nix.License, + Inputs: inputs, + Dependencies: depNames(nix.Dependencies), + } + platforms := map[string]bool{} for _, art := range archives { url, err := tmpl.New(ctx).WithArtifact(art).Apply(nix.URLTemplate) @@ -427,14 +435,48 @@ func installs(ctx *context.Context, nix config.Nix, art *artifact.Artifact) ([]s } result := []string{"mkdir -p $out/bin"} + binInstall := binInstallStr(nix) for _, bin := range artifact.ExtraOr(*art, artifact.ExtraBinaries, []string{}) { - result = append(result, fmt.Sprintf("cp -vr ./%s $out/bin/%[1]s", bin)) + result = append(result, fmt.Sprintf(binInstall, bin)) } log.WithField("install", result).Warnf("guessing install") return result, nil } +func binInstallStr(nix config.Nix) string { + if len(nix.Dependencies) == 0 { + return "cp -vr ./%s $out/bin/%[1]s" + } + var deps, linuxDeps, darwinDeps []string + + for _, dep := range nix.Dependencies { + switch dep.OS { + case "darwin": + darwinDeps = append(darwinDeps, dep.Name) + case "linux": + linuxDeps = append(linuxDeps, dep.Name) + default: + deps = append(deps, dep.Name) + } + } + + var depStrings []string + + if len(darwinDeps) > 0 { + depStrings = append(depStrings, fmt.Sprintf("lib.optionals stdenv.isDarwin [ %s ]", strings.Join(darwinDeps, " "))) + } + if len(linuxDeps) > 0 { + depStrings = append(depStrings, fmt.Sprintf("lib.optionals stdenv.isLinux [ %s ]", strings.Join(linuxDeps, " "))) + } + if len(deps) > 0 { + depStrings = append(depStrings, fmt.Sprintf("[ %s ]", strings.Join(deps, " "))) + } + + depString := strings.Join(depStrings, " ++ ") + return "wrapProgram $out/bin/%[1]s --prefix PATH : ${lib.makeBinPath (" + depString + ")}" +} + func split(s string) []string { var result []string for _, line := range strings.Split(strings.TrimSpace(s), "\n") { @@ -447,6 +489,14 @@ func split(s string) []string { return result } +func depNames(deps []config.NixDependency) []string { + var result []string + for _, dep := range deps { + result = append(result, dep.Name) + } + return result +} + type shaPrefetcher interface { Prefetch(url string) (string, error) Available() bool diff --git a/internal/pipe/nix/nix_test.go b/internal/pipe/nix/nix_test.go index efd7d1c57..4233f3322 100644 --- a/internal/pipe/nix/nix_test.go +++ b/internal/pipe/nix/nix_test.go @@ -93,6 +93,21 @@ func TestRunPipe(t *testing.T) { }, }, }, + { + name: "deps", + nix: config.Nix{ + Repository: config.RepoRef{ + Owner: "foo", + Name: "bar", + }, + Dependencies: []config.NixDependency{ + {Name: "fish"}, + {Name: "bash"}, + linuxDep("ttyd"), + darwinDep("chromium"), + }, + }, + }, { name: "open-pr", nix: config.Nix{ @@ -461,6 +476,60 @@ func TestDependencies(t *testing.T) { require.Equal(t, []string{"nix-prefetch-url"}, Pipe{}.Dependencies(nil)) } +func TestBinInstallStr(t *testing.T) { + t.Run("no-deps", func(t *testing.T) { + golden.RequireEqual(t, []byte(binInstallStr(config.Nix{}))) + }) + t.Run("deps", func(t *testing.T) { + golden.RequireEqual(t, []byte(binInstallStr(config.Nix{ + Dependencies: []config.NixDependency{ + {Name: "fish"}, + {Name: "bash"}, + {Name: "zsh"}, + }, + }))) + }) + t.Run("linux-only-deps", func(t *testing.T) { + golden.RequireEqual(t, []byte(binInstallStr(config.Nix{ + Dependencies: []config.NixDependency{ + linuxDep("foo"), + linuxDep("bar"), + }, + }))) + }) + t.Run("darwin-only-deps", func(t *testing.T) { + golden.RequireEqual(t, []byte(binInstallStr(config.Nix{ + Dependencies: []config.NixDependency{ + darwinDep("foo"), + darwinDep("bar"), + }, + }))) + }) + t.Run("mixed-deps", func(t *testing.T) { + golden.RequireEqual(t, []byte(binInstallStr(config.Nix{ + Dependencies: []config.NixDependency{ + {Name: "fish"}, + linuxDep("foo"), + darwinDep("bar"), + }, + }))) + }) +} + +func darwinDep(s string) config.NixDependency { + return config.NixDependency{ + Name: s, + OS: "darwin", + } +} + +func linuxDep(s string) config.NixDependency { + return config.NixDependency{ + Name: s, + OS: "linux", + } +} + type fakeNixShaPrefetcher map[string]string func (m fakeNixShaPrefetcher) Prefetch(url string) (string, error) { diff --git a/internal/pipe/nix/template.go b/internal/pipe/nix/template.go index 49422f7ef..a87aff41b 100644 --- a/internal/pipe/nix/template.go +++ b/internal/pipe/nix/template.go @@ -10,14 +10,16 @@ type Archive struct { } type templateData struct { - Name string - Version string - Install []string - PostInstall []string - SourceRoot string - Archives map[string]Archive - Description string - Homepage string - License string - Platforms []string + Name string + Version string + Install []string + PostInstall []string + SourceRoot string + Archives map[string]Archive + Description string + Homepage string + License string + Platforms []string + Inputs []string + Dependencies []string } diff --git a/internal/pipe/nix/testdata/TestBinInstallStr/darwin-only-deps.golden b/internal/pipe/nix/testdata/TestBinInstallStr/darwin-only-deps.golden new file mode 100644 index 000000000..b8df80a85 --- /dev/null +++ b/internal/pipe/nix/testdata/TestBinInstallStr/darwin-only-deps.golden @@ -0,0 +1 @@ +wrapProgram $out/bin/%[1]s --prefix PATH : ${lib.makeBinPath (lib.optionals stdenv.isDarwin [ foo bar ])} \ No newline at end of file diff --git a/internal/pipe/nix/testdata/TestBinInstallStr/deps.golden b/internal/pipe/nix/testdata/TestBinInstallStr/deps.golden new file mode 100644 index 000000000..b7c4903c6 --- /dev/null +++ b/internal/pipe/nix/testdata/TestBinInstallStr/deps.golden @@ -0,0 +1 @@ +wrapProgram $out/bin/%[1]s --prefix PATH : ${lib.makeBinPath ([ fish bash zsh ])} \ No newline at end of file diff --git a/internal/pipe/nix/testdata/TestBinInstallStr/linux-only-deps.golden b/internal/pipe/nix/testdata/TestBinInstallStr/linux-only-deps.golden new file mode 100644 index 000000000..cfbf29168 --- /dev/null +++ b/internal/pipe/nix/testdata/TestBinInstallStr/linux-only-deps.golden @@ -0,0 +1 @@ +wrapProgram $out/bin/%[1]s --prefix PATH : ${lib.makeBinPath (lib.optionals stdenv.isLinux [ foo bar ])} \ No newline at end of file diff --git a/internal/pipe/nix/testdata/TestBinInstallStr/mixed-deps.golden b/internal/pipe/nix/testdata/TestBinInstallStr/mixed-deps.golden new file mode 100644 index 000000000..a05638e5f --- /dev/null +++ b/internal/pipe/nix/testdata/TestBinInstallStr/mixed-deps.golden @@ -0,0 +1 @@ +wrapProgram $out/bin/%[1]s --prefix PATH : ${lib.makeBinPath (lib.optionals stdenv.isDarwin [ bar ] ++ lib.optionals stdenv.isLinux [ foo ] ++ [ fish ])} \ No newline at end of file diff --git a/internal/pipe/nix/testdata/TestBinInstallStr/no-deps.golden b/internal/pipe/nix/testdata/TestBinInstallStr/no-deps.golden new file mode 100644 index 000000000..b8f7e962b --- /dev/null +++ b/internal/pipe/nix/testdata/TestBinInstallStr/no-deps.golden @@ -0,0 +1 @@ +cp -vr ./%s $out/bin/%[1]s \ No newline at end of file diff --git a/internal/pipe/nix/testdata/TestRunPipe/deps_build.nix.golden b/internal/pipe/nix/testdata/TestRunPipe/deps_build.nix.golden new file mode 100644 index 000000000..bb5e318c1 --- /dev/null +++ b/internal/pipe/nix/testdata/TestRunPipe/deps_build.nix.golden @@ -0,0 +1,67 @@ +# 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 + wrapProgram $out/bin/foo --prefix PATH : ${lib.makeBinPath (lib.optionals stdenv.isDarwin [ chromium ] ++ lib.optionals stdenv.isLinux [ ttyd ] ++ [ fish bash ])} + ''; + + system = system; + + meta = with lib; { + + platforms = [ + "aarch64-darwin" + "aarch64-linux" + "armv6l-linux" + "armv7l-linux" + "i686-linux" + "x86_64-darwin" + "x86_64-linux" + ]; + }; +} diff --git a/internal/pipe/nix/testdata/TestRunPipe/deps_publish.nix.golden b/internal/pipe/nix/testdata/TestRunPipe/deps_publish.nix.golden new file mode 100644 index 000000000..761e906d0 --- /dev/null +++ b/internal/pipe/nix/testdata/TestRunPipe/deps_publish.nix.golden @@ -0,0 +1,66 @@ +# 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 + wrapProgram $out/bin/foo --prefix PATH : ${lib.makeBinPath (lib.optionals stdenv.isDarwin [ chromium ] ++ lib.optionals stdenv.isLinux [ ttyd ] ++ [ fish bash ])} + ''; + + system = system; + + meta = with lib; { + + platforms = [ + "aarch64-darwin" + "aarch64-linux" + "armv6l-linux" + "armv7l-linux" + "i686-linux" + "x86_64-darwin" + "x86_64-linux" + ]; + }; +} diff --git a/internal/pipe/nix/testdata/TestRunPipe/minimal_build.nix.golden b/internal/pipe/nix/testdata/TestRunPipe/minimal_build.nix.golden index 480af191a..62beff24f 100644 --- a/internal/pipe/nix/testdata/TestRunPipe/minimal_build.nix.golden +++ b/internal/pipe/nix/testdata/TestRunPipe/minimal_build.nix.golden @@ -1,6 +1,12 @@ # 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 }: +{ + system ? builtins.currentSystem + , pkgs + , lib + , fetchurl + , installShellFiles +}: let shaMap = { i686-linux = "0000000000000000000000000000000000000000000000000000"; diff --git a/internal/pipe/nix/testdata/TestRunPipe/minimal_publish.nix.golden b/internal/pipe/nix/testdata/TestRunPipe/minimal_publish.nix.golden index 2bd6335d0..654eea85b 100644 --- a/internal/pipe/nix/testdata/TestRunPipe/minimal_publish.nix.golden +++ b/internal/pipe/nix/testdata/TestRunPipe/minimal_publish.nix.golden @@ -1,6 +1,12 @@ # 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 }: +{ + system ? builtins.currentSystem + , pkgs + , lib + , fetchurl + , installShellFiles +}: let shaMap = { x86_64-linux = "sha1"; diff --git a/internal/pipe/nix/testdata/TestRunPipe/open-pr_build.nix.golden b/internal/pipe/nix/testdata/TestRunPipe/open-pr_build.nix.golden index a4b9035f9..c21ef1b6c 100644 --- a/internal/pipe/nix/testdata/TestRunPipe/open-pr_build.nix.golden +++ b/internal/pipe/nix/testdata/TestRunPipe/open-pr_build.nix.golden @@ -1,6 +1,12 @@ # 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 }: +{ + system ? builtins.currentSystem + , pkgs + , lib + , fetchurl + , installShellFiles +}: let shaMap = { i686-linux = "0000000000000000000000000000000000000000000000000000"; diff --git a/internal/pipe/nix/testdata/TestRunPipe/open-pr_publish.nix.golden b/internal/pipe/nix/testdata/TestRunPipe/open-pr_publish.nix.golden index edd9dc9cf..ad2187662 100644 --- a/internal/pipe/nix/testdata/TestRunPipe/open-pr_publish.nix.golden +++ b/internal/pipe/nix/testdata/TestRunPipe/open-pr_publish.nix.golden @@ -1,6 +1,12 @@ # 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 }: +{ + system ? builtins.currentSystem + , pkgs + , lib + , fetchurl + , installShellFiles +}: let shaMap = { x86_64-linux = "sha1"; diff --git a/internal/pipe/nix/testdata/TestRunPipe/partial_build.nix.golden b/internal/pipe/nix/testdata/TestRunPipe/partial_build.nix.golden index bf23f6fc5..91300d0f0 100644 --- a/internal/pipe/nix/testdata/TestRunPipe/partial_build.nix.golden +++ b/internal/pipe/nix/testdata/TestRunPipe/partial_build.nix.golden @@ -1,6 +1,12 @@ # 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 }: +{ + system ? builtins.currentSystem + , pkgs + , lib + , fetchurl + , installShellFiles +}: let shaMap = { x86_64-linux = "0000000000000000000000000000000000000000000000000000"; diff --git a/internal/pipe/nix/testdata/TestRunPipe/partial_publish.nix.golden b/internal/pipe/nix/testdata/TestRunPipe/partial_publish.nix.golden index f5a28dbb7..57aa7c2b1 100644 --- a/internal/pipe/nix/testdata/TestRunPipe/partial_publish.nix.golden +++ b/internal/pipe/nix/testdata/TestRunPipe/partial_publish.nix.golden @@ -1,6 +1,12 @@ # 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 }: +{ + system ? builtins.currentSystem + , pkgs + , lib + , fetchurl + , installShellFiles +}: let shaMap = { x86_64-linux = "sha1"; diff --git a/internal/pipe/nix/testdata/TestRunPipe/skip-upload-auto_build.nix.golden b/internal/pipe/nix/testdata/TestRunPipe/skip-upload-auto_build.nix.golden index b07ae5188..5e9fc24f4 100644 --- a/internal/pipe/nix/testdata/TestRunPipe/skip-upload-auto_build.nix.golden +++ b/internal/pipe/nix/testdata/TestRunPipe/skip-upload-auto_build.nix.golden @@ -1,6 +1,12 @@ # 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 }: +{ + system ? builtins.currentSystem + , pkgs + , lib + , fetchurl + , installShellFiles +}: let shaMap = { i686-linux = "0000000000000000000000000000000000000000000000000000"; diff --git a/internal/pipe/nix/testdata/TestRunPipe/skip-upload_build.nix.golden b/internal/pipe/nix/testdata/TestRunPipe/skip-upload_build.nix.golden index b07ae5188..5e9fc24f4 100644 --- a/internal/pipe/nix/testdata/TestRunPipe/skip-upload_build.nix.golden +++ b/internal/pipe/nix/testdata/TestRunPipe/skip-upload_build.nix.golden @@ -1,6 +1,12 @@ # 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 }: +{ + system ? builtins.currentSystem + , pkgs + , lib + , fetchurl + , installShellFiles +}: let shaMap = { i686-linux = "0000000000000000000000000000000000000000000000000000"; diff --git a/internal/pipe/nix/testdata/TestRunPipe/unibin-replaces_build.nix.golden b/internal/pipe/nix/testdata/TestRunPipe/unibin-replaces_build.nix.golden index 5f56378ca..8209592de 100644 --- a/internal/pipe/nix/testdata/TestRunPipe/unibin-replaces_build.nix.golden +++ b/internal/pipe/nix/testdata/TestRunPipe/unibin-replaces_build.nix.golden @@ -1,6 +1,12 @@ # 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 }: +{ + system ? builtins.currentSystem + , pkgs + , lib + , fetchurl + , installShellFiles +}: let shaMap = { i686-linux = "0000000000000000000000000000000000000000000000000000"; diff --git a/internal/pipe/nix/testdata/TestRunPipe/unibin-replaces_publish.nix.golden b/internal/pipe/nix/testdata/TestRunPipe/unibin-replaces_publish.nix.golden index ec5ef059f..de7503c89 100644 --- a/internal/pipe/nix/testdata/TestRunPipe/unibin-replaces_publish.nix.golden +++ b/internal/pipe/nix/testdata/TestRunPipe/unibin-replaces_publish.nix.golden @@ -1,6 +1,12 @@ # 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 }: +{ + system ? builtins.currentSystem + , pkgs + , lib + , fetchurl + , installShellFiles +}: let shaMap = { x86_64-linux = "sha1"; diff --git a/internal/pipe/nix/testdata/TestRunPipe/unibin_build.nix.golden b/internal/pipe/nix/testdata/TestRunPipe/unibin_build.nix.golden index d732fc50c..d83fe68ad 100644 --- a/internal/pipe/nix/testdata/TestRunPipe/unibin_build.nix.golden +++ b/internal/pipe/nix/testdata/TestRunPipe/unibin_build.nix.golden @@ -1,6 +1,12 @@ # 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 }: +{ + system ? builtins.currentSystem + , pkgs + , lib + , fetchurl + , installShellFiles +}: let shaMap = { i686-linux = "0000000000000000000000000000000000000000000000000000"; diff --git a/internal/pipe/nix/testdata/TestRunPipe/unibin_publish.nix.golden b/internal/pipe/nix/testdata/TestRunPipe/unibin_publish.nix.golden index bf98219f1..f3ea6a4c7 100644 --- a/internal/pipe/nix/testdata/TestRunPipe/unibin_publish.nix.golden +++ b/internal/pipe/nix/testdata/TestRunPipe/unibin_publish.nix.golden @@ -1,6 +1,12 @@ # 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 }: +{ + system ? builtins.currentSystem + , pkgs + , lib + , fetchurl + , installShellFiles +}: let shaMap = { x86_64-linux = "sha1"; diff --git a/internal/pipe/nix/testdata/TestRunPipe/wrapped-in-dir_build.nix.golden b/internal/pipe/nix/testdata/TestRunPipe/wrapped-in-dir_build.nix.golden index 76649aded..4a831b611 100644 --- a/internal/pipe/nix/testdata/TestRunPipe/wrapped-in-dir_build.nix.golden +++ b/internal/pipe/nix/testdata/TestRunPipe/wrapped-in-dir_build.nix.golden @@ -1,6 +1,12 @@ # 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 }: +{ + system ? builtins.currentSystem + , pkgs + , lib + , fetchurl + , installShellFiles +}: let shaMap = { i686-linux = "0000000000000000000000000000000000000000000000000000"; diff --git a/internal/pipe/nix/testdata/TestRunPipe/wrapped-in-dir_publish.nix.golden b/internal/pipe/nix/testdata/TestRunPipe/wrapped-in-dir_publish.nix.golden index 6ec4d7514..f85b8dc07 100644 --- a/internal/pipe/nix/testdata/TestRunPipe/wrapped-in-dir_publish.nix.golden +++ b/internal/pipe/nix/testdata/TestRunPipe/wrapped-in-dir_publish.nix.golden @@ -1,6 +1,12 @@ # 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 }: +{ + system ? builtins.currentSystem + , pkgs + , lib + , fetchurl + , installShellFiles +}: let shaMap = { x86_64-linux = "sha1"; diff --git a/internal/pipe/nix/tmpl.nix b/internal/pipe/nix/tmpl.nix index d50187d2e..0acf41163 100644 --- a/internal/pipe/nix/tmpl.nix +++ b/internal/pipe/nix/tmpl.nix @@ -1,6 +1,19 @@ # 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 }: +{ + system ? builtins.currentSystem + , pkgs + , lib + , fetchurl + , installShellFiles + {{- if .Dependencies }} + , makeWrapper + , stdenv + {{- end -}} + {{- range $index, $element := .Dependencies }} + , {{ . -}} + {{- end }} +}: let shaMap = { {{- with .Archives.linux386.Sha }} @@ -59,7 +72,7 @@ in pkgs.stdenv.mkDerivation { sourceRoot = "{{ .SourceRoot }}"; - nativeBuildInputs = [ installShellFiles ]; + nativeBuildInputs = [ {{ range $input, $plat := .Inputs }}{{ . }} {{ end }}]; installPhase = '' {{- range $index, $element := .Install }} diff --git a/pkg/config/config.go b/pkg/config/config.go index e46a23fd3..65a3680d2 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -259,6 +259,48 @@ type Nix struct { Description string `yaml:"description,omitempty" json:"description,omitempty"` Homepage string `yaml:"homepage,omitempty" json:"homepage,omitempty"` License string `yaml:"license,omitempty" json:"license,omitempty"` + + Dependencies []NixDependency `yaml:"dependencies,omitempty" json:"dependencies,omitempty"` +} + +type NixDependency struct { + Name string `yaml:"name" json:"name"` + OS string `yaml:"os,omitempty" json:"os,omitempty" jsonschema:"enum=linux,enum=darwin"` +} + +func (a NixDependency) JSONSchema() *jsonschema.Schema { + reflector := jsonschema.Reflector{ + ExpandedStruct: true, + } + type t NixDependency + schema := reflector.Reflect(&t{}) + return &jsonschema.Schema{ + OneOf: []*jsonschema.Schema{ + { + Type: "string", + }, + schema, + }, + } +} + +func (a *NixDependency) UnmarshalYAML(unmarshal func(interface{}) error) error { + var str string + if err := unmarshal(&str); err == nil { + a.Name = str + return nil + } + + type t NixDependency + var dep t + if err := unmarshal(&dep); err != nil { + return err + } + + a.Name = dep.Name + a.OS = dep.OS + + return nil } type Winget struct { diff --git a/www/docs/customization/nix.md b/www/docs/customization/nix.md index 6b4b7a6d6..0f8f5b053 100644 --- a/www/docs/customization/nix.md +++ b/www/docs/customization/nix.md @@ -74,6 +74,17 @@ nix: # Templates: allowed skip_upload: true + # Runtime dependencies of the package. + # + # Since: v1.20. + dependencies: + - zsh + - chromium + - name: bash + os: linux + - name: fish + os: darwin + # Custom install script. # # Default: 'mkdir -p $out/bin; cp -vr $binary $out/bin/$binary' diff --git a/www/docs/static/schema.json b/www/docs/static/schema.json index 6f0e067ab..4294786b9 100644 --- a/www/docs/static/schema.json +++ b/www/docs/static/schema.json @@ -2040,11 +2040,45 @@ }, "license": { "type": "string" + }, + "dependencies": { + "items": { + "$ref": "#/$defs/NixDependency" + }, + "type": "array" } }, "additionalProperties": false, "type": "object" }, + "NixDependency": { + "oneOf": [ + { + "type": "string" + }, + { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/goreleaser/goreleaser/pkg/config/t", + "properties": { + "name": { + "type": "string" + }, + "os": { + "type": "string", + "enum": [ + "linux", + "darwin" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "name" + ] + } + ] + }, "OpenCollective": { "properties": { "enabled": {