1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-22 18:29:39 +01:00

borgmatic: optionally exclude HM symlinks from backup

Co-authored-by: Naïm Favier <n@monade.li>
Co-authored-by: Robert Helgesson <robert@rycee.net>
This commit is contained in:
Damien Cassou 2023-03-19 11:28:02 +01:00 committed by Robert Helgesson
parent 2ddd4e151d
commit a8f5ca239f
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
5 changed files with 171 additions and 3 deletions

View file

@ -43,7 +43,10 @@ let
};
};
configModule = types.submodule {
configModule = types.submodule ({ config, ... }: {
config.location.extraConfig.exclude_from =
mkIf config.location.excludeHomeManagerSymlinks
(mkAfter [ (toString hmExcludeFile) ]);
options = {
location = {
sourceDirectories = mkOption {
@ -59,6 +62,18 @@ let
literalExpression ''["ssh://myuser@myrepo.myserver.com/./repo"]'';
};
excludeHomeManagerSymlinks = mkOption {
type = types.bool;
description = ''
Whether to exclude Home Manager generated symbolic links from
the backups. This facilitates restoring the whole home
directory when the Nix store doesn't contain the latest
Home Manager generation.
'';
default = false;
example = true;
};
extraConfig = extraConfigOption;
};
@ -120,10 +135,18 @@ let
extraConfig = extraConfigOption;
};
};
};
});
removeNullValues = attrSet: filterAttrs (key: value: value != null) attrSet;
hmFiles = builtins.attrValues config.home.file;
hmSymlinks = (lib.filter (file: !file.recursive) hmFiles);
hmExcludePattern = file: ''
${config.home.homeDirectory}/${file.target}
'';
hmExcludePatterns = lib.concatMapStrings hmExcludePattern hmSymlinks;
hmExcludeFile = pkgs.writeText "hm-symlinks.txt" hmExcludePatterns;
writeConfig = config:
generators.toYAML { } {
location = removeNullValues {