Skip to content

flake.lib.nixosSystem: Allow nixpkgs.system to be set modularly; improve error message - #177012

Merged
infinisil merged 5 commits into
NixOS:masterfrom
hercules-ci:nixos-modular-system
Aug 1, 2022
Merged

infinisil merged 5 commits into
NixOS:masterfrom
hercules-ci:nixos-modular-system

Conversation

@roberth

@roberth roberth commented Jun 9, 2022 •

Copy link
Copy Markdown
Member
Description of changes

Got a question today from someone who wanted to set nixpkgs.system modularly in a flake. They thought the system argument 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.nix but weren't implemented, presumably because of compatibility concerns.

Note that this is a simplification of the nixosSystem interface, relying on established options rather than repeating parameters for no good reason. The implementation could eventually be simplified too, by extracting a new entrypoint from eval-config.nix, similar to how eval-config-minimal.nix was extracted. I'm not doing that here because that would be a distraction.

The new error message when system is forgotten is:

nix-repl> (lib.nixosSystem { modules = [ { } ]; }).config.system.build.toplevel
error: The option nixpkgs.system has not been set. Please set it, or set nixpkgs.hostPlatform instead. Note that nixos-generate-config will set the latter for you in hardware-configuration.nix.

the old message was

error: attribute 'currentSystem' missing
Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 22.11 Release Notes (or backporting 22.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@roberth
roberth requested review from infinisil and nbp as code owners June 9, 2022 10:00
@github-actions github-actions Bot added the 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS label Jun 9, 2022
@ofborg ofborg Bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Jun 9, 2022
@roberth
roberth force-pushed the nixos-modular-system branch from 2e421e6 to 0807f11 Compare June 25, 2022 09:03
@github-actions github-actions Bot added the 8.has: module (update) This PR changes an existing module in `nixos/` label Jun 25, 2022
@roberth
roberth force-pushed the nixos-modular-system branch 2 times, most recently from 336d0b5 to 3b8bf4a Compare June 28, 2022 08:20
Comment thread nixos/modules/misc/nixpkgs.nix Resolved
Comment thread nixos/modules/misc/nixpkgs.nix Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be "The option system has been set, please set hostPlatform instead"?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@roberth roberth Jun 28, 2022 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread nixos/modules/misc/nixpkgs.nix Outdated
Comment on lines 296 to 317

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@roberth
roberth requested a review from infinisil June 29, 2022 08:57
@roberth roberth changed the title flake.lib.nixosSystem: Allow nixpkgs.system to be set; improve error message flake.lib.nixosSystem: Allow nixpkgs.system to be set modularly; improve error message Jul 1, 2022
@roberth roberth mentioned this pull request Jul 9, 2022
3 of 13 tasks

@alyssais alyssais left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@roberth
roberth force-pushed the nixos-modular-system branch from c8dd0c0 to b397a84 Compare July 10, 2022 11:21

@alyssais alyssais left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs some squashing before being merged.

roberth added 5 commits July 10, 2022 13:35
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.
@roberth
roberth force-pushed the nixos-modular-system branch from b397a84 to acd969a Compare July 10, 2022 11:40
@roberth

roberth commented Jul 10, 2022

Copy link
Copy Markdown
Member Author

Needs some squashing before being merged.

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).

@infinisil infinisil left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants