-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.nix
More file actions
62 lines (62 loc) · 1.59 KB
/
module.nix
File metadata and controls
62 lines (62 loc) · 1.59 KB
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
{occasion}: {
pkgs,
config,
lib ? pkgs.lib,
...
}: let
inherit (lib) mkEnableOption mkOption types mkIf literalExpression;
cfg = config.programs.occasion;
json = pkgs.formats.json {};
in {
options.programs.occasion = {
enable = mkEnableOption "Enable occasion.";
package = mkOption {
description = "Package for occasion.";
type = types.package;
default = occasion;
};
settings = mkOption {
description = "JSON config for occasion (occasions.json)";
type = json.type;
default = {};
example = literalExpression ''
{
dates = [
{
message = "hello friday!";
time = {
day_of = {
week = ["Friday"];
};
};
}
];
multiple_behavior = {
all = {
seperator = "";
};
};
}
'';
};
};
config = mkIf cfg.enable {
home.packages = [cfg.package];
xdg.configFile."occasions.json" = mkIf (cfg.settings != {}) {
source = json.generate "occasions.json" cfg.settings;
};
home.activation = mkIf (cfg.settings != {}) {
checkOccasionConfigFile = lib.hm.dag.entryBefore ["writeBoundary"] ''
if [ -f "$HOME/.config/occasion.json" ]; then
if ! output=$(${cfg.package}/bin/occasion --check 2>&1); then
echo "❌ Occasion config check failed:"
echo "$output"
exit 1
else
echo "✅ Occasion config check passed."
fi
fi
'';
};
};
}