-
-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create presets #108
base: master
Are you sure you want to change the base?
Create presets #108
Conversation
This is important for preserving files such as /etc/machine-id that appear before the impermanence is started
The first bullet point is not possible to implement in a safe fashion - the file or directory can be read or written to while it's being copied or moved. We should absolutely not do that. I'm not really sure why it would be needed anyway, since |
Can you share how you achieved that? I can't reproduce it on NixOS Unstable, neither on my systems nor on VMs. Perhaps you can point to some things that I should also test while I'm at it? I feel like this behaviour comes up pretty consistently. It is also the case with host SSH keys: they are created before Impermanence is being ran. |
Well, my setup is here: https://github.com/talyz/nixos-config/blob/master/modules/ephemeral-root.nix#L103 - nothing fancy at all. I get the following messages on boot:
but they're expected, since they've already been mounted by the activation script. |
Huh. I'm not sure what to think of it. I'll research the problem in more detail and come back with a more detailed report on what really happens and what can be done about it. I am pretty positive that I'm not getting the same behaviour, though, running NixOS Unstable and latest Impermanence. Perhaps the issue lies in my setup. I'm not actually deleting anything on boot yet. Perhaps machine-id and SSH keys are getting generated in stage 1, then the root is erased, and only then the bind mounts happen. That would be perfectly logical, but it would also mean that setups that don't yet erase anything are not supported. If so, then this caveat should be documented. |
If you're not using ephemeral storage, that's the issue, yes. To bind mount files, empty files are created to serve as bind mount endpoints; if they're still there on boot, they would be identified as already existing files and not overwritten / mounted over. I suppose we could check for zero length files and consider them safe to mount over, but it's not really a supported use-case. I think the readme is already pretty clear in this regard - it's listed as the first point in the premises at the very top ;) As a side-note, if you're afraid to accidentally delete anything, you can use something like https://github.com/talyz/nixos-config/blob/master/machines/trace/configuration.nix#L77-L86 to create a new root subvolume on every boot. This assumes you're using btrfs, but similar things should be possible with zfs. |
Thanks, your insight was very helpful. I reverted the "fix" I've done. The setup indeed works with the config snippet you provided for BTRFS. I'm not sure how to make it actually erase the system though, lol. I might make a separate PR that would offload the whole "erasing" functionality to |
To erase old subvolumes, I just do the following:
I don't think erasing the root should be the task of Impermanence - there are many ways to do it and it's highly setup specific. We could however list a few examples of how to do it in the readme. I'll look into doing so. When it comes to presets, I want to keep the structure as simple as possible:
|
Any particular reason for this? I feel like there's clear value in separating out the different types of state we can preserve, because it allows better judgement on what to preserve, how, if it should be backed up, etc. |
I'm hesitant to mention this because it's mostly aspirational (mostly something that I wished existed but really don't have time to work on myself). But anyway, I felt it might be worth pointing out my own persistence "presets" for NixOS for reference: Here's the list of "supported" services: Here's a poorly documented list of persistence levels: Aspirationally one would be able to persist "secret" level files to a different mount than other regular files, but I'm not sure this idea would prove out (or be useful). (There's a companion repo for Home Manager "presets" too, which is unfortunately bare) |
commit 89253fb Merge: ec1a8e7 6f4fc9d Author: Kim Lindberger <[email protected]> Date: Tue May 16 21:15:34 2023 +0200 Merge pull request nix-community#125 from ReneHollander/master Skip generating bind mounts if no bind mounts are configured. commit 6f4fc9d Author: Rene Hollander <[email protected]> Date: Sat Apr 15 09:38:56 2023 +0200 Skip generating bind mounts if no bind mounts are configured. This fixes nix-community#105 by no longer generating an empty bash function. Empty functions in bash are invalid, which cause the activation to fail. commit ec1a8e7 Merge: df1692e 5a39142 Author: Kim Lindberger <[email protected]> Date: Mon May 15 11:54:52 2023 +0200 Merge pull request nix-community#128 from lovesegfault/disable feat(nixos): allow persistant locations to be disabled commit 5a39142 Author: Bernardo Meurer <[email protected]> Date: Sun May 14 16:59:19 2023 -0400 feat(nixos): allow persistant locations to be disabled commit df1692e Merge: c3f7012 2d57522 Author: Kim Lindberger <[email protected]> Date: Sun Apr 23 18:46:51 2023 +0200 Merge pull request nix-community#126 from alois31/assertion-hotfix nixos: Fix collision detection logic commit 2d57522 Author: Alois Wohlschlager <[email protected]> Date: Sun Apr 23 16:14:43 2023 +0200 nixos: Fix collision detection logic The logic for detecting whether a file or directory is specified multiple times was not updated to account for the recent file/filePath and directory/dirPath changes. This can lead to spurious failures like the following if the same home-relative path is persisted for different users: Failed assertions: - environment.persistence: The following directories were specified two or more times: .cache .config .local/share .local/state .gnupg .ssh In addition, the assertion may falsely not trigger in the contrived situation where the same entity is persisted both in a per-user configuration (using the relative path) and the global configuration (using the absolute path). Fix these situations by checking the absolute paths again using filePath and dirPath. commit c3f7012 Merge: 6138eb8 170e9b1 Author: Kim Lindberger <[email protected]> Date: Sun Apr 23 08:20:41 2023 +0200 Merge pull request nix-community#109 from nix-community/dir-creation-order nixos: Improve directory creation and permission and ownership assignment commit 170e9b1 Author: talyz <[email protected]> Date: Sun Nov 13 22:26:04 2022 +0100 README: Add matrix room link Also, remove the unrelated name explanation. commit b4160ba Author: talyz <[email protected]> Date: Sun Nov 13 18:18:15 2022 +0100 nixos: Rewrite directory creation for saner default permissions Construct directory items for all parent directories of the user specified files and directories, assigning better default permissions and ownership to each and removing this responsibility from the create-directories script. This means that all parent directories of root directories will now have the default permissions and ownership, not inherit them from the child. User directories are assigned default user ownership. The home directory itself is handled specially to make sure it is owned by the user, not readable by anyone else and its parent gets default root ownership. To illustrate this with an example, here is a directory specification and the ownership and permissions that could potentially be assigned to the parent directories, given none of them yet exist in persistent storage: environment.persistence."/persistent" = { users.talyz = { directories = [ { directory = ".local/share/secret"; mode = "0500"; } ]; }; }; Before: /home talyz:talyz 0500 /home/talyz talyz:talyz 0500 /home/talyz/.local talyz:talyz 0500 /home/talyz/.local/share talyz:talyz 0500 /home/talyz/.local/share/secret talyz:talyz 0500 After: /home root:root 0755 /home/talyz talyz:talyz 0700 /home/talyz/.local talyz:talyz 0755 /home/talyz/.local/share talyz:talyz 0755 /home/talyz/.local/share/secret talyz:talyz 0500 commit d30c421 Author: talyz <[email protected]> Date: Sun Nov 13 18:17:56 2022 +0100 nixos: Change internal file and directory semantics This adds the new internal options `home`, `filePath` and `dirPath`. Whereas previously `file` and `directory` would be rewritten to the full path for user files and directories, they now keep the value specified by the user. The new `filePath` and `dirPath` options fill their previous use where the full path is required. In addition, the new `home` option can be used to get the path to the user's home directory for a specific file or directory item; for root items it's set to `null`. commit cc00a2a Author: talyz <[email protected]> Date: Sun Nov 13 18:17:21 2022 +0100 nixos: Use coercedTo type rather than manually converting from str This simplifies the code quite a bit and should be easier to maintain. commit d144e36 Author: talyz <[email protected]> Date: Sun Nov 13 18:16:57 2022 +0100 all: Line up lib inherits vertically commit a65d708 Author: talyz <[email protected]> Date: Sun Nov 13 18:16:18 2022 +0100 nixos: Use mkDefault to set the default directory permissions This means we don't have to pass them around as function arguments, making things a bit cleaner. commit 6138eb8 Merge: 3792c10 a0b6d84 Author: Kim Lindberger <[email protected]> Date: Thu Feb 2 18:40:54 2023 +0100 Merge pull request nix-community#114 from mweinelt/persist-nixos-uidgidmap nixos: Recommend persisting /var/lib/nixos commit 3792c10 Merge: 5df9108 ba22f42 Author: Kim Lindberger <[email protected]> Date: Thu Feb 2 18:38:53 2023 +0100 Merge pull request nix-community#115 from Kranzes/master nixos: Mount binds after the persistent storage path commit ba22f42 Author: Ilan Joselevich <[email protected]> Date: Thu Feb 2 19:28:09 2023 +0200 nixos: Mount binds after the persistent storage path commit a0b6d84 Author: Martin Weinelt <[email protected]> Date: Thu Feb 2 17:23:19 2023 +0100 nixos: Recommend persisting /var/lib/nixos The `/var/lib/nixos` directory contains the uid and gid map for entities without a static id. Not persisting them means your user and group ids could change between reboots, which is likely undesirable. commit 5df9108 Merge: cd56321 32a5793 Author: Kim Lindberger <[email protected]> Date: Thu Nov 17 08:08:35 2022 +0100 Merge pull request nix-community#110 from ckiee/gate-verbose mount-file.bash: be quieter when debugging is off commit 32a5793 Author: ckie <[email protected]> Date: Thu Nov 17 08:09:12 2022 +0200 mount-file.bash: be quieter when debugging is off commit cd56321 Author: talyz <[email protected]> Date: Tue Nov 15 18:32:06 2022 +0100 home-manager: Add wrappers path for fusermount Since nix-community/home-manager@8866759 the path no longer includes the wrappers, since it's reset. To fix this, add the wrappers to the path.
Wanted to give an update cos I saw the NixCon talk on Impermanence and it was mentioned that PR on presets is WIP (when it is, sadly, not in progress lmao) So there are a few things to keep in mind here:
|
TODO: * Look at for more inspiration nix-community/impermanence#108 * Do home-manager * Common files nix-community/impermanence#10
TODO: * Look at for more inspiration nix-community/impermanence#108 * Do home-manager * Common files nix-community/impermanence#10
TODO: * Look at for more inspiration nix-community/impermanence#108 * Do home-manager * Common files nix-community/impermanence#10
TODO: * Look at for more inspiration nix-community/impermanence#108 * Do home-manager * Common files nix-community/impermanence#10
TODO: * Look at for more inspiration nix-community/impermanence#108 * Do home-manager * Common files nix-community/impermanence#10
TODO: * Look at for more inspiration nix-community/impermanence#108 * Do home-manager * Common files nix-community/impermanence#10
TODO: * Look at for more inspiration nix-community/impermanence#108 * Do home-manager * Common files nix-community/impermanence#10
TODO: * Look at for more inspiration nix-community/impermanence#108 * Do home-manager * Common files nix-community/impermanence#10
TODO: * Look at for more inspiration nix-community/impermanence#108 * Do home-manager * Common files nix-community/impermanence#10
TODO: * Look at for more inspiration nix-community/impermanence#108 * Do home-manager * Common files nix-community/impermanence#10
TODO: * Look at for more inspiration nix-community/impermanence#108 * Do home-manager * Common files nix-community/impermanence#10
TODO: * Look at for more inspiration nix-community/impermanence#108 * Do home-manager * Common files nix-community/impermanence#10
TODO: * Look at for more inspiration nix-community/impermanence#108 * Do home-manager * Common files nix-community/impermanence#10
TODO: * Look at for more inspiration nix-community/impermanence#108 * Do home-manager * Common files nix-community/impermanence#10 * Useful config: https://github.com/chayleaf/dotfiles/blob/f77271b249e0c08368573c22a5c34f0737d3a766/system/modules/impermanence.nix
TODO: * Do home-manager * Look at for more inspiration github.com:nix-community/impermanence/pull/108 * Common files github.com:nix-community/impermanence/issues/10 * Useful config: github.com:chayleaf/dotfiles/blob/f77271b249e0c08368573c22a5c34f0737d3a766/system/modules/impermanence.nix
TODO: * Do home-manager * Look at for more inspiration github.com:nix-community/impermanence/pull/108 * Common files github.com:nix-community/impermanence/issues/10 * Useful config: github.com:chayleaf/dotfiles/blob/f77271b249e0c08368573c22a5c34f0737d3a766/system/modules/impermanence.nix
TODO: * Do home-manager * Look at for more inspiration github.com:nix-community/impermanence/pull/108 * Common files github.com:nix-community/impermanence/issues/10 * Useful config: github.com:chayleaf/dotfiles/blob/f77271b249e0c08368573c22a5c34f0737d3a766/system/modules/impermanence.nix
TODO: * Do home-manager * Look at for more inspiration github.com:nix-community/impermanence/pull/108 * Common files github.com:nix-community/impermanence/issues/10 * Useful config: github.com:chayleaf/dotfiles/blob/f77271b249e0c08368573c22a5c34f0737d3a766/system/modules/impermanence.nix
TODO: * Do home-manager * Look at for more inspiration github.com:nix-community/impermanence/pull/108 * Common files github.com:nix-community/impermanence/issues/10 * Useful config: github.com:chayleaf/dotfiles/blob/f77271b249e0c08368573c22a5c34f0737d3a766/system/modules/impermanence.nix
This PR addresses #10. Most of the design considerations are written down in that issue.
Roadmap (not necessarily in order):
impermanence
is ran, such as/etc/machine-id
essential
preset. It should take care of things one absolutely must preserve between rebootssystem
preset. It should take care of persisting some nice-to-haves, such as NetworkManager's passwords, bluetooth connections, and so onservices
preset. It should take care of persisting data that services use, such as Prometheus, Loki and so onsystem
preset and then turn off preserving bluetooth connections