How can I define and reference variables in flake.nix inputs?
14:47 19 Mar 2026

Consider a flake used in a home-manager configuration:

{
  description = "Home Manager configuration";
  inputs = {
    # Specify the sources of Nixpkgs and Home Manager .
    nixpkgs = {
      url = "github:nixos/nixpkgs/nixos-25.11"; # first time
    };
    home-manager = {
      url = "github:nix-community/home-manager/release-25.11"; # second time
      inputs.nixpkgs.follows = "nixpkgs";
    };
  }; 

  outputs = { nixpkgs, home-manager, ... }:
    let
      system = builtins.currentSystem;
      pkgs = nixpkgs.legacyPackages.${system};
    in {
      homeConfigurations = let
        user = builtins.getEnv "USER";
        homedir = builtins.getEnv "HOME";
        release = "25.11"; # third time
      in {
        ${user} = home-manager.lib.homeManagerConfiguration {
          inherit pkgs;
          modules = [ ./home.nix ];
          extraSpecialArgs = {
            inherit user homedir release;
          };
        };
      };
    };
}

I specify that I want nixos release 25.11 three times. This feels a bit silly. Is there a simple way to specify it once, and then have the other places inherit that?

Apparently let ... in syntax does not work in flake inputs: https://discourse.nixos.org/t/why-cant-i-use-let-variables-in-flake-nix-inputs/39929

Is there a way around this limitation?

nix declarative home-manager