-
-
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
Provide builtins.currentSystem as a input to flakes or make system a parameter #3843
Comments
cc @zimbatm who is involved in flake-utils |
Not passing in
|
There are multiple usability issues with the current design: The list of supported systems is currently internal to the flake. As a flake author, it is useful to be able to specify which systems are supported. As a flake user, it means that it is not possible to change that list without forking the repository. Especially once the flake ecosystem starts to grow, it will quickly become prohibitive to introduce new platforms. The amount of boilerplate that is needed to specify all the permutations of systems for all the derivations. That's why I wrote flake-utils, to make that usage a bit less cumbersome. The outputs are mixing both system-dependent and independent keys so it's not as easy as passing the Typing Each flake ends-up re-initializing nixpkgs. This adds to the boilerplate and evaluation time. One possibility would be to introduce a new {
description = "Usability flakes";
systems = [ "x86_64-linux" "x86_64-darwin"];
inputs = {}; # nothing changes here
# system-independent outputs
exports = inputs: {
nixosConfiguration = {};
overlay = final: prev: {};
lib = {};
};
# system-dependent outputs
outputs = system: { self, nixpkgs, ... }@inputs:
let
# I don't have a good idea to avoid that boilerplate
pkgs = import nixpkgs {
# Notice that the overlay is accessible via `self`
overlays = [ self.overlay ];
inherit system;
};
in
{
packages.hello = pkgs.hello;
apps = {};
};
} One of the use-case that this design prevents is combining the derivations of multiple systems. This is for example if you want to create a release tarball that includes multiple architectures. In practice, that kind of construct is quite difficult to build outside of CI systems which have all the archs attached as remote builders. |
Another possibility is that |
Could we recognise the usefulness of ternary logic known-good/known-broken/unsure? The less overhead there is in checking whether something never-tried works due to upstream efforts, the better information we will have available. |
The original RFC states:
Is my assumption correct, that the idea of exposing I'm looking for exactly that use case. I'd like to expose a function that produces a python derivation, given a set of constraints.
With this trick, it's already possible to build constructs which allow passing arguments (kind of). Why not support it properly? |
No, you can definitely have library functions as flake outputs. You just can't call them from the command line.
See my comment above. Having said that, the |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/flakes-with-unfree-licenses/9405/1 |
Flake outputs are a mixture of system-dependent and system-independent sets, and flake-utils doesn't do much to distinguish one from the other. Because of that, the `age` NixOS module currently has to be acessed as `agenix.nixosModules.${system}.age`, rather than the documented `agenix.nixosModules.age`. To remedy that, (conceptually) split `outputs` in two, let flake-utils handle the system-dependent half, and merge them to form the actual outputs. The names for the two halves were taken from [1]. Since someone may already be using the current paths, use the singular `nixosModule` output, so it can be accessed as `agenix.nixosModule`. [1]: NixOS/nix#3843 (comment)
Flake outputs are a mixture of system-dependent and system-independent sets, and flake-utils doesn't do much to distinguish one from the other. Because of that, the `age` NixOS module currently has to be acessed as `agenix.nixosModules.${system}.age`, rather than the documented `agenix.nixosModules.age`. To remedy that, (conceptually) split `outputs` in two, let flake-utils handle the system-dependent half, and merge them to form the actual outputs. The names for the two halves were taken from [1]. [1]: NixOS/nix#3843 (comment)
I have similar problem as @DavHau, I'd like to give users of my flake the ability to compile firmware from the command line. The ideal UX is that one would write a config file, describing the build for the build system of the original project and then a derivation would be built, which would contain just the resulting What's the alternative? |
What format is the config file in? |
it's Kconfig, the kernel like build config |
I wrote a proposal without knowing about this issue. @Mic92 pointed me to it later on and it's interesting to observe that I've come to the same conclusions. |
I strongly support the idea of making the I think the current design has a really good thing though, in that it’s conceptually very simple (the only part of the Nix codebase that has to know about the notion of a flake “system” is the cli shortcut that expands (commenting here on @domenkozar's doc because I can't comment inline on it)
I guess you'd need a way to override the
Then that leaves the problem that “The list of supported systems is currently internal to the flake” (Edit: you use
Maybe it’s the case (need to think it a bit more), but this only holds as long as Nix can generate a system-independent lockfile (because it would be pretty bad if the lockfile couldn’t be shared between two different systems)
That bit isn't really clear to me: If
I don’t think it’s really easier to parallelize this than the current version. The blocker in both cases is that the evaluator isn’t reentrant. |
Maybe a (relatively) small change to solve the problem of systems being hardcoded in a flake (which might also solve other issues) would be to allow raw Nix values as input for a flake (this shouldn’t mess-up caching as long as these values end-up in the lockfile). Then we could have a convention that flakes accept a That does in a way add yet-more-convention and doesn’t do anything for reducing the boilerplate so I’m not sure it’s a good idea as-it-is, but there might be something to build on top of that. |
Thanks for putting it so succinctly!
That's because it pushes most of the questions to the writer of the flake. I consider that a con, because things have to be implemented over and over again.
It wouldn't be an output, but you'd declare it as a setting for the input itself - evaluating the same input for different systems. I'll update the document to clarify this.
It gives the space for warning the user that the system isn't supported by the flake, instead of getting an attribute error. That seems quite an improvement for the experience.
Looking at the lockfiles (there's, unfortunately, no documentation about them), what does
It would mean you can evaluate the flake for all given systems, for example on a CI to make sure everything evaluates.
It's parallelizable because one needs to pass system as an input, so when evaluating for more than one system, that's one evaluation per system.
That will relative flakes would really go a long way with modularity. I'd still make
Yes, this design change is "convention over configuration" applied to dealing with |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: |
I agree with the gist of this change. The larger issue though is Flakes is constantly lagging behind idioms in Nixpkgs that have been polished over the years. For example:
We could incorporate all this stuff in Nix for Flakes, but that leaves Flakes quite brittle when we can and do refine this stuff from time to time in Nixpkgs. Or maybe we should implement more of Flakes in Nix. Factoring out |
Maybe the
That's basically correct. The flake file format doesn't impose a lot of requirements on what the output attributes of a flake are. Thus it can accommodate whatever idioms regarding systems/platforms we may come up with in the future. (This is also why we shouldn't have a OTOH, various tools can define "well-known" flake output attributes, e.g.
The semantics of those attributes are determined by the tools that operate on them. You can't just change the meaning of |
Lock files are documented here: https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-flake.html#lock-files
The current hydra-evaluator is already parallel. Having to deal with a |
I understand what you are arguing for, but I am confused because to me it seems like this might at odds with the goals of nix flakes as declared in the abstract of the RFC
So "standard structure" is indeed only to be understood as "something to manage inputs / lockfile" as @Ericson2314 put it above? |
@tobiasBora The proposed Nixpkgs "problem" infrastructure could perhaps be used for this purpose. It wasn't specifically design for this, but it seems that it could be made to work well outside Nixpkgs as well. It's currently in development at: |
I've renamed this issue to hint at an alternative that is less contradicting to the requirements suggested in the first response. Suggestions have been made to solve this by
We can change this back to a discussion about a single solution if you prefer, but otherwise I think this issue is representative of roughly the requirements
|
This issue has been mentioned on NixOS Discourse. There might be relevant details there: |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: |
I would love never having to lookup the correct string for my system ever again (an absurd bit of busywork). Whatever you need to do to make this happen, go ahead. |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-09-25-nix-team-meeting-minutes-89/33489/1 |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/flake-design-of-system-os/36654/4 |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/flake-design-of-system-os/36654/7 |
- Simplifies the whole thing due to not having to mess with `system`, see NixOS/nix#3843 - Makes the lockfile _way_ smaller, see NixOS/nix#7730
- Simplifies the whole thing due to not having to mess with `system`, see NixOS/nix#3843 - Makes the lockfile _way_ smaller, see NixOS/nix#7730
I did this in my flake, would this work?:
I can't build it since I am still making my flake, could someone test |
If ¹: harm => ability to use the wrong variable + the usual reasons for Interface Segregation. Example: accidental use of the "impure" |
Would something like this work?:
|
@JumpIn-Git Sorry to be a bit crude, but please be more respectful of people's time and attention. This thread is for discussing development of Nix, with many busy people subscribed to it, making your untested support-level questions not a great fit. For somebody relatively new like you I suggest the main Nix/NixOS Matrix room instead, but even there you're expected to spend more effort before asking, among other common etiquette. |
huh? what i am asking is related to this subject; those values give the current system |
@JumpIn-Git This thread is not a support forum, please ask on discourse.nixos.org or the mentioned matrix room. Anyway to get back on topic about the requirements:
Ultimately IMO this points to the need for changing the structure of (currently system-dependent) flake outputs. Instead of Instead, couldn't we leave the tasks of specifying and constraining systems to nixpkgs? We already have And more to the point, why should
I disagree, or in any case, we are already in that situation today since we're picking the system presumably out of thin air from the CLI. Whereas in consuming flakes, it makes sense to ensure that system is effectively passed to the derivation via the same mechanisms which we control nixpkgs instances' platforms today.
I don't have a good answer for this one, but I think we should be able to come up with something less clunky than the current outputs structure... |
I don't think it was a support question, but unfortunately you cannot use |
Sure, provide it as an arg when you import |
Is your feature request related to a problem? Please describe.
Right now one has to explicitly define system in flake outputs.
The nix flake itself already comes with boiler code like this:
I think having to use that much code hurts portability of the ecosystem because people
will only specify the minimum and there seems no easy way of overriding it without changing the
flake itself.
Describe the solution you'd like
Describe alternatives you've considered
Use boilercode in every project or rely on external libraries like https://github.com/numtide/flake-utils
If someone needs to explicitly specify platforms i.e. to build packages for different architectures with hydra this should be still possible.
The text was updated successfully, but these errors were encountered: