Policy based custom classes for Impermanence support in aspects #590
|
Hi there, I'm currently trying to wrap my head around the architecture patterns in den to see if they might be helpful for reorganizing my NixOS config. One aspect (see what I did there 😀) that I find most interesting would be the ability for individual aspects to provide the file paths for Impermanence that belong to the given program the aspect enables. I imagine something like this: {
den.aspects.my-tool = {
homeManager ={
programs.my-tool.enable = true;
};
persistUserFiles = [
".config/tool.rc"
];
persistUserFolders = [
".config/tool"
];
persistFiles = [
"/etc/tool.rc"
];
persistFolders = [
"/etc/tool"
];
};
}Ideally there is only one additional aspect that then enables Impermanence for a given host and takes these values into account to configure {
environment.persistence."/persistence" = {
# for persistFolders
directories = [
...
];
# for persistFiles
files = [
...
];
users.$USER = {
# for persistUserFolders with the correct username of the entity the aspect applied to
directories = [
...
];
# for persistUserFiles
files = [
...
];
};
};
}I've seen different concepts in the den documentation that would seem a possible avenue for realizing this functionality. Quirks, policies and batteries.forward. I've read in other discussions that policies seem the future for enabling this kind of thing. So what would be the most idiomatic, concise and modern way to implement this requirement? |
Replies: 4 comments 34 replies
|
Thought I'd share my findings. I suppose you are somewhat familiar with impermanence and should understand den overall. I followed README and examples and that was generally enough to create the class. I currently use den.batteries.forward in this manner (currently all in one file though could be broken up, sry if it's a bit messy). I use similar pattern for disko. Supposing you use flakes. I use flake-file and highly recommend using it if you aren't already.
In case you are confused, take a look at examples below. Class does the following: Aspect pulls in impermanence nixosModule and sets up some basic configuration.
1.Host enables with:
and examples for some user stuff: or for the user itself: This way you don't need to pass |
|
Sorry to have kept you waiting, was busy and tired.
Overall, there is no |
|
I actually don't use policies at all for impermanence -- no need for forward rules. I use quirks. https://github.com/sini/nix-config/blob/main/modules/den/quirks/impermanence.nix |
|
I did something similar to what they did above. First, I used a forwarder, then I patched the impermanence module by adding deduplication logic. (See this). The second, I tried an experiment using quirks similar to the one above. The difference is that in the user schema, I set the |
I got it. The thing is, you apply the impermanence aspect in the sys-secret-basic aspect that will included in to-users. It'll executed twice because you have 2 users. Even you're using lib.unique, this will still duplicated because the mergePersist is called twice.
That's my bad, I just understood the trace you did.
I tried several ways and find one that works. Here for the logic: