wrapper-manager-fds/modules: add option for binary wrapper creation

Also updated the name of the wrapper arguments to its
stdenv.mkDerivation equivalent.
This commit is contained in:
Gabriel Arazas 2024-07-02 11:38:30 +08:00
parent a9992ee194
commit 7cdb74a4a3

View File

@ -19,11 +19,21 @@
example = "package"; example = "package";
}; };
extraWrapperArgs = lib.mkOption { isBinary = lib.mkOption {
type = lib.types.bool;
description = ''
Sets the build step to create a tiny compiled executable for the
wrapper. By default, it is set to `true`.
'';
default = true;
example = false;
};
makeWrapperArgs = lib.mkOption {
type = with lib.types; listOf str; type = with lib.types; listOf str;
description = '' description = ''
A list of extra arguments to be passed to the `makeWrapper` nixpkgs A list of extra arguments to be passed to the `makeWrapperArgs` build
setup hook function. step of the evaluation.
''; '';
example = [ "--inherit-argv0" ]; example = [ "--inherit-argv0" ];
}; };
@ -36,6 +46,7 @@
part of the derivation attribute into the resulting script from part of the derivation attribute into the resulting script from
{option}`preScript`. {option}`preScript`.
''; '';
default = { };
}; };
toplevel = lib.mkOption { toplevel = lib.mkOption {
@ -46,31 +57,33 @@
}; };
}; };
config.build = { config = {
extraWrapperArgs = [ build = {
"--argv0" (config.executableName or config.arg0) makeWrapperArgs = [
"--add-flags" config.prependFlags "--argv0" (config.executableName or config.arg0)
"--append-flags" config.appendFlags ]
] ++ (lib.mapAttrsToList (n: v: "--set ${n} ${v}") config.env)
++ (lib.mapAttrsToList (n: v: "--set ${lib.escapeShellArg n} ${lib.escapeShellArg v}") config.env) ++ (builtins.map (v: "--prefix 'PATH' ':' ${lib.escapeShellArg v}") config.pathAdd)
++ (builtins.map (v: "--prefix 'PATH' ':' ${lib.escapeShellArg v}") config.pathAdd) ++ (builtins.map (v: "--add-flags ${v}") config.prependArgs)
++ (lib.optionals (config.preScript != "") ( ++ (builtins.map (v: "--append-flags ${v}") config.appendArgs)
let ++ (lib.optionals (!config.build.isBinary && config.preScript != "") (
preScript = let
pkgs.runCommand "wrapper-script-prescript-${config.executableName}" config.build.extraArgs config.preScript; preScript =
in pkgs.runCommand "wrapper-script-prescript-${config.executableName}" config.build.extraArgs config.preScript;
"--run" preScript)); in
[ "--run" preScript ]));
toplevel = toplevel =
if config.build.variant == "executable" then if config.build.variant == "executable" then
wrapperManagerLib.mkWrapper (config.build.extraArgs // { wrapperManagerLib.mkWrapper (config.build.extraArgs // {
inherit (config) arg0 executableName; inherit (config) arg0 executableName;
makeWrapperArgs = config.build.extraWrapperArgs; inherit (config.build) isBinary makeWrapperArgs;
}) })
else else
wrapperManagerLib.mkWrappedPackage (config.build.extraArgs // { wrapperManagerLib.mkWrappedPackage (config.build.extraArgs // {
inherit (config) package executableName; inherit (config) package executableName;
makeWrapperArgs = config.build.extraWrapperArgs; inherit (config.build) isBinary makeWrapperArgs;
}); });
};
}; };
} }