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

[feature request] Add support for viperML/nh #1044

Open
dtomvan opened this issue Feb 17, 2025 · 0 comments
Open

[feature request] Add support for viperML/nh #1044

dtomvan opened this issue Feb 17, 2025 · 0 comments
Labels
C-feature request New feature request

Comments

@dtomvan
Copy link
Contributor

dtomvan commented Feb 17, 2025

I want to suggest a new step

Which tool is this about? Where is its repository?

nh, the nix helper, used for updating nixos and home-manager through flakes

GitHub: https://github.com/viperML/nh

Found in nixpkgs at: https://github.com/NixOS/nixpkgs/blob/nixos-24.11/pkgs/by-name/nh/nh/package.nix

Related to #719 because nh relies on nvd and nom to improve UX. Read nh's README for a better elevator pitch...

A FLAKE=/home/user/nix-configuration is set to specify where the NixOS and home-manager configuration lives. nh picks this up and looks for configuration there, so you'll never need to manually specify where your config lives. This is useful for people who keep their nix dotfiles version-controlled in a flake.

Which operating systems are supported by this tool?

They only target NixOS-supported systems.

In their flake.nix they specify:

[
    "x86_64-linux"
    "aarch64-linux"
    # experimental
    "x86_64-darwin"
    "aarch64-darwin"
]

What should Topgrade do to figure out if the tool needs to be invoked?

Check wether $FLAKE exists, is a directory and contains a flake.nix. Then we know that a NixOS and/or home-manager configuration should live in that directory.

To check wether a NixOS configuration is present, you could parse the output of nix eval --json $FLAKE#nixosConfigurations --apply builtins.attrNames and look for $(hostname).

Example output of above command:

["tom-laptop", "tom-pc"]

To check wether a home-manager configuration is present, you could parse the output of nix eval --json $FLAKE#homeConfigurations --apply builtins.attrNames and look for an entry in the form of $(whoami)@$(hostname) or just $(whoami).

Example output of above command:

["tomvd@aurora", "tomvd@tom-pc", "alice"]

Which exact commands should Topgrade run?

  • When "$FLAKE" is a valid flake: nix --experimental-features "nix-command flakes" flake update --flake $FLAKE;
  • When we've found a NixOS configuration: nh os switch;
  • When we've found a home-manager configuration: nh home switch.

Does it have a --dry-run option? i.e., print what should be done and exit

nix flake update does NOT have --dry-run, but nh has --dry.

Does it need the user to confirm the execution? And does it provide a --yes option to skip this step?

  • nix flake update never asks for user input;
  • nh os switch never asks by itself unless you specify --ask, but requires a sudo password to actually finish the update;
  • nh home switch never asks for confirmation unless --ask is specified.

More information

I know how to test this feature if someone were to implement it. I am willing to do it myself though.

NOTE: where I specified any nix command it is a good idea to use nix --experimental-features "nix-command flakes" as in some systems this isn't enabled yet and nix will refuse to do anything with flakes when it isn't set.

@dtomvan dtomvan added the C-feature request New feature request label Feb 17, 2025
@dtomvan dtomvan mentioned this issue Feb 17, 2025
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature request New feature request
Projects
None yet
Development

No branches or pull requests

1 participant