Keeping dotfiles with /usr/share compatible with other distros

Hi! I’m new to NixOS and trying to figure out how to deal with my dotfiles that are linking to /usr/share.

For the foot terminal, I have include=/usr/share/foot/themes/kitty in my config and for sway I have output * bg $(find "/usr/share/backgrounds" -type f | shuf -n1) fill to set a random wallpaper.

I have installed the nix packages for foot, foot.themes and gnome.gnome-backgrounds.

My goal is to keep my dotfiles distro-agnostic, so I’d like to not migrate them to home-manager or have custom ones for NixOS, just configure the base system with Nix and have it work. Is there any way to achieve this?

I’ve experimented with environment.pathsToLink that I found here, thinking that I might be able to symlink afterwards, but I’ve not even been able to get the files to show up under /run/current-system/sw/.

You could use variables to set the correct path instead. To be truly distro-agnostic you’ll likely have to do that anyway.

I’d suggest you either:

  • Configure both of these with nix, and substitute the paths with something like:
    ${if config.isNixOS then "${pkgs.gnome.gnome-backgrounds}/share/backgrounds" else "/usr/share/backgrounds"}
    
    config.isNixOS isn’t a real option, of course, more likely you’ll have to case on whether you’re using home manager or NixOS.
  • Configure an environment variable with environment.variables and home.variables, and set it correctly for each host you deploy to, then use that in the kitty/foot config to find the paths you’re looking for.