nixpkgs.{system,localSystem,crossSystem} *values* are useless

Created on 4 Nov 2018  路  11Comments  路  Source: NixOS/nixpkgs

Issue description

Of course these options serve a purpose inside the nixpkgs.nix module, to set pkgs. However, these options tend to be used elsewhere, even though they are hard to use, leading to problems with cross compiled NixOS.

For this reason, I suggest that we make these config values unusable by providing an appropriate error message showing what else to do.

Why aren't they useful

system is a legacy option that will now tend to be set to its default, builtins.currentSystem.

localSystem will only consistently represent the system where stuff was built. This is typically not useful information, yet it is used erroneously in some modules.

crossSystem is meaningful, but is not always set.

What can we do

Maybe system can be fixed by inspecting options.nixpkgs.localSystem and options.nixpkgs.crossSystem. However, it is hard to reason about all possible uses of the module system and this feels like laying down a minefield for further changes to the nixpkgs.nix module.

A better solution seems to be to just treat these options as write-only. Users will set them and no other module than nixpkgs.nix can use its value. We can then, by means of an error message, direct module authors to the right value. This should probably be pkgs.targetPlatform. I don't think NixOS needs to provide its own way to determine its platform. pkgs can do that for NixOS just fine.

How to implement

Simply set all three options to private...

The module system does not yet have that option option, but it's almost there in #49766

Alternatives

Overhaul the nixpkgs options once more

So we ask people to set

  • nothing at all to use builtins.currentSystem
  • nixpkgs.targetSystem to set the system of the resulting NixOS
  • nixpkgs.hostSystem to set the system to build it on

Boils down to the same thing of course, but now we have a nixpkgs.targetSystem option that is actually useful.

I don't know how the old nixpkgs.system fits into this.
This means we'll need to reevaluate all the corner cases once more.
It will probably still confuse people and cause them to use nixpkgs.hostSystem which will then supposedly fail as it should by being null most of the time.

Most helpful comment

@roberth yes the crossSystem interface sucks for precisely the reason that there is no easy consistent way to get the build-time and run-time platforms.

@coretemp I did not invent such a thing. crossSystem already existed for years. I kept it around to not break existing documentation (at the time, the old wiki). I regret doing this; that documentation is little read now anyways.

Also, keep in mind that most of the work gone into cross compilation by me at least was reading undocumented interfaces, and then consolidating/deduplicating them. So we went from one internally inconsistent state with very little documentation to one mostly internally consistent state with some more documentation. Some things I kind of only want to document thoroughly once they are in a good enough state to not spill copious amounts of ink on a shitty interface I want flexibility to fix.


All that said, I think the solution is to change the arguments to Nixpkgs itself (with some sort of back compat provision) and then change the NixOS interface accordingly.

All 11 comments

I think the best move is to just replace theae usages with pkgs.buildPlatform and pkgs.hostPlatform. It would be niceto have a way to forbid these usages but i don鈥檛 know if it鈥檚 that useful for any other options.

I think the amount of time invested in the development of this feature (cross-compilation) along with the confusion it has created related to the documentation that comes with it is too high myself.

If you invest a few hundred hours in a feature, documenting it for at least 5 hours seems appropriate to me.

Hey coretemp. I too had to look up how to use the cross compilation and I understand your frustration. In particular I find the documentation for the distinction between a system string and { system : string, config : ? } and such lacking.

That said I do appreciate the amount of effort that it takes to work on a such a complicated project. I have been working on some improving some of the glue, like adding pkgs.nixos, and I find that the documentation is a significant part of the work. I imagine that the cross compilation is similar in this regard, except much much more involved. Because of its size, I understand that documentation has suffered, but I absolutely agree that it's not done until the documentation is in a good shape.

I am glad to see that you filed an issue, #49510. If there's anything else you think must be improved, please file another issue.

@roberth yes the crossSystem interface sucks for precisely the reason that there is no easy consistent way to get the build-time and run-time platforms.

@coretemp I did not invent such a thing. crossSystem already existed for years. I kept it around to not break existing documentation (at the time, the old wiki). I regret doing this; that documentation is little read now anyways.

Also, keep in mind that most of the work gone into cross compilation by me at least was reading undocumented interfaces, and then consolidating/deduplicating them. So we went from one internally inconsistent state with very little documentation to one mostly internally consistent state with some more documentation. Some things I kind of only want to document thoroughly once they are in a good enough state to not spill copious amounts of ink on a shitty interface I want flexibility to fix.


All that said, I think the solution is to change the arguments to Nixpkgs itself (with some sort of back compat provision) and then change the NixOS interface accordingly.

@matthewbauer I recall using pkgs.anything could cause infinite recursion problems maybe? That's why a proper fix would definitely be preferred.

It shouldn't in NixOS modules unless something very weird is going on. You have to use the final "pkgs" - not config.nipkgs.pkgs though.

I've found a couple usages of localSystem but it seems pretty rare (dysnomia and containers). Were there any others?

You have to use the final "pkgs" - not config.nipkgs.pkgs though.

Oh, ok. Well that would be great to use pkgs everywhere and fix remove system from https://github.com/NixOS/nixpkgs/blob/master/nixos/lib/eval-config.nix#L11-L12

@Ericson2314 OK, thank you for that clarification.

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.

We still pass around system in eval-config, so I think this is not stale..

just dropping a thought that was floating around in my brain:
nixpkgs.targetSystem, which is currently nixpkgs.crossSystem.system should probably be set by nixos-generate-config in hardware-configurationx.nix since its a static property of the target system.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vaibhavsagar picture vaibhavsagar  路  3Comments

teto picture teto  路  3Comments

chris-martin picture chris-martin  路  3Comments

tomberek picture tomberek  路  3Comments

langston-barrett picture langston-barrett  路  3Comments