From 86913e049dc5c6b91088300515de09b62a9ff554 Mon Sep 17 00:00:00 2001 From: Marie Ramlow Date: Tue, 27 Feb 2024 12:19:31 +0100 Subject: [PATCH] gauge: add wrapper Adds a wrapper to the gauge package, which allows installing plugins declaratively with nix. --- .../manual/release-notes/rl-2405.section.md | 4 ++ pkgs/development/tools/gauge/default.nix | 6 +++ pkgs/development/tools/gauge/nix-check.patch | 50 +++++++++++++++++++ pkgs/development/tools/gauge/wrapper.nix | 48 ++++++++++++++++++ pkgs/top-level/all-packages.nix | 3 +- 5 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 pkgs/development/tools/gauge/nix-check.patch create mode 100644 pkgs/development/tools/gauge/wrapper.nix diff --git a/nixos/doc/manual/release-notes/rl-2405.section.md b/nixos/doc/manual/release-notes/rl-2405.section.md index 5f2c384473da..7b06a89c3245 100644 --- a/nixos/doc/manual/release-notes/rl-2405.section.md +++ b/nixos/doc/manual/release-notes/rl-2405.section.md @@ -399,6 +399,10 @@ The pre-existing [services.ankisyncd](#opt-services.ankisyncd.enable) has been m upgrade NetBox by changing `services.netbox.package`. Database migrations will be run automatically. +- `gauge` now supports installing plugins using nix. For the old imperative approach, switch to `gauge-unwrapped`. + You can load plugins from an existing gauge manifest file using `gauge.fromManifest ./path/to/manifest.json` or + specify plugins in nix using `gauge.withPlugins (p: with p; [ js html-report xml-report ])`. + - `firefox-devedition`, `firefox-beta`, `firefox-esr` executable file names for now match their package names, which is consistent with the `firefox-*-bin` packages. The desktop entries are also updated so that you can have multiple editions of firefox in your app launcher. - switch-to-configuration does not directly call systemd-tmpfiles anymore. diff --git a/pkgs/development/tools/gauge/default.nix b/pkgs/development/tools/gauge/default.nix index efe9917a0d8a..f1cdcbe0a538 100644 --- a/pkgs/development/tools/gauge/default.nix +++ b/pkgs/development/tools/gauge/default.nix @@ -4,6 +4,12 @@ buildGoModule rec { pname = "gauge"; version = "1.6.6"; + patches = [ + # adds a check which adds an error message when trying to + # install plugins imperatively when using the wrapper + ./nix-check.patch + ]; + src = fetchFromGitHub { owner = "getgauge"; repo = "gauge"; diff --git a/pkgs/development/tools/gauge/nix-check.patch b/pkgs/development/tools/gauge/nix-check.patch new file mode 100644 index 000000000000..37aec8a51b62 --- /dev/null +++ b/pkgs/development/tools/gauge/nix-check.patch @@ -0,0 +1,50 @@ +diff --git a/plugin/install/install.go b/plugin/install/install.go +index 60c61550..d7573c2d 100644 +--- a/plugin/install/install.go ++++ b/plugin/install/install.go +@@ -151,6 +151,7 @@ func isOSCompatible(zipfile string) bool { + + // InstallPluginFromZipFile installs plugin from given zip file + func InstallPluginFromZipFile(zipFile string, pluginName string) InstallResult { ++ CheckForNixStore(fmt.Sprintf("Tried to install the plugin `%s`.", pluginName)) + if !isPlatformIndependent(zipFile) && !isOSCompatible(zipFile) { + err := fmt.Errorf("provided plugin is not compatible with OS %s %s", runtime.GOOS, runtime.GOARCH) + return installError(err) +@@ -314,6 +315,7 @@ func runPlatformCommands(commands platformSpecificCommand, workingDir string) er + // UninstallPlugin uninstall the given plugin of the given uninstallVersion + // If uninstallVersion is not specified, it uninstalls all the versions of given plugin + func UninstallPlugin(pluginName string, uninstallVersion string) { ++ CheckForNixStore(fmt.Sprintf("Tried to uninstall the plugin `%s`.", pluginName)) + pluginsHome, err := common.GetPrimaryPluginsInstallDir() + if err != nil { + logger.Fatalf(true, "Failed to uninstall plugin %s. %s", pluginName, err.Error()) +@@ -518,6 +520,7 @@ func AllPlugins(silent, languageOnly bool) { + + // UpdatePlugins updates all the currently installed plugins to its latest version + func UpdatePlugins(silent bool) { ++ CheckForNixStore("Tried to update plugins") + var failedPlugin []string + pluginInfos, err := pluginInfo.GetPluginsInfo() + if err != nil { +@@ -673,3 +676,21 @@ func AddPluginToProject(pluginName string) error { + logger.Infof(true, "Plugin %s was successfully added to the project\n", pluginName) + return nil + } ++ ++func CheckForNixStore(message string) error { ++ installDir, err := common.GetPrimaryPluginsInstallDir() ++ if err != nil { ++ return err ++ } ++ if strings.HasPrefix(installDir, "/nix/store") { ++ ++ // check if we're installing in the sandbox ++ if os.Getenv("NIX_GAUGE_IN_SANDBOX") == "true" { ++ return nil ++ } ++ logger.Errorf(true, "%s\ngauge is installed with nix.\nPlease install plugins using nix or use the `gauge-unwrapped` package.", message) ++ os.Exit(1) ++ ++ } ++ return nil ++} diff --git a/pkgs/development/tools/gauge/wrapper.nix b/pkgs/development/tools/gauge/wrapper.nix new file mode 100644 index 000000000000..cbc192bf12c4 --- /dev/null +++ b/pkgs/development/tools/gauge/wrapper.nix @@ -0,0 +1,48 @@ +{ gauge-unwrapped +, makeWrapper +, stdenvNoCC +, lib +, xorg +, gaugePlugins +, plugins ? [] +}: + +stdenvNoCC.mkDerivation { + pname = "gauge-wrapped"; + inherit (gauge-unwrapped) version; + + dontUnpack = true; + + installPhase = '' + mkdir -p $out{bin,/share/gauge/{plugins,config}} + export NIX_GAUGE_IN_SANDBOX=true + export GAUGE_HOME=$(mktemp -d) + + # run gauge to create config files + cd $(mktemp -d) + gauge init js || true + + mkdir -p "$out/share/gauge/config" + mv "$GAUGE_HOME"/config/{gauge,template}.properties "$out/share/gauge/config" + + export GAUGE_HOME="$out/share/gauge" + + ${lib.concatMapStringsSep "\n" (plugin: '' + for plugin in "$(ls ${plugin}/share/gauge-plugins)"; do + echo Installing gauge plugin $plugin + mkdir -p "$GAUGE_HOME/plugins/$plugin" + # Use lndir here + # gauge checks for a directory, which fails if it's a symlink + # It's easier to link this with lndir, than patching an upstream dependency + lndir "${plugin}/share/gauge-plugins/$plugin" "$GAUGE_HOME/plugins/$plugin" + done + '') plugins} + + makeWrapper ${gauge-unwrapped}/bin/gauge $out/bin/gauge \ + --set GAUGE_HOME "$GAUGE_HOME" + ''; + + nativeBuildInputs = [ gauge-unwrapped makeWrapper xorg.lndir ]; + + inherit (gauge-unwrapped) meta; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index b604757b0e68..d86301632c8b 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -8326,7 +8326,8 @@ with pkgs; gau = callPackage ../tools/security/gau { }; - gauge = callPackage ../development/tools/gauge { }; + gauge-unwrapped = callPackage ../development/tools/gauge { }; + gauge = callPackage ../development/tools/gauge/wrapper.nix { }; gaugePlugins = recurseIntoAttrs (callPackage ../development/tools/gauge/plugins {}); gawd = python3Packages.toPythonApplication python3Packages.gawd;