Why can't I use let variables in flake.nix inputs?

I was hoping to use a variable to specify the release of the inputs to a flake but the following example gives an error. If I use a recursive set it gives the same error but with string instead of thunk. Could someone please explain what I’m missing here? Thank you

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

flake.nix:

{
  description = "Home Manager configuration of user";

  inputs =
    let
      nix-release = "23.11";
    in {
      nixpkgs.url = "github:nixos/nixpkgs/nixos-${nix-release}";
      home-manager = {
        url = "github:nix-community/home-manager/release-${nix-release}";
        inputs.nixpkgs.follows = "nixpkgs";
      };
    };

  outputs = inputs:
    let
      user = "user";
      system = "x86_64-darwin";
      pkgs = inputs.nixpkgs.legacyPackages.${system};
    in {
      homeConfigurations.${user} = inputs.home-manager.lib.homeManagerConfiguration {
        inherit pkgs;
        modules = [ ./home.nix ];
      };
    };
}

nix --version = 2.18.1
manual: nix flake - Nix Reference Manual

The only place where you can use the entire nix language in a flake.nix is in the outputs attribute. I’m not sure about the exact reasons behind it, but I think has something to do with the need to be able to statically analyze the inputs, which might not be possible if arbitrary nix expressions are allowed, since nix is a turing complete language.

1 Like

See this post by infinisil on some caveats wrt flakes;

especially

4 Likes