2024-07-29 11:03:31 +00:00
|
|
|
{ lib, pkgs, config, ... }:
|
|
|
|
|
|
|
|
let
|
2024-10-01 05:03:23 +00:00
|
|
|
cfg = config.wraparound.boxxy;
|
2024-07-29 11:03:31 +00:00
|
|
|
|
|
|
|
boxxyRuleModule = { name, lib, ... }: {
|
|
|
|
options = {
|
|
|
|
source = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = ''
|
|
|
|
The path of the file to be remounted.
|
|
|
|
'';
|
|
|
|
example = "~/.tmux.conf";
|
|
|
|
};
|
|
|
|
|
|
|
|
destination = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = name;
|
|
|
|
description = ''
|
|
|
|
The path where the source will be remounted to.
|
|
|
|
'';
|
|
|
|
example = "~/.config/tmux/tmux.conf";
|
|
|
|
};
|
|
|
|
|
|
|
|
mode = lib.mkOption {
|
|
|
|
type = with lib.types; nullOr (enum [ "file" "dir" ]);
|
|
|
|
description = ''
|
|
|
|
Mode indicating the behavior for remounting.
|
|
|
|
'';
|
|
|
|
default = null;
|
|
|
|
example = "dir";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
boxxyModuleFactory = { isGlobal ? false }: {
|
|
|
|
package = lib.mkPackageOption pkgs "boxxy" { } // lib.optionalAttrs (!isGlobal) {
|
|
|
|
default = cfg.package;
|
|
|
|
};
|
|
|
|
|
2024-08-01 01:01:05 +00:00
|
|
|
# TODO: Perhaps, consider creating a PR to upstream repo to pass a config file?
|
|
|
|
# Boxxy doesn't have a way to pass a custom configuration file so we're
|
|
|
|
# settling with this. Besides, Boxxy-launched programs can inherit the
|
|
|
|
# environment anyways so a custom config file is not needed for now.
|
2024-07-29 11:03:31 +00:00
|
|
|
rules = lib.mkOption {
|
|
|
|
type = with lib.types; attrsOf (submodule boxxyRuleModule);
|
2024-07-30 03:52:31 +00:00
|
|
|
default = { };
|
|
|
|
description = if isGlobal then ''
|
2024-07-29 11:03:31 +00:00
|
|
|
Global set of rules to be applied per-wrapper.
|
2024-07-30 03:52:31 +00:00
|
|
|
'' else ''
|
|
|
|
Set of rules to be applied to the wrapper.
|
2024-07-29 11:03:31 +00:00
|
|
|
'';
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
{
|
|
|
|
"~/.config/tmux/tmux.conf".source = "~/.tmux.conf";
|
|
|
|
"~/.config/bash/bashrc".source = "~/.bashrc";
|
|
|
|
"~/.config/vscode" = {
|
|
|
|
source = "~/.vscode";
|
|
|
|
mode = "dir";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraArgs = lib.mkOption {
|
|
|
|
type = with lib.types; listOf str;
|
2024-07-30 03:52:31 +00:00
|
|
|
description = if isGlobal then ''
|
|
|
|
Global list of arguments to be appended to each Boxxy-enabled wrappers.
|
|
|
|
'' else ''
|
2024-07-31 05:29:51 +00:00
|
|
|
List of arguments to the {command}`boxxy` executable.
|
2024-07-29 11:03:31 +00:00
|
|
|
'';
|
2024-07-30 03:52:31 +00:00
|
|
|
default = [ ];
|
2024-07-29 11:03:31 +00:00
|
|
|
example = [ "--immutable" "--daemon" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
2024-10-01 05:03:23 +00:00
|
|
|
options.wraparound.boxxy = boxxyModuleFactory { isGlobal = true; };
|
2024-07-29 11:03:31 +00:00
|
|
|
|
|
|
|
options.wrappers =
|
|
|
|
let
|
|
|
|
boxxySandboxModule = { name, lib, config, pkgs, ... }:
|
|
|
|
let
|
2024-10-01 05:03:23 +00:00
|
|
|
submoduleCfg = config.wraparound.boxxy;
|
2024-07-29 11:03:31 +00:00
|
|
|
in
|
|
|
|
{
|
2024-10-01 05:03:23 +00:00
|
|
|
options.wraparound.variant = lib.mkOption {
|
2024-07-29 11:03:31 +00:00
|
|
|
type = with lib.types; nullOr (enum [ "boxxy" ]);
|
|
|
|
};
|
|
|
|
|
2024-10-01 05:03:23 +00:00
|
|
|
options.wraparound.boxxy = boxxyModuleFactory { isGlobal = false; };
|
2024-07-29 11:03:31 +00:00
|
|
|
|
2024-10-01 05:03:23 +00:00
|
|
|
config = lib.mkIf (config.wraparound.variant == "boxxy") {
|
|
|
|
wraparound.boxxy.rules = cfg.rules;
|
2024-07-30 03:52:31 +00:00
|
|
|
|
2024-10-01 05:03:23 +00:00
|
|
|
wraparound.boxxy.extraArgs =
|
2024-07-30 03:52:31 +00:00
|
|
|
cfg.extraArgs
|
|
|
|
++ (lib.mapAttrsToList
|
2024-07-29 11:03:31 +00:00
|
|
|
(_: metadata:
|
|
|
|
let
|
|
|
|
inherit (metadata) source destination mode;
|
2024-08-10 13:28:31 +00:00
|
|
|
ruleArg =
|
|
|
|
if mode != null
|
|
|
|
then "${source}:${destination}:${mode}"
|
|
|
|
else "${source}:${destination}";
|
2024-07-29 11:03:31 +00:00
|
|
|
in
|
2024-08-12 09:56:36 +00:00
|
|
|
"--rule ${ruleArg}")
|
2024-07-30 03:52:31 +00:00
|
|
|
submoduleCfg.rules);
|
2024-07-29 11:03:31 +00:00
|
|
|
|
2024-09-04 06:28:53 +00:00
|
|
|
arg0 = lib.getExe' submoduleCfg.package "boxxy";
|
2024-07-29 11:03:31 +00:00
|
|
|
prependArgs = lib.mkBefore
|
|
|
|
(submoduleCfg.extraArgs
|
2024-10-01 05:03:23 +00:00
|
|
|
++ [ "--" config.wraparound.subwrapper.arg0 ]
|
|
|
|
++ config.wraparound.subwrapper.extraArgs);
|
2024-07-29 11:03:31 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
lib.mkOption {
|
|
|
|
type = with lib.types; attrsOf (submodule boxxySandboxModule);
|
|
|
|
};
|
|
|
|
}
|