mirror of
https://github.com/foo-dogsquared/nix-module-wrapper-manager-fds.git
synced 2025-02-12 00:19:03 +00:00
wrapper-manager-fds/modules: overhaul wrapper config
Now, there could be multiple wrappers within the configuration but it should still result with one derivation unlike the original version. This could be handy for making package overrides with multiple binaries (for example, 7Z) while making the interface consistent. This turns out to be way nicer than I thought which is a good thing.
This commit is contained in:
parent
393465ec47
commit
28dfaefc20
10
modules/env/common.nix
vendored
10
modules/env/common.nix
vendored
@ -11,10 +11,7 @@ let
|
|||||||
modulesPath = builtins.toString ../wrapper-manager;
|
modulesPath = builtins.toString ../wrapper-manager;
|
||||||
};
|
};
|
||||||
modules = [
|
modules = [
|
||||||
({ lib, name, ... }: {
|
../wrapper-manager
|
||||||
imports = [ ../wrapper-manager ];
|
|
||||||
config.executableName = lib.mkDefault name;
|
|
||||||
})
|
|
||||||
] ++ cfg.sharedModules;
|
] ++ cfg.sharedModules;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
@ -34,18 +31,17 @@ in
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
config.build = {
|
config.build = {
|
||||||
variant = "package";
|
|
||||||
isBinary = true;
|
isBinary = true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
'';
|
'';
|
||||||
description = ''
|
description = ''
|
||||||
Extra modules to be added to all of the wrappers.
|
Extra modules to be added to all of the wrapper-manager configurations.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
wrappers = lib.mkOption {
|
packages = lib.mkOption {
|
||||||
type = lib.types.attrsOf wrapperManagerModule;
|
type = lib.types.attrsOf wrapperManagerModule;
|
||||||
description = ''
|
description = ''
|
||||||
A set of wrappers to be added into the environment configuration.
|
A set of wrappers to be added into the environment configuration.
|
||||||
|
4
modules/env/home-manager/default.nix
vendored
4
modules/env/home-manager/default.nix
vendored
@ -11,9 +11,9 @@ in
|
|||||||
config = lib.mkMerge [
|
config = lib.mkMerge [
|
||||||
{ wrapper-manager.extraSpecialArgs.hmConfig = config; }
|
{ wrapper-manager.extraSpecialArgs.hmConfig = config; }
|
||||||
|
|
||||||
(lib.mkIf (cfg.wrappers != {}) {
|
(lib.mkIf (cfg.packages != {}) {
|
||||||
home.packages =
|
home.packages =
|
||||||
lib.mapAttrsToList (_: wrapper: wrapper.build.toplevel) cfg.wrappers;
|
lib.mapAttrsToList (_: wrapper: wrapper.build.toplevel) cfg.packages;
|
||||||
})
|
})
|
||||||
] ;
|
] ;
|
||||||
}
|
}
|
||||||
|
4
modules/env/nixos/default.nix
vendored
4
modules/env/nixos/default.nix
vendored
@ -11,9 +11,9 @@ in
|
|||||||
config = lib.mkMerge [
|
config = lib.mkMerge [
|
||||||
{ wrapper-manager.extraSpecialArgs.nixosConfig = config; }
|
{ wrapper-manager.extraSpecialArgs.nixosConfig = config; }
|
||||||
|
|
||||||
(lib.mkIf (cfg.wrappers != {}) {
|
(lib.mkIf (cfg.packages != {}) {
|
||||||
environment.systemPackages =
|
environment.systemPackages =
|
||||||
lib.mapAttrsToList (_: wrapper: wrapper.build.toplevel) cfg.wrappers;
|
lib.mapAttrsToList (_: wrapper: wrapper.build.toplevel) cfg.packages;
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -1,120 +1,45 @@
|
|||||||
{ config, lib, ... }:
|
{ config, lib, ... }:
|
||||||
|
|
||||||
let
|
|
||||||
flagType = with lib.types; listOf (coercedTo anything (x: builtins.toString x) str);
|
|
||||||
in
|
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
prependArgs = lib.mkOption {
|
wrappers = lib.mkOption {
|
||||||
type = flagType;
|
type = with lib.types; attrsOf (submoduleWith {
|
||||||
|
modules = [ ./shared/wrappers.nix ];
|
||||||
|
specialArgs.envConfig = config;
|
||||||
|
});
|
||||||
description = ''
|
description = ''
|
||||||
A list of arguments to be prepended to the user-given argument for the
|
A set of wrappers to be included in the resulting derivation from
|
||||||
wrapper script.
|
wrapper-manager evaluation.
|
||||||
'';
|
|
||||||
default = [ ];
|
|
||||||
example = lib.literalExpression ''
|
|
||||||
[
|
|
||||||
"--config" ./config.conf
|
|
||||||
]
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
appendArgs = lib.mkOption {
|
|
||||||
type = flagType;
|
|
||||||
description = ''
|
|
||||||
A list of arguments to be appended to the user-given argument for the
|
|
||||||
wrapper script.
|
|
||||||
'';
|
|
||||||
default = [ ];
|
|
||||||
example = lib.literalExpression ''
|
|
||||||
[
|
|
||||||
"--name" "doggo"
|
|
||||||
"--location" "Your mom's home"
|
|
||||||
]
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
arg0 = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
description = ''
|
|
||||||
The first argument of the wrapper script. This option is used when the
|
|
||||||
{option}`build.variant` is `executable`.
|
|
||||||
'';
|
|
||||||
example = lib.literalExpression "lib.getExe' pkgs.neofetch \"neofetch\"";
|
|
||||||
};
|
|
||||||
|
|
||||||
package = lib.mkOption {
|
|
||||||
type = lib.types.package;
|
|
||||||
description = ''
|
|
||||||
The package to be wrapped. This is used only when the
|
|
||||||
{option}`build.variant` is set to `package.`
|
|
||||||
'';
|
|
||||||
example = lib.literalExpression "pkgs.hello";
|
|
||||||
};
|
|
||||||
|
|
||||||
env = lib.mkOption {
|
|
||||||
type = with lib.types; attrsOf str;
|
|
||||||
description = ''
|
|
||||||
A set of environment variables to be declared in the wrapper script.
|
|
||||||
'';
|
'';
|
||||||
default = { };
|
default = { };
|
||||||
example = {
|
example = lib.literalExpression ''
|
||||||
"FOO_TYPE" = "custom";
|
{
|
||||||
"FOO_LOG_STYLE" = "systemd";
|
yt-dlp-audio = {
|
||||||
};
|
arg0 = lib.getExe' pkgs.yt-dlp "yt-dlp";
|
||||||
};
|
prependArgs = [
|
||||||
|
"--config-location" ./config/yt-dlp/audio.conf
|
||||||
unset = lib.mkOption {
|
];
|
||||||
type = with lib.types; listOf nonEmptyStr;
|
};
|
||||||
description = ''
|
}
|
||||||
A list of environment variables to be unset into the wrapper script.
|
|
||||||
'';
|
'';
|
||||||
default = [ ];
|
|
||||||
example = [ "NO_COLOR" ];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
executableName = lib.mkOption {
|
basePackages = lib.mkOption {
|
||||||
type = lib.types.nonEmptyStr;
|
type = with lib.types; listOf package;
|
||||||
description = ''
|
description = ''
|
||||||
The name of the executable of the wrapper script.
|
A list of packages to be included in the wrapper package.
|
||||||
|
|
||||||
This option behaves differently depending on {option}`build.variant`.
|
::: {note}
|
||||||
|
If the list is not empty, this can override some of the binaries
|
||||||
- When the build variant option is `executable`, it sets the name of the
|
included in this list which is typically intended to be used as a
|
||||||
wrapper script.
|
wrapped package.
|
||||||
- When the build variant option is `package`, it depends on the name on
|
:::
|
||||||
one of the executables from the given package.
|
|
||||||
'';
|
|
||||||
default =
|
|
||||||
if config.build.variant == "executable" then
|
|
||||||
lib.last (lib.path.subpath.components (lib.removePrefix "/" config.arg0))
|
|
||||||
else
|
|
||||||
config.package.meta.mainProgram or config.package.pname;
|
|
||||||
example = "custom-name";
|
|
||||||
};
|
|
||||||
|
|
||||||
pathAdd = lib.mkOption {
|
|
||||||
type = with lib.types; listOf path;
|
|
||||||
description = ''
|
|
||||||
A list of paths to be added as part of the `PATH` environment variable.
|
|
||||||
'';
|
'';
|
||||||
default = [ ];
|
default = [ ];
|
||||||
example = lib.literalExpression ''
|
example = lib.literalExpression ''
|
||||||
wrapperManagerLib.getBin (with pkgs; [
|
with pkgs; [
|
||||||
yt-dlp
|
yt-dlp
|
||||||
gallery-dl
|
]
|
||||||
])
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
preScript = lib.mkOption {
|
|
||||||
type = lib.types.lines;
|
|
||||||
description = ''
|
|
||||||
Script to run before the main executable.
|
|
||||||
'';
|
|
||||||
default = "";
|
|
||||||
example = lib.literalExpression ''
|
|
||||||
echo "HELLO WORLD!"
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -1,24 +1,7 @@
|
|||||||
{ config, lib, pkgs, wrapperManagerLib, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
{
|
{
|
||||||
options.build = {
|
options.build = {
|
||||||
variant = lib.mkOption {
|
|
||||||
type = lib.types.enum [ "executable" "package" ];
|
|
||||||
description = ''
|
|
||||||
Tells how should wrapper-manager wrap the executable. The toplevel
|
|
||||||
derivation resulting from the module environment will vary depending on
|
|
||||||
the value.
|
|
||||||
|
|
||||||
- With `executable`, the wrapper is a lone executable wrapper script in
|
|
||||||
`$OUT/bin` subdirectory in the output.
|
|
||||||
|
|
||||||
- With `package`, wrapper-manager creates a wrapped package with all of
|
|
||||||
the output contents intact.
|
|
||||||
'';
|
|
||||||
default = "executable";
|
|
||||||
example = "package";
|
|
||||||
};
|
|
||||||
|
|
||||||
isBinary = lib.mkOption {
|
isBinary = lib.mkOption {
|
||||||
type = lib.types.bool;
|
type = lib.types.bool;
|
||||||
description = ''
|
description = ''
|
||||||
@ -29,24 +12,12 @@
|
|||||||
example = false;
|
example = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
makeWrapperArgs = lib.mkOption {
|
extraSetup = lib.mkOption {
|
||||||
type = with lib.types; listOf str;
|
type = lib.types.lines;
|
||||||
description = ''
|
description = ''
|
||||||
A list of extra arguments to be passed to the `makeWrapperArgs` build
|
Additional script for setting up the wrapper script derivation.
|
||||||
step of the evaluation.
|
|
||||||
'';
|
'';
|
||||||
example = [ "--inherit-argv0" ];
|
default = "";
|
||||||
};
|
|
||||||
|
|
||||||
extraArgs = lib.mkOption {
|
|
||||||
type = with lib.types; attrsOf anything;
|
|
||||||
description = ''
|
|
||||||
A attrset of extra arguments to be passed to the
|
|
||||||
`wrapperManagerLib.mkWrapper` function. This will also be passed as
|
|
||||||
part of the derivation attribute into the resulting script from
|
|
||||||
{option}`preScript`.
|
|
||||||
'';
|
|
||||||
default = { };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
toplevel = lib.mkOption {
|
toplevel = lib.mkOption {
|
||||||
@ -59,32 +30,25 @@
|
|||||||
|
|
||||||
config = {
|
config = {
|
||||||
build = {
|
build = {
|
||||||
makeWrapperArgs = [
|
toplevel =
|
||||||
"--argv0" (config.executableName or config.arg0)
|
|
||||||
]
|
|
||||||
++ (lib.mapAttrsToList (n: v: "--set ${n} ${v}") config.env)
|
|
||||||
++ (builtins.map (v: "--unset ${v}") config.unset)
|
|
||||||
++ (builtins.map (v: "--prefix 'PATH' ':' ${lib.escapeShellArg v}") config.pathAdd)
|
|
||||||
++ (builtins.map (v: "--add-flags ${v}") config.prependArgs)
|
|
||||||
++ (builtins.map (v: "--append-flags ${v}") config.appendArgs)
|
|
||||||
++ (lib.optionals (!config.build.isBinary && config.preScript != "") (
|
|
||||||
let
|
let
|
||||||
preScript =
|
mkWrapBuild = wrappers:
|
||||||
pkgs.runCommand "wrapper-script-prescript-${config.executableName}" config.build.extraArgs config.preScript;
|
lib.concatMapStrings (v: ''
|
||||||
|
makeWrapper "${v.arg0}" "${builtins.placeholder "out"}/bin/${v.executableName}" ${lib.concatStringsSep " " v.makeWrapperArgs}
|
||||||
|
'') wrappers;
|
||||||
in
|
in
|
||||||
[ "--run" preScript ]));
|
pkgs.symlinkJoin {
|
||||||
|
name = "wrapper-manager-fds-wrapped-package";
|
||||||
toplevel =
|
paths = config.basePackages;
|
||||||
if config.build.variant == "executable" then
|
nativeBuildInputs =
|
||||||
wrapperManagerLib.mkWrapper (config.build.extraArgs // {
|
if config.build.isBinary
|
||||||
inherit (config) arg0 executableName;
|
then [ pkgs.makeBinaryWrapper ]
|
||||||
inherit (config.build) isBinary makeWrapperArgs;
|
else [ pkgs.makeWrapper ];
|
||||||
})
|
postBuild = ''
|
||||||
else
|
${config.build.extraSetup}
|
||||||
wrapperManagerLib.mkWrappedPackage (config.build.extraArgs // {
|
${mkWrapBuild (lib.attrValues config.wrappers)}
|
||||||
inherit (config) arg0 package executableName;
|
'';
|
||||||
inherit (config.build) isBinary makeWrapperArgs;
|
};
|
||||||
});
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
127
modules/wrapper-manager/shared/wrappers.nix
Normal file
127
modules/wrapper-manager/shared/wrappers.nix
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
{ name, lib, config, pkgs, envConfig, ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
flagType = with lib.types; listOf (coercedTo anything (x: builtins.toString x) str);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
prependArgs = lib.mkOption {
|
||||||
|
type = flagType;
|
||||||
|
description = ''
|
||||||
|
A list of arguments to be prepended to the user-given argument for the
|
||||||
|
wrapper script.
|
||||||
|
'';
|
||||||
|
default = [ ];
|
||||||
|
example = lib.literalExpression ''
|
||||||
|
[
|
||||||
|
"--config" ./config.conf
|
||||||
|
]
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
appendArgs = lib.mkOption {
|
||||||
|
type = flagType;
|
||||||
|
description = ''
|
||||||
|
A list of arguments to be appended to the user-given argument for the
|
||||||
|
wrapper script.
|
||||||
|
'';
|
||||||
|
default = [ ];
|
||||||
|
example = lib.literalExpression ''
|
||||||
|
[
|
||||||
|
"--name" "doggo"
|
||||||
|
"--location" "Your mom's home"
|
||||||
|
]
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
arg0 = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
description = ''
|
||||||
|
The first argument of the wrapper script. This option is used when the
|
||||||
|
{option}`build.variant` is `executable`.
|
||||||
|
'';
|
||||||
|
example = lib.literalExpression "lib.getExe' pkgs.neofetch \"neofetch\"";
|
||||||
|
};
|
||||||
|
|
||||||
|
executableName = lib.mkOption {
|
||||||
|
type = lib.types.nonEmptyStr;
|
||||||
|
description = "The name of the executable.";
|
||||||
|
default = name;
|
||||||
|
example = "custom-name";
|
||||||
|
};
|
||||||
|
|
||||||
|
env = lib.mkOption {
|
||||||
|
type = with lib.types; attrsOf str;
|
||||||
|
description = ''
|
||||||
|
A set of environment variables to be declared in the wrapper script.
|
||||||
|
'';
|
||||||
|
default = { };
|
||||||
|
example = {
|
||||||
|
"FOO_TYPE" = "custom";
|
||||||
|
"FOO_LOG_STYLE" = "systemd";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
unset = lib.mkOption {
|
||||||
|
type = with lib.types; listOf nonEmptyStr;
|
||||||
|
description = ''
|
||||||
|
A list of environment variables to be unset into the wrapper script.
|
||||||
|
'';
|
||||||
|
default = [ ];
|
||||||
|
example = [ "NO_COLOR" ];
|
||||||
|
};
|
||||||
|
|
||||||
|
pathAdd = lib.mkOption {
|
||||||
|
type = with lib.types; listOf path;
|
||||||
|
description = ''
|
||||||
|
A list of paths to be added as part of the `PATH` environment variable.
|
||||||
|
'';
|
||||||
|
default = [ ];
|
||||||
|
example = lib.literalExpression ''
|
||||||
|
wrapperManagerLib.getBin (with pkgs; [
|
||||||
|
yt-dlp
|
||||||
|
gallery-dl
|
||||||
|
])
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
preScript = lib.mkOption {
|
||||||
|
type = lib.types.lines;
|
||||||
|
description = ''
|
||||||
|
Script fragments to run before the main executable. This option is only
|
||||||
|
used when the wrapper script is not compiled into a binary (that is,
|
||||||
|
when {option}`build.isBinary` is set to `false`).
|
||||||
|
'';
|
||||||
|
default = "";
|
||||||
|
example = lib.literalExpression ''
|
||||||
|
echo "HELLO WORLD!"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
makeWrapperArgs = lib.mkOption {
|
||||||
|
type = with lib.types; listOf str;
|
||||||
|
description = ''
|
||||||
|
A list of extra arguments to be passed as part of makeWrapper.
|
||||||
|
'';
|
||||||
|
example = [ "--inherit-argv0" ];
|
||||||
|
readOnly = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
makeWrapperArgs = [
|
||||||
|
"--argv0" config.arg0
|
||||||
|
]
|
||||||
|
++ (lib.mapAttrsToList (n: v: "--set ${n} ${v}") config.env)
|
||||||
|
++ (builtins.map (v: "--unset ${v}") config.unset)
|
||||||
|
++ (builtins.map (v: "--prefix 'PATH' ':' ${lib.escapeShellArg v}") config.pathAdd)
|
||||||
|
++ (builtins.map (v: "--add-flags ${v}") config.prependArgs)
|
||||||
|
++ (builtins.map (v: "--append-flags ${v}") config.appendArgs)
|
||||||
|
++ (lib.optionals (!envConfig.build.isBinary && config.preScript != "") (
|
||||||
|
let
|
||||||
|
preScript =
|
||||||
|
pkgs.runCommand "wrapper-script-prescript-${config.executableName}" { } config.preScript;
|
||||||
|
in
|
||||||
|
[ "--run" preScript ]));
|
||||||
|
};
|
||||||
|
}
|
4
tests/lib/env/default.nix
vendored
4
tests/lib/env/default.nix
vendored
@ -10,7 +10,7 @@ lib.runTests {
|
|||||||
specialArgs.yourMomName = "Joe Mama";
|
specialArgs.yourMomName = "Joe Mama";
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
lib.isDerivation sampleConf.config.build.toplevel;
|
lib.isDerivation sampleConf;
|
||||||
expected = true;
|
expected = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ lib.runTests {
|
|||||||
specialArgs.yourMomName = "Joe Mama";
|
specialArgs.yourMomName = "Joe Mama";
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
lib.isDerivation sampleConf.config.build.toplevel;
|
lib.isDerivation sampleConf;
|
||||||
expected = true;
|
expected = true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
8
tests/lib/env/wrapper-fastfetch.nix
vendored
8
tests/lib/env/wrapper-fastfetch.nix
vendored
@ -1,7 +1,9 @@
|
|||||||
{ lib, pkgs, ... }:
|
{ lib, pkgs, ... }:
|
||||||
|
|
||||||
{
|
{
|
||||||
arg0 = lib.getExe' pkgs.fastfetch "fastfetch";
|
wrappers.fastfetch = {
|
||||||
appendArgs = [ "--logo" "Guix" ];
|
arg0 = lib.getExe' pkgs.fastfetch "fastfetch";
|
||||||
env.NO_COLOR = "1";
|
appendArgs = [ "--logo" "Guix" ];
|
||||||
|
env.NO_COLOR = "1";
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
16
tests/lib/env/wrapper-neofetch.nix
vendored
16
tests/lib/env/wrapper-neofetch.nix
vendored
@ -1,11 +1,13 @@
|
|||||||
{ lib, pkgs, yourMomName, ... }:
|
{ lib, pkgs, yourMomName, ... }:
|
||||||
|
|
||||||
{
|
{
|
||||||
arg0 = lib.getExe' pkgs.neofetch "neofetch";
|
wrappers.neofetch = {
|
||||||
executableName = yourMomName;
|
arg0 = lib.getExe' pkgs.neofetch "neofetch";
|
||||||
appendArgs = [
|
executableName = yourMomName;
|
||||||
"--ascii_distro" "guix"
|
appendArgs = [
|
||||||
"--title_fqdn" "off"
|
"--ascii_distro" "guix"
|
||||||
"--os_arch" "off"
|
"--title_fqdn" "off"
|
||||||
];
|
"--os_arch" "off"
|
||||||
|
];
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user