-
Notifications
You must be signed in to change notification settings - Fork 0
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
fd alias to list stray files in /persist #21
Comments
I made a post activation script for the impermanence NixOS module, but I realised when I started working on the home-manager module won't actually be able to see a log from the home-manager module when rebuilding my system, which is arguably more important to me. I'm going to pivot and adapt a version of the fd alias I use for detecting files I might want to persist That way I can just run a command and detect what is in /persist that I probably don't want anymore Not as clean as I would have hoped, but I can't see I way I would have the home-manager module output to the rebuild logs Here's a patch for nix-community/impermanence@23c1f06 with my changes in case I decide to come back to this at some point --- a/nixos.nix
+++ b/nixos.nix
@@ -658,6 +658,18 @@ in
${concatMapStrings mkPersistFile files}
exit $_status
'';
+
+ listStrayFilesScript = let
+ searchPaths = filter (n: cfg.${n}.enable) (attrNames cfg);
+ searchString = concatStringsSep " " (map escapeShellArg searchPaths);
+ excludeFiles = map (file: concatPaths [file.persistentStoragePath file.filePath]) files;
+ excludeDirs = map (dir: concatPaths [dir.persistentStoragePath dir.dirPath]) directories;
+ excludeString = concatStringsSep " -o " (map (path: "-path " + escapeShellArg path) (excludeFiles ++ excludeDirs));
+ in
+ pkgs.writeShellScript "impermanence-list-stray-files" ''
+ echo -e "\033[1;33mimpermanence: The following files/directories were found in your persistent storage were not found in your persistence configuration\033[0m"
+ find ${searchString} \( ${excludeString} \) -prune -o \( -empty -type d -print0 \) -o \( -type f -print0 \) | xargs -0 -I{} /bin/sh -c 'echo -e "\033[1;33m{}\033[0m"'
+ '';
in
{
"createPersistentStorageDirs" = {
@@ -668,6 +680,9 @@ in
deps = [ "createPersistentStorageDirs" ];
text = "${persistFileScript}";
};
+ "listStrayFiles" = {
+ text = "${listStrayFilesScript}";
+ };
};
assertions =
|
I was not able to adapt my current fd alias to work, fd does not support excluding absolute paths unfortunately (see sharkdp/fd#851), and I could not think of a workaround I was able to implement the same functionality using the find command, and reworked the alias using fd to use find aswell Implemented using find in 374793a |
Files that are removed from persistence remain in
/persist
, a way to combat this would be to add a post activation script that goes through each directory in/persist
, excluding those persisted and displays them as a warning, so that they can be removed or added back to the persistence configurationThe text was updated successfully, but these errors were encountered: