-
-
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
error: '/nix/store/.../flake.nix' must be an attribute set #3966
Comments
That's a strange limitation of how flakes are being evaluated. All of the data structures must be pretty much JSON-like data. The only place where more complex nix code is allowed is within the outputs function. |
That's right. It ensures that a command like |
Ok I realize it's actually terribly picky, even thunks are forbidden (i.e. in an input's
|
Why then use nix syntax if it is not nix? I'd say, either use a clearly defined subset of nix code, at best with another name and file ending (tnix – total nix) or the flake file shall be in a total language like plain json and the outputs attr refers to nix expressions, or dhall (but a comparatively complex new language). If it looks like nix but isn't, to me it is confusing unexpected (”strange“ – zimbatm) behaviour. Edit: Why not split the |
I like the idea of specifying inputs and metadata in json. It's easier to work with for Nix itself and for external tools. With I always used to think of the Nix language as a predictable element in an otherwise messy domain. Just a lazy evaluator that implicitly writes derivations. I don't think flakes need to change that. |
The
Well there is the |
Ugh. I just spent 8 hours writing a nix expression that dynamically generates flake inputs from an external registry and now I find out that it won't work. Is this limitation really such a great idea? If it's just there to improve the UX of |
Would it be difficult to disallow most builtins instead? 🤔 This would more or less solve the problem with people writing complex expressions and would allow for some flexibility which would be neat. |
Why are we trying to protect users from their own non-terminating nix expressions? On the other hand, why only in commands like |
Why are we trying to protect users from their own non-terminating nix expressions?
E.g. because you want to safely list an unknown online flake.
|
I just faced the same issue, very confusing to know I can't even concatenate strings inside flake inputs. |
Can I add to this issue as well. I understand that limiting the computability of flakes are important, but I have some usecases where using expressions in flakes would be very useful. For example, when all inputs comes from the same server. Here we have a Haskell flake that requires some specific versions of many packages from hackage: {
description = "My Picky Haskell Program";
inputs = let
hackage = name: {
url = "https://hackage.haskell.org/package/${name}/${name}.tar.gz";
flake = false;
};
in {
package1 = hackage "package1-1.2.3";
package2 = hackage "package2-3.2.1";
...
};
outputs = { self, package1, package2, ...}:
#...
;
} Having to write out "http://hackage.haskell.org..." for every entry, is very error prone, and is hard to change. Being able to template the flakes inputs would really be a huge usability boon. |
I agree, something like this would be very useful {
inputs = {
foo = rec {
type = "tarball";
version = "1.2.3";
url = "https://very.long/url/${version}/that/${version}/includes/${version}/a/lot/of/${version}"
};
# or:
bar = let version = "1.2.3"; in { ... };
};
} |
Related: #4945 |
Darn. I got stuck on this for a few hours also. Definitely could use a better error message at least, if things like top-level |
There is also a restriction on the form of outputs = import ./outputs.nix;
I don't see why this limitation should be needed for outputs = inputs: import ./outputs.nix inputs; This works without issue. |
I think the main rationale behind using a subset of Nix for inputs is Letting computations in inputs would let the whole ecosystem bloat, be volatile, less readable, mostly losing the point of Nix flakes (for most users). At least some building blocks of the ecosystem should have fixed semantics, IMHO. Though, I did encounter myself the input restrictions when trying to read inputs URLs using |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/programmatic-editing-of-flake-nix/35321/1 |
hello. so there are 2 issues: a. nix is not actually nix, but part of it like flake.json. so kind of flake.json flake.lock flake.nix trio. either one fix of a or b will make else less important. will donate more to nix if a or be handled, as it seems good for increased adoption. thank you |
I'm sure tooling is the key. |
We develop a product which includes a server machine based on NixOS with some software modules (developed by us). As for servers, it also implies remote deployment and support. So we somehow have survived with plain channels (by pinning them using a few forbidden techniques), but now I'm migrating all of this to flakes (because it refuses to build now). The prime issue is dependency tracking. Every our software module is a separate folder in the monorepo, though they interconnect as dependencies (e.g. libraries). The first plan was just importing nixpkgs commit hash from a certain file. But as that's a very unsafe approach, now I'm brewing a single channel dispatcher to somehow provide a unified nixpkgs revision to all the modules in need. Thus, yes, tooling is the key, but some unsafe-ty (at least possible to enable implicitly) could help. |
Here is some tooling proposed in the other issue: #4945 (comment). The generation of |
Implemented: https://github.com/jorsn/flakegen. |
Does |
Describe the bug
This flake.nix evaluates to an attribute set:
however
nix develop
(ornix build .#devShell
) results in the following error:I can make nix happy by moving the
let
inside theoutputs
definition:Expected behavior
I'm expecting the flake commands to allow top-level
let
bindings; but maybe that's on purpose to ensure theflake.nix
stays as simple as possible?nix-env --version
outputnix-env (Nix) 2.4pre20200721_ff314f1
The text was updated successfully, but these errors were encountered: