Install dotfiles on NixOS system with a script

Hi everybody,
I’m new here and new to nix/nixos and I have what is probably a silly question. I have my own dotfiles in a GitHub repo, where I mostly have my zsh settings. I don’t want to convert those to be nix/home-manager because I have to keep installing them in systems in which I don’t have or can’t have nix and I don’t want to duplicate them. At the same time, I’d love to “install” those to a NixOS installation I have without having to manually run a script. Do you have recommendations on how to do so?

Thank you very much in advance!

1 Like

You could use home.file to install the files verbatim in a home-manager setup, and they’d still be compatible with a non-home-manager setup elsewhere.

@tejing thanks, Appendix A. Configuration Options is what you refer to, right? Would you be able to give me pointers on how to also download the repo so that I can copy it with home.file?

Yes. And when copying a directory like that, you likely want to set home.file.<path>.recursive = true; so that it recursively symlinks the files from the nix store rather than symlinking the entire directory. This allows other files to be inserted into the directory structure at runtime.

I would probably use pkgs.fetchFromGitHub to retrieve the repo. There’s also builtins.fetchTree, which is useful if you want to load nix code from github without requiring import-from-derivation, but for this, it should be fine to use a derivation-based fetcher.

1 Like

Thanks a lot, I will give this a try and report back what works for me.