omerxx / dotfiles

My dotfiles synced from localhost and remote machines
https://dotfiles.omerxx.com
1.17k stars 96 forks source link

Wrap your dotfiles with nix #10

Open adrian-gierakowski opened 6 months ago

adrian-gierakowski commented 6 months ago

so that people could reproducibly instantiate it on their system with a single command

omerxx commented 6 months ago

@adrian-gierakowski that's a great idea, I still don't consider myself a Nix pro so don't want to break anything for others. What you have in mind is a flake with the configuration and something like stow for symlinking?

adrian-gierakowski commented 6 months ago

What I had in mind was a home-manager configuration with all the programs and their configs.

I’ll be willing to pair on this as I’m fairly experienced with nix and I’m keen to learn about some of the tools you’ve got here.

rafaeloledo commented 3 months ago

@adrian-gierakowski Hello, i'm using nixos and home-manager for about 2 months. My current problem with the hm is that i want to replicate my dotfiles inside VMs. I've thought about backing up the config files from home-manager's output, but it has some nix-store paths. It seems that nix home-manager is a tool that makes me depend to use it on every distro, that is some that i don't want. It that the purpose? I've tested right now the stow solution and seems more easy to adapt between any kind of distros. Then, i just activated my i3 and hyprland setup with nixpkgs prefix inside nixos modules barebones.

It'll be nice if anyone can explain how can i use home-manager inside nixos without needing to re-use it on every place to avoid maintaing dotfiles twice.

adrian-gierakowski commented 3 months ago

You can use home-manager on any distro. But it only makes sense if IMHO if you are also using nix\HM on those distros to manage what software is installed. The benefit of this is that you not only ensure that the app configs are the same across those systems, but that the apps\binaries themselves are also the same.

You can obviously use stow on NixOS if you don’t want to use HM everywhere, but you are just making more work for yourself IMHO

adrian-gierakowski commented 3 months ago

@rafaeloledo may I ask what you’d want to avoid using nix\HM everywhere? IMHO it’s the only sane solution if you want to keep things in sync across multiple systems

rafaeloledo commented 3 months ago

@adrian-gierakowski Since i don't want to depend strategically only on chace.nixos.org, i try to avoid keeping 100% of my workflow on it. It's a personal choice considering i'm not a source-and-compile user. I'm not saying the cache is not solid or anything, i just don't want to be in a state of awareness and keep concerns on my head on the current state of fundings. Just pick a strategy and forget it.

I saw that i can set a private cache in a local server on the wiki, i'm consindering doing this on future to resolve this dilemma. For now, stow's solution doesn't lock you on a binary provider.

Other solution that nix and hm ecossystem can adopt is making an api to backup the config files in their original form offline dereferencing the nix-store paths and symlinks (i don't know if it's possible). I think is a good option to people feel more secure on using nix in the long-term.

adrian-gierakowski commented 3 months ago

You can use home.file for arbitrary files which can be sourced from current dir in a git repo and will be copied to nix store and then symlinked to chosen path in your home dir. If you use this exclusively you can manage your dotfiles without accidentally “polluting” them with nix store paths. Although you’d be foregoing all the best parts of home manager so maybe better to just use stow instead (note that I know nothing about stow)

rafaeloledo commented 3 months ago

I think it's a good balance. Creating another abstraction layer inside home-manager API is not a good selling point for me. Using home.file, i can leverage the generations if i break something and not use stow (avoiding the extra work as you've mentioned). The only downside is creating additional copies in nix-store which i can garbage-collect afterwards.

Thanks.

Note:

@omerxx is using at commit fffac07 this kind of solution too

image

rafaeloledo commented 3 months ago

@adrian-gierakowski I had some problems setting my neovim like above. When i update the lazy-lock.json file it complains that's root permissions and read-only like this:

image

So, i've reached this discussion: https://github.com/nix-community/home-manager/issues/676 Thanks to IgorGee.

It appears that hm has a way to create an exception and now i can link integrally outside of nix-store normal constraints and got this:

image

Simply, i've followed the example above and use this internal home-manager's function

image