Flake: How to have a Literal Value Input (no URL/file path)

Maybe I’m misunderstanding flakes (please correct me if thats true)

I’d like to do:

{
    inputs = {
        nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
        enableFeature1 = {};
    };
    outputs = { nixpkgs, enableFeature1 ? true }:
         /*stuff*/;
}

or that^ without the inputs entry (e.g. extra argument). But I’m unsure how, and can’t seem to find information about it. There seems to be a way to to it using paths and having a file contain the default value but it feels like I would be abusing that feature rather than using it as intended.

What you want is not currently supported – flake inputs can currently only be other flakes. In particular, if you do not specify a URL, Nix will attempt to obtain if from flake registry based on the input name so you will just get an error:

error:
       … while updating the lock file of flake 'git+file:///…'

       … while updating the flake input 'enableFeature1'

       error: cannot find flake 'flake:enableFeature1' in the flake registries

There is a feature request to support more general Nix expressions as inputs Allow plain Nix expressions as flake inputs · Issue #5663 · NixOS/nix · GitHub but there are still unresolved questions.

2 Likes

If you have a small set of flags (ie: =< 3 features), you can use different outputs.

packages.x86_64-linux.default = ... # default version
packages.x86_64-linux.f1   = ... # feature1 enabled version
packages.x86_64-linux.f2   = ... # feature2 enabled version
packages.x86_64-linux.f1f2 = ... # feature1 and feature2 enabled version
...

Check this out :smiling_imp: