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 = { config.build = {
isBinary = true; variant = "shell";
}; };
} }
] ]

View File

@ -141,8 +141,8 @@ let
Script fragments to run before the main executable. Script fragments to run before the main executable.
::: {.note} ::: {.note}
This option is only used when {option}`build.isBinary` is set to This option is only used when {option}`build.variant` is set to
`false`. `shell`.
::: :::
''; '';
default = ""; default = "";
@ -181,7 +181,7 @@ let
) config.env ) config.env
++ (builtins.map (v: "--add-flags ${lib.escapeShellArg v}") config.prependArgs) ++ (builtins.map (v: "--add-flags ${lib.escapeShellArg v}") config.prependArgs)
++ (builtins.map (v: "--append-flags ${lib.escapeShellArg v}") config.appendArgs) ++ (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 let
preScript = preScript =
pkgs.runCommand "wrapper-script-prescript-${config.executableName}" { } pkgs.runCommand "wrapper-script-prescript-${config.executableName}" { }

View File

@ -7,21 +7,14 @@
{ {
options.build = { options.build = {
isBinary = lib.mkOption { variant = lib.mkOption {
type = lib.types.bool; type = lib.types.enum [ "binary" "shell" ];
description = '' description = ''
Sets the build step to create a tiny compiled executable for the Indicates the type of wrapper to be made. By default, wrapper-manager
wrapper. By default, it is set to `true`. sets this to `binary`.
::: {.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`).
:::
''; '';
default = true; default = "binary";
example = false; example = "shell";
}; };
extraSetup = lib.mkOption { extraSetup = lib.mkOption {
@ -53,8 +46,11 @@
build = { build = {
toplevel = toplevel =
let let
inherit (config.build) variant;
makeWrapperArg0 = makeWrapperArg0 =
if config.build.isBinary then "makeBinaryWrapper" else "makeShellWrapper"; if variant == "binary" then "makeBinaryWrapper"
else if variant == "shell" then "makeShellWrapper"
else "makeWrapper";
mkWrapBuild = mkWrapBuild =
wrappers: wrappers:
@ -72,7 +68,9 @@
name = "wrapper-manager-fds-wrapped-package"; name = "wrapper-manager-fds-wrapped-package";
paths = desktopEntries ++ config.basePackages; paths = desktopEntries ++ config.basePackages;
nativeBuildInputs = 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 = '' postBuild = ''
${config.build.extraSetup} ${config.build.extraSetup}
${mkWrapBuild (lib.attrValues config.wrappers)} ${mkWrapBuild (lib.attrValues config.wrappers)}
@ -82,7 +80,11 @@
config.basePackages.overrideAttrs (final: prev: { config.basePackages.overrideAttrs (final: prev: {
nativeBuildInputs = nativeBuildInputs =
(prev.nativeBuildInputs or [ ]) (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 ]; ++ lib.optionals (config.xdg.desktopEntries != { }) [ pkgs.copyDesktopItems ];
desktopItems = (prev.desktopItems or [ ]) ++ desktopEntries; desktopItems = (prev.desktopItems or [ ]) ++ desktopEntries;
postFixup = '' postFixup = ''

View File

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

View File

@ -26,7 +26,7 @@
wrapper = config.build.toplevel; wrapper = config.build.toplevel;
in in
pkgs.runCommand "wrapper-manager-neofetch-actually-built" { } '' 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
''; '';
}; };
} }