Repository navigation
flake.lib.nixosSystem: Allow nixpkgs.system to be set modularly; improve error message - #177012
Conversation
2e421e6 to
0807f11
Compare
336d0b5 to
3b8bf4a
Compare
There was a problem hiding this comment.
Shouldn't it be "The option system has been set, please set hostPlatform instead"?
There was a problem hiding this comment.
Setting system is still valid for now, as we can't start an ecosystem-wide change without first making the new way widely available. Even adding a warning will cause annoyance as 2nd-party repos can not implement the change without breaking 22.05 support. So this will take time. We can consider this for 23.05, and unstable in January when 22.05 is EOL.
I've put in place migration logic for such changes, but I didn't use it here because the implementation is complicated enough as it is. See NixOS/release-wiki#31.
We could add such a warning in advance with isInOldestRelease, but I'm hesitant to automate this before this has ecosystem support.
There was a problem hiding this comment.
I'm mainly asking because of the sentence itself, which doesn't make sense to me. If it's complaining about system not being set, then the natural solution would be to set system. The sentence only makes sense to me if you remove the first "not".
There was a problem hiding this comment.
Ok, just pushed this
- default = throw ''The option ${opt.system} has not been set. Please set ${opt.hostPlatform} instead. Note that nixos-generate-config will set it in hardware-configuration.nix.'';
+ default = throw ''The option ${opt.system} has not been set. Please set it, or set ${opt.hostPlatform} instead. Note that nixos-generate-config will set the latter for you in hardware-configuration.nix.'';It does not advise which one to choose yet, as either one is currently valid for the reasons mentioned before.
There was a problem hiding this comment.
Diffs render on one line, so here a readable version
The option ${opt.system} has not been set. Please set it, or set ${opt.hostPlatform} instead. Note that nixos-generate-config will set the latter for you in hardware-configuration.nix.
There was a problem hiding this comment.
@infinisil Could you review again?
I've taken into account your feedback that it's ok to set system.
Setting hostPlatform is the default solution for an unset system in the case of nixos-generate-config-based configurations, so this should be mentioned. Eventually we can deprecate system and get rid of this complexity.
The new message is:
The option nixpkgs.system has not been set. Please set it, or set nixpkgs.hostPlatform instead. Note that recent versions of nixos-generate-config will set the latter for you in hardware-configuration.nix.
There was a problem hiding this comment.
Maybe we could explain when somebody would want to use one or the other? In particular, push people towards setting hostPlatform if they don't need to support 22.05? Otherwise, people will see this message, set nixpkgs.system because it's the first thing mentioned, then have to change it again when we deprecate nixpkgs.system. We could save them that trouble by encouraging them to use hostPlatform if they don't need 22.05 support.
There was a problem hiding this comment.
Yeah I was trying to be too conservative (and too concise for that matter). The new message is:
error: Neither nixpkgs.hostPlatform nor or the legacy option nixpkgs.system has been set.
You can set nixpkgs.hostPlatform in hardware-configuration.nix by re-running
a recent version of nixos-generate-config.
The option nixpkgs.system is still fully supported for NixOS 22.05 interoperability,
but will be deprecated in the future, so we recommend to set nixpkgs.hostPlatform.
flake.lib.nixosSystem: Allow nixpkgs.system to be set; improve error messageflake.lib.nixosSystem: Allow nixpkgs.system to be set modularly; improve error message
There was a problem hiding this comment.
I'm trying to get us out of the business of passing system doubles around inside Nixpkgs, because not all platforms Nixpkgs supports can be expressed with a double. It looks like this change only affects the entry point to NixOS, and will actually make it easier for a flake user to set e.g. localSystem.config = "x86_64-unknown-linux-musl"; (this would also be important for all of the various ARM ABI variants), so this seems to be a step in the right direction.
Deprecating the system argument to eval-config.nix is definitely a good step, and something I was planning on proposing soon myself!
c8dd0c0 to
b397a84
Compare
alyssais
left a comment
There was a problem hiding this comment.
Needs some squashing before being merged.
localSystem is ill-defined because unlike hostPlatform, its meaning is different in a cross or non-cross context.
The ${opt.*} syntax will print the full path when NixOS is used
as a submodule.
nixpkgs.system / nixpkgs.localSystem must not be read by any
other module because its meaning is ambiguous in cross vs
non-cross contexts. hostPlatform is generally what you need.
*Where* you build something generally doesn't matter in a
system _configuration_ context like NixOS.
b397a84 to
acd969a
Compare
Done. I find the remaining commit boundaries to be useful, as they form a build-up from low-level possibility to having the option to recommending it (subtly for the time being). |

Description of changes
Got a question today from someone who wanted to set
nixpkgs.systemmodularly in a flake. They thought thesystemargument was the only way to set it, which it is not.This is change is in line with the improvements that were intended for
eval-config.nixbut weren't implemented, presumably because of compatibility concerns.Note that this is a simplification of the
nixosSysteminterface, relying on established options rather than repeating parameters for no good reason. The implementation could eventually be simplified too, by extracting a new entrypoint fromeval-config.nix, similar to howeval-config-minimal.nixwas extracted. I'm not doing that here because that would be a distraction.The new error message when
systemis forgotten is:the old message was
Things done
sandbox = trueset innix.conf? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)nixos/doc/manual/md-to-db.shto update generated release notes