-
-
Notifications
You must be signed in to change notification settings - Fork 172
Description
Prerequisites
- I have searched existing issues to make sure this isn't a duplicate
- I have checked the documentation to see if this feature already exists
Problem Description
Currently the recommended way to use nixos-anywhere is with flakes. Many people prefer avoiding flakes for a variety of reasons, and there are good alternatives such as npins. Nixos-anywhere has a documented way of being used without flakes, but the command is a little unintuitive and unnecessarily verbose:
nixos-anywhere --store-paths $(nix-build -A config.system.build.diskoScript -A config.system.build.toplevel --no-out-link) root@machine
whereas flake usage:
nixos-anywhere --flake .#myconfig nixos@fec0::5054:ff:fe12:3456
Proposed Solution
I would like an ergonomic option for the non-flake based approach. Both nix-build
, nixos-rebuild
and nh
support this approach.
The way it's done with nh is very concise and easy to use, the argument is -f, --file <FILE> [ATTRPATH]
so the full command would be nh os switch -f . <attribute-name>
.
The standard nix cli tools support argument --attr ⟨#opt-attr⟩ / -A attrPath
so with the same setup it would be nixos-rebuild switch -A <attribute-path>
and if the file path also needs to be provided it's slightly more complicated.
I think the best solution would be if nixos-anywhere
could support the same arguments as the standard cli for selecting the file and attribute in a concise way, and wrapping the less intuitive command with that, so something like:
nixos-anywhere -A myconfig root@machine
Alternatives Considered
If it's not possible to support the same style as the standard nix cli, nh's approach would be also fantastic - nixos-anywhere --file . myconfig root@machine
, or the flake-like representation could also be used, for example nixos-anywhere --non-flake .#myconfig root@machine
, but these would be less intuitive for a nix cli user.
Feature Type
New command-line option
Use Case
In case of a non-flake based setup, eg. dependencies managed by npins, people would typically have a default.nix that has an attribute, which contains the NixOS configuration, similar to a flake. Example here.
myconfig = nixos {
specialArgs = { inherit disko; };
pkgsPath = sources.nixpkgs;
system = "aarch64-linux";
configuration = ./hosts/mymachine;
};
This type of setup should have first class support with nixos-anywhere.
Implementation Ideas
If -A is one of the arguments when the CLI is invoked (and --flake isn't), it could automatically expand to do the same as:
nixos-anywhere [all other arguments forwarded] --store-paths $(nix-build -A <attr>.config.system.build.diskoScript -A <attr>.config.system.build.toplevel --no-out-link) root@machine
Additional Context
No response