-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Extend the flake / cli interface with a function for system-specific attributes #7709
Comments
A good starting point would be to have the list of supported systems be part of the flake metadata. That way, it becomes inspectable with {
systems = ["x86_64-linux" "aarch-64linux"];
outputs = { self, nixpkgs, ... }:
{
# system would be attached to `self`
packages = nixpkgs.lib.genAttrs self.systems (system: /*...*/);
};
} I think your proposal is also nicely complementary to this one. |
Team discussion: we've agreed that we want to experiment with function-like behavior for these attributes under a new feature flag. |
Note from the team discussion: It would be nice to have a functor-like interface for having attrset-like objects that are implemented by functions, i.e. allowing dynamically computed sets of attributes. Something like:
where This way, a flake attribute like
|
A dynamic attrset would be a fairly large and powerful change, beyond the scope of this issue. Is this something feasible to add to the language without breakage? On its own it would provide a new avenue to expose better interfaces to users, at the cost of a complex feature. (Though I’d love to explore the consequences!) Edit: Proof-of-concept: master...flox:nix:dynamic_select |
One problem I've been thinking about a lot recently, as I've been working heavily on cross-compilation, is that increasingly, Nixpkgs supports platforms that cannot be expressed as simple strings, but Nix hasn't really kept up with this. For example, how are we going to express With non-Flakes Nix, Nixpkgs can support these custom platforms just fine. They're easy to use with |
@tomberek maybe open an issue or draft pr? A possible half-way point is to have a schema and/or convention that allows any By changing the implicit CLI expression to something like the following, we could immediately solve the cross problem for expressions that need cross. (leaving the CLI question somewhat unanswered for now, which might be desirable for this issue?) # nix build installable =>
with calledOutputs;
(configure { system = system; }).packages.${installable} This way, a flake expression can also accept a custom nixpkgs: {
outputs = { nixpkgs, ... }: {
configure = { system, pkgs ? nixpkgs.legacyPackages.${system} }: {
packages.installable = pkgs.stdenv.mkDerivation ...;
};
};
} Benefits:
Potential percieved disadvantages:
Maybe relevant; flake-parts already benefits from treating |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/nix-systems-externally-extensible-flake-systems/27110/9 |
This platform/system issue is the sole reason I haven't really adopted flakes, so I'm really glad to see it being discussed seriously (and if it takes 10 years then so be it; I'm totally in support of the team ensuring this done right rather than done quick). Correct me if I'm missing one but I believe the current goals/design-constraints are:
@alyssais Challenge accepted! I think I have a structure (and lots of viable variations) for you that meets all the goals, and does it without functions. For a moment, imagine an alternative to
The list order matters, and the systemMatch is just checking if it's a valid subset of the host (or cross compile target). Meaning if someone put With one extension, we can make this interface handle custom system/platform checks. We can do it using derivations:
How that might look;
I believe this meets all the design constraints, and is a balance between the 100% non-lazy approach (a function with a system argument), and the very-lazy but non-extensible/flawed-enumeration approach ( |
Is your feature request related to a problem? Please describe.
The flake schema suggested by the flake / cli interface has two usability problems
Describe the solution you'd like
From what I read and recall from the discussion of #6773 (comment), we were close to an agreement to extend the cli instead of the flake core.
Compared to that PR
E.g. instead of searching only
packages.${system}.${installable}
legacyPackages.${system}.${installable}
${installable}
... we could search:
(perSystem system).packages.${installable}
(perSystem system).${installable}
packages.${system}.${installable}
legacyPackages.${system}.${installable}
${installable}
... or:
getPackage system installable
if not null(getPackages system).${installable} or null
if not nullpackages.${system}.${installable}
legacyPackages.${system}.${installable}
${installable}
The latter search path allows for optimal laziness, which is most relevant for non-trivial flakes that use a framework, while also supporting enumeration for
nix flake show
and CI.TODO
nix flake show
work, by invoking for the current systemnix flake show --for-supported-systems
work, by querying an new output attributesupportedSystems
Describe alternatives you've considered
Bad implementation ideas:
packages
as a function. This does not allow a flake to be compatible with both calling conventions, breaking compatibility with previous cli versions and (worse) breaking compatibility with flakes using the flake as a dependency.Not really acting on the issue:
Only fix the "exotic system" problem by trying to convince users to implement a non-cli schema on their own. This will fail because there is little incentive, and no easy way to test correctness.
Only fix the enumeration problem by making all flakes regurgitate a list that Nixpkgs provides. This is only fixes half of the problem and makes apparent set of supported systems completely useless.
Additional context
Add any other context or screenshots about the feature request here.
Priorities
Add 👍 to issues you find important.
The text was updated successfully, but these errors were encountered: