From b667a335dec0f67b9d3ab1a91f21ed4450273d98 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Sat, 21 Sep 2024 10:14:54 +0800 Subject: [PATCH] wrapper-manager-fds/modules: change `build.isBinary` to `build.variant` This makes it possible to implement different types of wrappers, even our own in case it is desparately needed. --- modules/env/common.nix | 2 +- modules/wrapper-manager/base.nix | 6 ++--- modules/wrapper-manager/build.nix | 34 +++++++++++++++-------------- tests/configs/wrapper-fastfetch.nix | 2 +- tests/configs/wrapper-neofetch.nix | 2 +- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/modules/env/common.nix b/modules/env/common.nix index b4c4111..8f25343 100644 --- a/modules/env/common.nix +++ b/modules/env/common.nix @@ -40,7 +40,7 @@ in [ { config.build = { - isBinary = true; + variant = "shell"; }; } ] diff --git a/modules/wrapper-manager/base.nix b/modules/wrapper-manager/base.nix index 2785e3c..55c8ea3 100644 --- a/modules/wrapper-manager/base.nix +++ b/modules/wrapper-manager/base.nix @@ -141,8 +141,8 @@ let Script fragments to run before the main executable. ::: {.note} - This option is only used when {option}`build.isBinary` is set to - `false`. + This option is only used when {option}`build.variant` is set to + `shell`. ::: ''; default = ""; @@ -181,7 +181,7 @@ let ) config.env ++ (builtins.map (v: "--add-flags ${lib.escapeShellArg v}") config.prependArgs) ++ (builtins.map (v: "--append-flags ${lib.escapeShellArg v}") config.appendArgs) - ++ (lib.optionals (!envConfig.build.isBinary && config.preScript != "") ( + ++ (lib.optionals (envConfig.build.variant == "shell" && config.preScript != "") ( let preScript = pkgs.runCommand "wrapper-script-prescript-${config.executableName}" { } diff --git a/modules/wrapper-manager/build.nix b/modules/wrapper-manager/build.nix index e9008af..84d0a9e 100644 --- a/modules/wrapper-manager/build.nix +++ b/modules/wrapper-manager/build.nix @@ -7,21 +7,14 @@ { options.build = { - isBinary = lib.mkOption { - type = lib.types.bool; + variant = lib.mkOption { + type = lib.types.enum [ "binary" "shell" ]; description = '' - Sets the build step to create a tiny compiled executable for the - wrapper. By default, it is set to `true`. - - ::: {.warning} - Binary wrappers cannot have runtime expansion in its arguments - especially when setting environment variables that needs it. For this, - you'll have to switch to shell wrappers (e.g., `build.isBinary = - false`). - ::: + Indicates the type of wrapper to be made. By default, wrapper-manager + sets this to `binary`. ''; - default = true; - example = false; + default = "binary"; + example = "shell"; }; extraSetup = lib.mkOption { @@ -53,8 +46,11 @@ build = { toplevel = let + inherit (config.build) variant; makeWrapperArg0 = - if config.build.isBinary then "makeBinaryWrapper" else "makeShellWrapper"; + if variant == "binary" then "makeBinaryWrapper" + else if variant == "shell" then "makeShellWrapper" + else "makeWrapper"; mkWrapBuild = wrappers: @@ -72,7 +68,9 @@ name = "wrapper-manager-fds-wrapped-package"; paths = desktopEntries ++ config.basePackages; nativeBuildInputs = - if config.build.isBinary then [ pkgs.makeBinaryWrapper ] else [ pkgs.makeShellWrapper ]; + if variant == "binary" then [ pkgs.makeBinaryWrapper ] + else if variant == "shell" then [ pkgs.makeShellWrapper ] + else [ ]; postBuild = '' ${config.build.extraSetup} ${mkWrapBuild (lib.attrValues config.wrappers)} @@ -82,7 +80,11 @@ config.basePackages.overrideAttrs (final: prev: { nativeBuildInputs = (prev.nativeBuildInputs or [ ]) - ++ (if config.build.isBinary then [ pkgs.makeBinaryWrapper ] else [ pkgs.makeWrapper ]) + ++ ( + if variant == "binary" then [ pkgs.makeBinaryWrapper ] + else if variant == "shell" then [ pkgs.makeShellWrapper ] + else [ ] + ) ++ lib.optionals (config.xdg.desktopEntries != { }) [ pkgs.copyDesktopItems ]; desktopItems = (prev.desktopItems or [ ]) ++ desktopEntries; postFixup = '' diff --git a/tests/configs/wrapper-fastfetch.nix b/tests/configs/wrapper-fastfetch.nix index ba6d344..93a291f 100644 --- a/tests/configs/wrapper-fastfetch.nix +++ b/tests/configs/wrapper-fastfetch.nix @@ -7,7 +7,7 @@ }: { - build.isBinary = false; + build.variant = "shell"; wrappers.fastfetch = { arg0 = lib.getExe' pkgs.fastfetch "fastfetch"; diff --git a/tests/configs/wrapper-neofetch.nix b/tests/configs/wrapper-neofetch.nix index d012fad..4ca2f89 100644 --- a/tests/configs/wrapper-neofetch.nix +++ b/tests/configs/wrapper-neofetch.nix @@ -26,7 +26,7 @@ wrapper = config.build.toplevel; in pkgs.runCommand "wrapper-manager-neofetch-actually-built" { } '' - [ -x "${wrapper}/bin/${config.wrappers.fastfetch.executableName}" ] && touch $out + [ -x "${wrapper}/bin/${config.wrappers.neofetch.executableName}" ] && touch $out ''; }; }