mirror of
https://github.com/foo-dogsquared/nix-module-wrapper-manager-fds.git
synced 2025-01-30 22:57:58 +00:00
wrapper-manager-fds/lib: init modules subset
This commit is contained in:
parent
19a035da58
commit
90a9702169
@ -22,8 +22,10 @@ pkgs.lib.makeExtensible (
|
||||
{
|
||||
env = import ./env.nix;
|
||||
utils = callLibs ./utils.nix;
|
||||
modules = callLibs ./modules.nix;
|
||||
|
||||
inherit (self.env) build eval;
|
||||
inherit (self.utils) getBin getLibexec;
|
||||
inherit (self.modules) makeWraparound;
|
||||
}
|
||||
)
|
||||
|
52
lib/modules.nix
Normal file
52
lib/modules.nix
Normal file
@ -0,0 +1,52 @@
|
||||
# These are functions that are only meant to be invoked inside of a
|
||||
# wrapper-manager environment.
|
||||
#
|
||||
# On a note for wrapper-manager developer(s), due to how tedious it can be to
|
||||
# test library functions like that, we're putting them inside of the test
|
||||
# configs instead of the typical library test suite.
|
||||
{
|
||||
pkgs,
|
||||
lib,
|
||||
self,
|
||||
}:
|
||||
|
||||
rec {
|
||||
/*
|
||||
Make a wrapper-manager wrapper config containing a sub-wrapper that wraps
|
||||
another program. Several examples of this includes sudo, Bubblewrap, and
|
||||
Gamescope.
|
||||
*/
|
||||
makeWraparound = {
|
||||
arg0,
|
||||
under,
|
||||
underFlags ? [ ],
|
||||
underSeparator ? "",
|
||||
...
|
||||
}@module:
|
||||
let
|
||||
# These are the attrnames that would be overtaken with the function and
|
||||
# will be merged anyways so...
|
||||
functionArgs = builtins.functionArgs makeWraparound;
|
||||
module' = lib.removeAttrs module (lib.attrNames functionArgs);
|
||||
in
|
||||
lib.mkMerge [
|
||||
{
|
||||
arg0 = under;
|
||||
|
||||
# This should be the very first things to be in the arguments so
|
||||
# we're just making sure that it is the case. The priority is chosen
|
||||
# arbitrarily just in case the user already has `prependArgs` values
|
||||
# with `lib.mkBefore` for the original arg0.
|
||||
prependArgs = lib.mkOrder 250 (
|
||||
underFlags
|
||||
++ lib.optionals (underSeparator != "") [ underSeparator ]
|
||||
++ [ arg0 ]
|
||||
);
|
||||
}
|
||||
|
||||
# It's constructed like this to make it ergonomic to use. The user can
|
||||
# simply delete the makeWraparound exclusive arguments and still work
|
||||
# normally.
|
||||
module'
|
||||
];
|
||||
}
|
@ -17,4 +17,5 @@ in
|
||||
};
|
||||
single-basepackage = build { modules = [ ./single-basepackage.nix ]; };
|
||||
neofetch-with-additional-files = build { modules = [ ./neofetch-with-additional-files.nix ]; };
|
||||
lib-modules-make-wraparound = build { modules = [ ./lib-modules-subset/make-wraparound.nix ]; };
|
||||
}
|
||||
|
26
tests/configs/lib-modules-subset/make-wraparound.nix
Normal file
26
tests/configs/lib-modules-subset/make-wraparound.nix
Normal file
@ -0,0 +1,26 @@
|
||||
{ config, lib, pkgs, wrapperManagerLib, ... }:
|
||||
|
||||
let
|
||||
inherit (wrapperManagerLib) makeWraparound;
|
||||
in
|
||||
{
|
||||
build.variant = "shell";
|
||||
wrappers.tmux = makeWraparound {
|
||||
under = lib.getExe' pkgs.boxxy "boxxy";
|
||||
underFlags = [ "--rule" "~/.tmux.conf:~/.config/tmux/tmux.conf" ];
|
||||
underSeparator = "--";
|
||||
|
||||
arg0 = lib.getExe' pkgs.tmux "tmux";
|
||||
};
|
||||
|
||||
build.extraPassthru.wrapperManagerTests = {
|
||||
actuallyBuilt =
|
||||
let
|
||||
wrapper = config.build.toplevel;
|
||||
tmux = lib.getExe' wrapper "tmux";
|
||||
in
|
||||
pkgs.runCommand "wrapper-manager-tmux-actually-built" { } ''
|
||||
[ -x "${tmux}" ] && touch $out
|
||||
'';
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user