/
boxxy.nix
110 lines (94 loc) · 2.64 KB
/
boxxy.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
{ 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;
description = ''
Unique identifier of the boxxy rule. This can be any single-line string.
'';
};
target = mkOption {
type = types.str;
default = "";
example = "~/.ssh";
description = ''
What directory/file to redirect.
'';
};
rewrite = mkOption {
type = types.str;
default = "";
example = literalExpression ''"''${config.xdg.configHome}/ssh"'';
description = ''
Where that file/directory should be rewritten to.
'';
};
mode = mkOption {
type = types.enum [ "file" "directory" ];
default = "directory";
description = ''
Does the current path redirect a file or a directory?
'';
};
only = mkOption {
type = types.listOf types.str;
default = [ ];
example = literalExpression ''
[
"bash"
"/usr/bin/sh"
]
'';
description = ''
Apply redirection ONLY to specified executable names.
'';
};
context = mkOption {
type = types.listOf types.str;
default = [ ];
example = [ "/home/example/Projects/my-project" ];
description = ''
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";
}
'';
description = ''
Give certain environment variables for said match.
'';
};
};
};
in {
options.programs.boxxy = {
enable = mkEnableOption "boxxy: Boxes in badly behaving applications";
package = mkPackageOption pkgs "boxxy" { };
rules = mkOption {
type = types.listOf boxxyRulesOpts;
default = [ ];
description = "List of boxxy rules";
};
};
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 ];
}