2023-06-09 22:32:11 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.programs.boxxy;
|
|
|
|
|
|
|
|
configPath = "${config.xdg.configHome}/boxxy/boxxy.yaml";
|
|
|
|
settingsFormat = pkgs.formats.yaml { };
|
|
|
|
|
|
|
|
boxxyRulesOpts = types.submodule {
|
|
|
|
freeformType = settingsFormat.type;
|
|
|
|
|
|
|
|
options = {
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2023-06-09 22:32:11 +02:00
|
|
|
Unique identifier of the boxxy rule. This can be any single-line string.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
target = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
example = "~/.ssh";
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2023-06-09 22:32:11 +02:00
|
|
|
What directory/file to redirect.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
rewrite = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
example = literalExpression ''"''${config.xdg.configHome}/ssh"'';
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2023-06-09 22:32:11 +02:00
|
|
|
Where that file/directory should be rewritten to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
mode = mkOption {
|
|
|
|
type = types.enum [ "file" "directory" ];
|
|
|
|
default = "directory";
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2023-06-09 22:32:11 +02:00
|
|
|
Does the current path redirect a file or a directory?
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
only = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
|
|
|
example = literalExpression ''
|
|
|
|
[
|
|
|
|
"bash"
|
|
|
|
"/usr/bin/sh"
|
|
|
|
]
|
|
|
|
'';
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2023-06-09 22:32:11 +02:00
|
|
|
Apply redirection ONLY to specified executable names.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
context = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
|
|
|
example = [ "/home/example/Projects/my-project" ];
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2023-06-09 22:32:11 +02:00
|
|
|
Apply redirection ONLY when in a certain directory.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
env = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = { };
|
|
|
|
example = literalExpression ''
|
|
|
|
{
|
|
|
|
MY_ENV_VAR = "my_env_var_value";
|
|
|
|
}
|
|
|
|
'';
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2023-06-09 22:32:11 +02:00
|
|
|
Give certain environment variables for said match.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
options.programs.boxxy = {
|
2023-07-01 01:30:13 +02:00
|
|
|
enable =
|
|
|
|
mkEnableOption (lib.mdDoc "boxxy: Boxes in badly behaving applications");
|
2023-06-09 22:32:11 +02:00
|
|
|
|
2023-07-01 11:41:32 +02:00
|
|
|
package = mkPackageOptionMD pkgs "boxxy" { };
|
2023-06-09 22:32:11 +02:00
|
|
|
|
|
|
|
rules = mkOption {
|
|
|
|
type = types.listOf boxxyRulesOpts;
|
|
|
|
default = [ ];
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc "List of boxxy rules";
|
2023-06-09 22:32:11 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
assertions =
|
|
|
|
[ (hm.assertions.assertPlatform "programs.boxxy" pkgs platforms.linux) ];
|
|
|
|
|
|
|
|
home.file = mkIf (cfg.rules != [ ]) {
|
|
|
|
"${configPath}".source =
|
|
|
|
settingsFormat.generate "boxxy-config.yaml" { rules = cfg.rules; };
|
|
|
|
};
|
|
|
|
|
|
|
|
home.packages = [ cfg.package ];
|
|
|
|
};
|
|
|
|
|
|
|
|
meta.maintainers = with lib.hm.maintainers; [ nikp123 ];
|
|
|
|
}
|
|
|
|
|