Skip to content

What language is flake.nix written in? #4945

Open

Description

@dasJ

This issue may sound silly but it's actually not clear to me what language they are written in.
The syntax and file ending both look like Nix but the manual doesn't apply most of the time.
The manual makes it seem like this should work:

{
  description = "Testflake";
  outputs = import ./outputs.nix;
}

but running that results in

error: expected a function but got a thunk at /nix/store/lm4pyqnkbiwvp2kxjd64nqb2xkdxmbfx-source/flake.nix:4:3

So what language are flake.nix files written in (is there any specification or documentation) and why is that language not Nix?

Activity

  1. edolstra commented on Jun 25, 2021

    @edolstra
    Member

    It's a subset of Nix that doesn't allow computation in the flake metadata attributes. So e.g. outputs cannot be a function application like import ./outputs.nix, it must be a function directly outputs = { bla }: .... This is to prevent arbitrarily complex, possibly non-terminating computations while querying flake metadata.

    This should be documented in the flake manpage.

  2. stale commented on Jan 3, 2022

    @stale

    I marked this as stale due to inactivity. → More info

  3. dasJ commented on May 19, 2022

    @dasJ
    MemberAuthor

    Will care about this when the feature gets remotely usable for my use case so please leave this open

  4. exarkun commented on May 30, 2022

    @exarkun

    I ran into this and was quite surprised and confused for about half an hour. I used let ... in ... at the top of my flake.nix and the resulting error message, "error: file '/nix/store/91d71n4sxkxnby3c3pbc8is4xm7a70r9-source/flake.nix' must be an attribute set" had me scratching my head (builtins.typeOf said it evaluated to an attribute set) and looking all over for someplace I had put some non-set type into a set position.

    I didn't believe the error message was worded accurately and precisely because I am used to Nix error messages that tell me one type was expected in place of another with little or no further location information and I thought this was one of those cases.

    An error message something like "file '...' must be written using the limited flake expression language" might have helped me discover my mistake more quickly.

    Also, none of the docs I read on my way to learning about flakes said anything about this limited expression language so apart from tripping over this error I'm not sure how I would have learned about this.

  5. nixos-discourse commented on May 30, 2023

    @nixos-discourse
  6. nixos-discourse commented on Sep 7, 2023

    @nixos-discourse
  7. dzmitry-lahoda commented on Nov 12, 2023

    @dzmitry-lahoda

    could be awesome if there would be turing decidable(always halt) security attack protected(like infinite reference circular import parsing) nix which allows to be flake input limited flake expression language and that to be documented as flake input.

  8. nixos-discourse commented on Nov 14, 2023

    @nixos-discourse
  9. infinisil commented on Nov 14, 2023

    @infinisil
    Member

    This issue has a better title and description, but it's a effectively a duplicate of #3966, which has a bunch more discussion.

  10. 18 remaining items

  11. roberth commented on Dec 7, 2025

    @roberth
    Member

    I've opened NixOS/rfcs#193 to explore a solution to this.

  12. Malix-Labs commented on Apr 8, 2026

    @Malix-Labs
    Member

    I don't really know if NixOS/rfcs#193 could be considered as a "solution" to the fact that flake.nix is not a nix file but rather a subset of nix with a specific schema file

    It can be a solution if it becomes the only standard to write flakes in, since they wouldn't mislead into thinking flakes are full nix files to begin with. (which doesn't mean NixOS/rfcs#193 is desirable either)

    It seems like bikeshedding, but xkcd 927 is basically what I'm fearing :

    https://xkcd.com/927/

  13. roberth commented on Apr 8, 2026

    @roberth
    Member

    Working towards a removal of flake.nix is one way to settle the question, but yeah, only in a literal interpretation of the question posed, and I do think it's only a compelling vision when combined with NixOS/rfcs#194

  14. ruro commented on Apr 8, 2026

    @ruro

    Cross-posting from my comment on the RFC:

    I feel like this RFC should not just assume that the currently enforced status-quo limitation of "Flake input metadata can't contain arbitrarily complex, possibly non-terminating computations" must be kept as is, without justification. (...)

    For example, do we know if this restriction is actually useful / needed? I think, I read somewhere that FlakeHub is relying on the fact that flake metadata can be computed statically-ish (I've never used FlakeHub, so I am not sure if this is actually the case). Are there any more examples where this property is actually useful?

    If FlakeHub is the only (or one of the few) users of this restriction / guarantee, then maybe it should be implemented as a simple evaluation "depth" limiter on the side of FlakeHub, instead of in Flakes themselves?

    Or maybe it's enough to have a simple way to opt-out of this restriction? Something like

    {
        dynamic = true;
        inputs = {
            # Arbitrary nix expressions are now allowed inside inputs,
            # because `dynamic` was set to true. This flake might not have
            # full functionality on services like FlakeHub, but this is fine.
        };
    }

    Honestly, the more time I spend thinking about this, the less I like the idea that forcing static metadata is the correct solution. Restricting inputs to be static metadata is only one possible solution and it feels really weird that everyone just assumes it to be a non-negotiable requirement.

    As I've mentioned previously, here are some alternative options off the top of my head (roughly in order of personal preference, from best to worst):

    1. Use "full" nix, but have an evaluation depth / complexity limit (enforce it only where it's actually needed, ie on FlakeHub or when loading a flake from an untrusted source or something).

    2. Allow "full" nix, but also evaluate a static version of the metadata and save it in flake.lock (warn/error if static metadata doesn't match the locally evaluated results). Bonus points: you can also precompute and save some static information about the available outputs (which could be useful for searching / indexing purposes).

    3. Use "static" subset of nix by default, but have a way to opt-out (for users that don't care about FlakeHub, etc).

    4. Accept either flake.nix or flake.toml. Allow "full" nix inside flake.nix. That way, users that care about FlakeHub/etc will use flake.toml (or only the static subset of flake.nix), while everyone else can write arbitrary expressions in flake.nix.

    P.S. I already asked this before, but does anyone have any concrete examples where this static metadata requirement is actually needed other than on FlakeHub?

  15. Malix-Labs commented on Apr 8, 2026

    @Malix-Labs
    Member

    Also see #15132, which is related about the last comment

    #15132 (comment) from @Malix-Labs :

    Arguably it's more controlled than the alternative, which is that users have to cobble together input modifications using scripts that perform text replacements in flake.nix, or things along those lines.

    This is a strong argument;
    People really wanting to compute their flakes inputs are just doing it regardless, in an unsafer way.

  16. Malix-Labs commented on Jun 23, 2026

    @Malix-Labs
    Member

    I just discovered https://github.com/denful/flake-file

    @roberth is right in #15132 (comment) :

    I'm not convinced that Flakes users need to be patronized in this way, or that IFD is particularly problematic here.
    Arguably it's more controlled than the alternative, which is that users have to cobble together input modifications using scripts that perform text replacements in flake.nix, or things along those lines.

    I am now completely convinced that nix should indeed allow non-trivial expressions in flakes (#15132);
    To which extends is the question, and the current extends is unsatisfactory

    I am also convinced that if #15132 was to be rejected, then NixOS/rfcs#193 (or another non-turing configuration language) AND deprecating flake.nix would be the only legitimate alternative to the concept of nix flakes;

    Either flakes inputs are defined in a non-turing configuration language, either they are defined in Nix

    The current state of flake being a loosely defined subset of nix is objectively wrong because of this indecision

  17. mightyiam commented on Jun 23, 2026

    @mightyiam
    Member

    I'm a user of flake-file because it allows me to declare inputs in different files. If flake inputs could be evaluated dynamically that would obviate the need to run a command that generates the flake.nix and that would make the workflow nicer and probably make flake-file obsolete, in favor of some built-in flake-parts support for declaring flake inputs.

    Having said that, I would support a path similar to Lix, where flake features are frozen until the flakes are well defined and stable or whatever else ends up being their fate.

  18. vaxerski commented on Jul 20, 2026

    @vaxerski

    I have to use flake-file to avoid the absolute ugliness of flake.nix for my needs.

    I develop hyprland, and I need to be dogfooding my own software on the absolute latest revs.

    Now, problem is, when you have like 10 apps and 10 libraries, it turns into this fiesta of:

    app = { url = "..."; inputs.lib1.follows = "..."; inputs.lib2.follows = "..."; inputs.lib3.follows = "..."; inputs.lib4.follows = "..."; };

    which is a) an eyesore and b) a maintenance nightmare, because if any dep gets added, I need to manually keep track of it and add it.

    With flake-file, I can actually generate those automatically.

    The basic flake.nix seems awfully restricted.

  19. Malix-Labs commented on Jul 20, 2026

    @Malix-Labs
    Member

    See #15132 (comment) from @roberth, which is an instance of what Vax is doing

  20. mightyiam commented on Jul 21, 2026

    @mightyiam
    Member

    While this is offtopic, it's a short point and might serve @vaxerski and those who read his comment on the proliferation and handling of transitive inputs.

    If a flake input can be consumed not via its flake outputs but instead by importing a nix file by path from it or perhaps by using it as a source, then its transitive inputs can be avoided by setting flake = false; (to be clear, the attr path is inputs.<name>.flake). This opts out of evaluating the inputs flake.nix and flake.lock. I do this whenever possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions