You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
error: '/nix/store/.../flake.nix' must be an attribute set #3966
however nix develop (or nix build .#devShell) results in the following error:
$ nix develop
error: --- Error ------------------------------------------------------------------------------------ nix
file '/nix/store/wvlsr8s3nysj0pmgdl7ndggpxc8za87f-source/flake.nix' must be an attribute set
(use '--show-trace' to show detailed location information)
I can make nix happy by moving the let inside the outputs definition:
I'm expecting the flake commands to allow top-level let bindings; but maybe that's on purpose to ensure the flake.nix stays as simple as possible?
nix-env --version output
nix-env (Nix) 2.4pre20200721_ff314f1
Reacted by Grégoire Geis, Fujita Hitoshi, Sivizius, Fabian Hauser, ralismark, Felix Bubbar, Lisanna Dettwyler, Flafy, Scott Olson, Julian Antonielli and 28 more
Reacted by AleXoundOS, Johannes Kirschbauer and sokai
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.
but maybe that's on purpose to ensure the flake.nix stays as simple as possible?
That's right. It ensures that a command like nix flake info doesn't have to evaluate an arbitrarily complex (and possibly non-terminating) Nix expression.
Reacted by AleXoundOS, dzmitry-lahoda and digicoder
Reacted by dzmitry-lahoda, Flafy, teapot, Jake Chvatal, 0x241F31, Sridhar Ratnakumar, Luis Quiñones, algasami, Luis Durão, Hraban and 4 more
Ok I realize it's actually terribly picky, even thunks are forbidden (i.e. in an input's { url = "foo" + "bar"; }):
/tmp/tmp.7jJ3XRKbVP$ nix develop
error: --- Error ------------------------------------------------------------------------------------- nix
expected a string but got a thunk at /nix/store/4yiaxz02925lr1ssyir8nc7cs8dp7bf0-source/flake.nix:2:3
(use '--show-trace' to show detailed location information)
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 flake.nix into flake.json containing metadata and inputs and flake.nix/outputs.nix containing only the outputs function in real Nix lang?
Reacted by Nicolas Mattia, Andreas Rammhold, Cole Helbling, xaverdh, Germano Gabbianelli, Alexei Robyn, Bastien Rivière, asrar, L-as, David Costa and 34 more
Reacted by Scott Olson, Will Fancher, Joachim Breitner, Zane Dufour, Matthew Boyea, Parthiv Seetharaman and Megadash452
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 niv I often use niv update some-input -b feature-branch to test things out. nix flake doesn't have such a command and it'd be relatively hard to implement given the current flake format, because we don't have a way to write back modified asts without touching unmodified whitespace and comments.
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.
I like the idea of specifying inputs and metadata in json.
The configs branch adds support for TOML as an alternative to flake.nix (1dc3f53). This allows the flake to be modified from the command line (e.g. 3632593).
nix flake doesn't have such a command
Well there is the --override-input flag. Since it only overwrites the lock file it doesn't have to deal with rewriting Nix expressions.
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 nix flake info I would consider dropping it and allowing arbitrary Nix code in flakes.
Reacted by Product Engineer, Fujita Hitoshi, Xavier Vello, Michael Livshin, Sean L, ruro, Yuto Oguchi, Dmitriy Smolin, Flafy, Danila Danko and 20 more
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.
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 idea is, you have a flake.template.nix written in ordinary Nix, which is used to generate the actual flake.nix.
With this, you can write your flake in normal Nix. When it is really worth it (!), then also the small overhead is justified.
The generation of flake.nix could even be wrapped as a flake app. One could make a flake template (that can be used by nix flake init – not the flake.template.nix) that provides a seed flake.nix only containing the generation app.
The generation of flake.nix could even be wrapped as a flake app. One could make a flake template (that can be used by nix flake init – not the flake.template.nix) that provides a seed flake.nix only containing the generation app.
Does nix flake info get the data from flake.nix or flake.lock?
Because I would think if you need pure data for that function, storing it in the precomputed lockfile would work fine?
Activity
zimbatm commentedon Aug 28, 2020
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.
edolstra commentedon Aug 28, 2020
That's right. It ensures that a command like
nix flake infodoesn't have to evaluate an arbitrarily complex (and possibly non-terminating) Nix expression.nmattia commentedon Aug 28, 2020
Ok I realize it's actually terribly picky, even thunks are forbidden (i.e. in an input's
{ url = "foo" + "bar"; }):jorsn commentedon Sep 19, 2020
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
flake.nixintoflake.jsoncontaining metadata and inputs andflake.nix/outputs.nixcontaining only theoutputsfunction in real Nix lang?roberth commentedon Oct 10, 2020
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
nivI often useniv update some-input -b feature-branchto test things out.nix flakedoesn't have such a command and it'd be relatively hard to implement given the current flake format, because we don't have a way to write back modified asts without touching unmodified whitespace and comments.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.
edolstra commentedon Oct 11, 2020
The
configsbranch adds support for TOML as an alternative toflake.nix(1dc3f53). This allows the flake to be modified from the command line (e.g. 3632593).Well there is the
--override-inputflag. Since it only overwrites the lock file it doesn't have to deal with rewriting Nix expressions.malte-v commentedon Mar 7, 2021
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
nix flake infoI would consider dropping it and allowing arbitrary Nix code in flakes.gytis-ivaskevicius commentedon Jun 6, 2021
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.
ggPeti commentedon Jun 7, 2021
Why are we trying to protect users from their own non-terminating nix expressions? On the other hand, why only in commands like
nix flake info?jorsn commentedon Jun 7, 2021
50 remaining items
chekoopa commentedon Jan 7, 2024
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.
jorsn commentedon Jan 8, 2024
Here is some tooling proposed in the other issue: #4945 (comment).
The idea is, you have a
flake.template.nixwritten in ordinary Nix, which is used to generate the actual flake.nix.With this, you can write your flake in normal Nix. When it is really worth it (!), then also the small overhead is justified.
The generation of
flake.nixcould even be wrapped as a flake app. One could make a flake template (that can be used bynix flake init– not theflake.template.nix) that provides a seedflake.nixonly containing the generation app.jorsn commentedon Jan 12, 2024
Implemented: https://github.com/jorsn/flakegen.
remove followsNixpkgs see [issue](NixOS/nix#3966)
IogaMaster commentedon Jan 4, 2025
Does
nix flake infoget the data from flake.nix or flake.lock?Because I would think if you need pure data for that function, storing it in the precomputed lockfile would work fine?
Define nixos-version in inputs and outputs