-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpersist.nix
105 lines (88 loc) · 2.11 KB
/
persist.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
{ config, lib, osConfig, ... }:
let
inherit (lib)
filterAttrs
mapAttrsToList
mkIf
mkMerge
mkOption
pipe
unique
;
inherit (lib.types) attrsOf bool str submodule;
cfg = config.aquaris.persist;
inherit (osConfig.aquaris.persist) root;
inherit (osConfig.users.users.${config.home.username}) home;
allParents = file:
if file == "/" || file == "." then [ ]
else allParents (dirOf file) ++ [ file ];
mkIn = pfx: map (x: "d ${pfx}/${x} 0755 - - - -");
mkEntry = d: x:
let
persistDirs = pipe d [
allParents
(mkIn "${root}/${home}")
];
targetDirs = pipe d [
dirOf
allParents
(mkIn home)
];
final = let hd = "${home}/${d}"; in [
"z ${root}/${hd} ${x.m} - - - - "
"L+ ${hd} - - - - ${root}/${hd}"
];
in
persistDirs ++ targetDirs ++ final;
entry = submodule {
options = {
e = mkOption {
description = "Enable";
type = bool;
default = true;
};
m = mkOption {
description = "Mode";
type = str;
default = "0755";
};
};
};
in
{
options.aquaris.persist = mkOption {
description = "List of persistent directories";
type = attrsOf entry;
};
config = mkIf osConfig.aquaris.persist.enable {
aquaris.persist = mkMerge [
{
".cache/nix" = { };
}
(mkIf config.programs.direnv.enable {
".local/share/direnv" = { };
})
(mkIf config.programs.firefox.enable {
".cache/mozilla/firefox" = { };
${if config.aquaris.firefox.cleanHome
then ".local/share/mozilla/firefox"
else ".mozilla/firefox"} = { };
})
(mkIf config.programs.gpg.enable {
".gnupg" = { m = "0700"; };
})
(mkIf config.programs.zoxide.enable {
".local/share/zoxide" = { };
})
(mkIf config.programs.zsh.enable {
".cache/zsh" = { };
})
];
systemd.user.tmpfiles.rules = pipe cfg [
(filterAttrs (_: x: x.e))
(mapAttrsToList mkEntry)
builtins.concatLists
unique
];
};
}