diff --git a/lib/default.nix b/lib/default.nix index 689dc23..cd6efcd 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -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; } ) diff --git a/lib/modules.nix b/lib/modules.nix new file mode 100644 index 0000000..a890582 --- /dev/null +++ b/lib/modules.nix @@ -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' + ]; +} diff --git a/tests/configs/default.nix b/tests/configs/default.nix index a0506e8..9aac2c6 100644 --- a/tests/configs/default.nix +++ b/tests/configs/default.nix @@ -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 ]; }; } diff --git a/tests/configs/lib-modules-subset/make-wraparound.nix b/tests/configs/lib-modules-subset/make-wraparound.nix new file mode 100644 index 0000000..4ba00c7 --- /dev/null +++ b/tests/configs/lib-modules-subset/make-wraparound.nix @@ -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 + ''; + }; +}