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.
This commit is contained in:
Gabriel Arazas 2024-09-21 10:14:54 +08:00
parent 3516efa6f2
commit b667a335de
5 changed files with 24 additions and 22 deletions

View File

@ -40,7 +40,7 @@ in
[
{
config.build = {
isBinary = true;
variant = "shell";
};
}
]

View File

@ -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}" { }

View File

@ -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 = ''

View File

@ -7,7 +7,7 @@
}:
{
build.isBinary = false;
build.variant = "shell";
wrappers.fastfetch = {
arg0 = lib.getExe' pkgs.fastfetch "fastfetch";

View File

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