Hdn: proof-of-concept tool for updating home.nix

Hello! I created a proof-of-concept tool that makes it easier to update your home.nix.

So far, you can run

hdn add pkgs.hello

and the tool will add pkgs.hello to your home.nix, and call home-manager switch. If home-manager switch fails, it will automatically roll back home.nix to its previous version.

I’m planning to make its output nicer and add a remove subcommand, but I’d love to hear what you all think about this idea first.

Also see the thread on r/nixos.

3 Likes

home-manager switch can fail for many reasons like no network or previous changes. Removing the package just because of that could often be unintended and does not allow to fix the underlying problem.

Thanks for the feedback. That’s a good point that home-manager switch can fail for many reasons.

However, I think that restoring home.nix to its previous state, without the added packages, is the least astonishing result.

If home-manager switch called from hdn add x failed because of no network, my thought process is that the user would fix their network, and then run hdn add x again. The user would be able to run it again because home.nix was restored to its state before the first run.

Another thing to consider is similarity to existing tools. When poetry add x fails, x doesn’t get added to pyproject.toml. It’s the same with cargo add x.

1 Like

I have all my nix files versioned under git, so for me personally not really, that’s a basic feature of all code I manage.

SnowflakeOS is trying to do astonishing things by parsing your existing config and being able to do edit it while at the same time retaining full customizability.

Pretty cool tool! I wasn’t aware of nix_editor, but that seems quite useful as well. Thanks!

Glad you found it cool! And yup, nix_editor proved to be useful.