Skip to content
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

Best way to extract dotfiles from home-manager? #1658

Closed
colinxs opened this issue Dec 16, 2020 · 4 comments
Closed

Best way to extract dotfiles from home-manager? #1658

colinxs opened this issue Dec 16, 2020 · 4 comments

Comments

@colinxs
Copy link
Contributor

colinxs commented Dec 16, 2020

Issue description

I'd like to backup the dotfiles generated by home-manager. Looking at the source, it appears all the generated symlinks point to files in the home-files package so I could just backup this directory. I'm hesitant to depend on an internal API, however. Is there another way to get a list of all files managed by home-manager so I can back them up?

Thanks!

Meta

Maintainer CC

Technical details

  • system: "x86_64-linux"
  • host os: Linux 5.6.0-1020-oem, Pop!_OS, 20.04 LTS
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.3.9
  • channels(root): "nixpkgs-21.03pre258115.8006772a054"
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixpkgs
@cole-h
Copy link
Member

cole-h commented Dec 16, 2020

I'm curious as to why you'd rather back up the files rather than the config that generated those files. It seems like a better idea to just backup your home.nix (and whatever else it imports) than to somehow enumerate all home-files and back those up.

@peterhoeg
Copy link
Collaborator

I'm with @cole-h on this - the output really doesn't matter so I don't really see the point in this. But just in case you really do want it, you can wire up a script that does something like this:

  1. get the path to the most recent generation in the nix store: home-manager generations | head -n1 | gawk '{ print $7 }'
  2. copy out the contents of home-files inside that directory

@colinxs
Copy link
Contributor Author

colinxs commented Jan 20, 2021

Hey all, sorry for the late reply. I somehow stopped getting GitHub notifications.

Right now I'm doing:

home.activation.copyHomeFiles = let
  src = config.home-files;
  dest = home.homeDirectory + "/home-files";
in lib.hm.dag.entryAfter [ "installPackages" ] ''
  rm -rf ${dest}
  rsync -ah --copy-links --chmod=D755,F664 --quiet ${src}/ ${dest}
'';

Which is relying on the internal option home-files. Is this fairly safe to rely on or do you expect it to change?

Ideally it would be nice to have to have a command home-manager files that is similar to home-manager packages but lists all managed/modified files (either dotfiles or dconf settings). Even better if it showed which modules were responsible for which dotfiles. Of course that takes time to implement :).

Thanks for the help!

@rycee
Copy link
Member

rycee commented Jan 20, 2021

FWIW. I do something like

hmFilesIgnorePatterns =
  concatStringsSep "\n"
  (map (file: "ignore = Path ${file.target}")
  (filter (file: !file.recursive)
  (mapAttrsToList (_: file: file) config.home.file)));

and include hmFilesIgnorePatterns in a Unison configuration I use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants