gauge: add wrapper

Adds a wrapper to the gauge package, which allows installing plugins declaratively with nix.
This commit is contained in:
Marie Ramlow 2024-02-27 12:19:31 +01:00 committed by Yaya
parent 6ad8088b73
commit 86913e049d
5 changed files with 110 additions and 1 deletions

View File

@ -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.

View File

@ -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";

View File

@ -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
+}

View File

@ -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;
}

View File

@ -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;