-
-
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
Flake arguments #2861
Comments
Will need to handle the |
A command like $ nix run nixpkgs#hello will now build the attribute 'packages.${system}.hello' rather than 'packages.hello'. Note that this does mean that the flake needs to export an attribute for every system type it supports, and you can't build on unsupported systems. So 'packages' typically looks like this: packages = nixpkgs.lib.genAttrs ["x86_64-linux" "i686-linux"] (system: { hello = ...; }); The 'checks', 'defaultPackage', 'devShell', 'apps' and 'defaultApp' outputs similarly are now attrsets that map system types to derivations/apps. 'nix flake check' checks that the derivations for all platforms evaluate correctly, but only builds the derivations in 'checks.${system}'. Fixes #2861. (That issue also talks about access to ~/.config/nixpkgs and --arg, but I think it's reasonable to say that flakes shouldn't support those.) The alternative to attribute selection is to pass the system type as an argument to the flake's 'outputs' function, e.g. 'outputs = { self, nixpkgs, system }: ...'. However, that approach would be at odds with hermetic evaluation and make it impossible to enumerate the packages provided by a flake.
I think this will make the adoption of new systems more difficult as each flake has a hard-coded list of supported systems. Would it be bad to add a top-level |
Alternatively to @zimbatm's comment, I'd be fine with having forAllSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" "x86_64-darwin" "i686-linux" "aarch64-linux" ] be a provided function somewhere, that could work on a series of groups. |
I guess if the flake depends on nixpkgs, then we could have nixpkgs export a |
I realize that the issue of specifying system has (sort of) been resolved, but afaik there is still no way to pass arguments to flakes. I guess its very hard to make arguments work with the sort of hermetic, pure environment that flakes strives to acheive. Not being able to pass any arguments is a pretty huge compromise though. |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/passing-options-to-flakes/7579/3 |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/creating-an-sdimage-with-nix-build-nixpkgs/19298/1 |
Can we reopen this? As things are RN, it's very hard to parametrize a flake, which seems very limiting. The use case I have at hand is - I'd like to use a I tried to make a I guess the last resort is to wrap the whole |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/what-would-you-like-to-see-improved-in-nix-cli-experience/24012/22 |
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: https://discourse.nixos.org/t/how-can-we-pass-argument-to-flake-nix/30833/2 |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: |
Could someone point me to an explanation on why this issue has been closed? Has it been replaced by some other issue? I’m particularly interested in passing arguments other than system. Is this still on the roadmap? |
@adrian-gierakowski it seems arguments are supported by the derivation path. This doesn't support arbitrary arguments, however. |
@RyanGibb could you please elaborate? An example of what’s possible would great. something I’d like to be able to do is:
|
You could create a derivation path such as
Perhaps #6583? |
@RyanGibb thank you for clarifying and for the link |
Currently, flakes are evaluated in pure mode and have no function arguments (other than the computed set of flake dependencies), so it's not possible to do things like:
builtins.currentSystem
.~/.config/nixpkgs/{config.nix,overlays}
.--arg
.Thus we need a controlled way to pass arguments to a flake. This must not compromise hermetic evaluation or the ability to aggressively cache evaluation results. For example, the arguments passed to a flake should be unambiguously hashable to produce a cache key (such that
(flakeClosureHash, argumentsHash, attributeName)
uniquely determines the evaluation result).For replacing
builtins.currentSystem
, however, we don't necessarily have to rely on a function argument. Instead, a flake could simply provide packages/derivations for all platforms that it supports. This is feasible thanks to laziness. For example, thenixpkgs
flake would provide attributes such aspackages.x86_64-linux.hello
andpackages.x86_64-darwin.hello
rather than a singlepackages.hello
that depends on a function argument. (This is an approach familiar from Hydra jobsets.) Thenix
UI can select the appropriate set automatically (e.g.nix run nixpkgs.hello
will selectnixpkgs.provides.packages.$system.hello
.)The text was updated successfully, but these errors were encountered: