Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override inputs when using builtins.getFlake #9154

Open
raboof opened this issue Oct 14, 2023 · 2 comments · May be fixed by #11952
Open

Override inputs when using builtins.getFlake #9154

raboof opened this issue Oct 14, 2023 · 2 comments · May be fixed by #11952
Labels
feature Feature request or proposal flakes

Comments

@raboof
Copy link
Member

raboof commented Oct 14, 2023

Is your feature request related to a problem? Please describe.

Sometimes it can be cumbersome to refactor a derivation to 'pass in' a flake input, for example when you're working with a 'classic' nix system or the derivation you want to modify is somewhere 'deep'. In these cases the getFlake builtin comes in handy.

getFlake, however, strictly honors the flake.lock of whatever you got. If that refers to something big, such as nixpkgs, this might lead to different versions of that dependency in your store.

Describe the solution you'd like

It would be nice to be able to 'pass in' inputs to getFlake, similar to input.nixpkgs.follows = "nixpkgs" in flake.nix or --override-input on the nix commandline.

Priorities

Add 👍 to issues you find important.

@raboof raboof added the feature Feature request or proposal label Oct 14, 2023
@rrix
Copy link

rrix commented Oct 31, 2023

this is making using software distributed as flakes from a "legacy" configuration.nix or a non-flake project essentially impossible, especially if your system isn't running on unstable:

error: Python version mismatch in 'python3.10-arcology-0.1.0':

       The Python derivation 'python3.10-arcology-0.1.0' depends on a Python derivation
       named 'python3.10-arroyo_rs-0.1.0', but the two derivations use different versions
       of Python:

            'python3.10-arcology-0.1.0' uses /nix/store/c3cjxhn73xa5s8fm79w95d0879bijp04-python3-3.10.13
           'python3.10-arroyo_rs-0.1.0' uses /nix/store/pzf6dnxg8gf04xazzjdwarm7s03cbrgz-python3-3.10.12

       Possible solutions:

         * If 'python3.10-arroyo_rs-0.1.0' is a Python library, change the reference to 'python3.10-arroyo_rs-0.1.0'
           in the propagatedBuildInputs of 'python3.10-arcology-0.1.0' to use a 'python3.10-arroyo_rs-0.1.0' built from the same
           version of Python

         * If 'python3.10-arroyo_rs-0.1.0' is used as a tool during the build, move the reference to
           'python3.10-arroyo_rs-0.1.0' in 'python3.10-arcology-0.1.0' from propagatedBuildInputs to nativeBuildInputs

         * If 'python3.10-arroyo_rs-0.1.0' provides executables that are called at run time, pass its
           bin path to makeWrapperArgs:

               makeWrapperArgs = [ "--prefix PATH : ${lib.makeBinPath [ arroyo_rs ] }" ];

        at /home/rrix/Code/nixpkgs/pkgs/development/tools/poetry2nix/poetry2nix/default.nix:427:11

I'm very close to ripping flake.nix out of all of my projects and distributing them classically, rather than going "all-in" on flakes.

@benaryorg
Copy link

Adding this feature would also allow e.g. a Hydra jobset to have an additional job which overrides the flake input to point at a more current version (e.g. to automatically test against the current nixpkgs from a non-flake job with a regular git input which uses builtins.getFlake and overrides).
Any other solutions like building a derivation that runs nix flake update with --override-input (which is already hell of a stretch in usability) falls flat due to the is not allowed to refer to a store path constraint while also requiring IFD via e.g. builtins.path to even get to that point.

The usual approach of working around this by creating a parent flake which overrides the input as mentioned by OP also does not work programmatically since any flake created within Nix at runtime will be a store path, and anything created before runtime has effectively the same issue of being potentially outdated at runtime.

edolstra added a commit to DeterminateSystems/nix-src that referenced this issue Nov 25, 2024
This uses the same syntax as flake inputs in flake.nix, e.g.

  builtins.getFlake {
    url = "github:NixOS/nix/55bc52401966fbffa525c574c14f67b00bc4fb3a";
    inputs.nixpkgs.url = "github:NixOS/nixpkgs/c69a9bffbecde46b4b939465422ddc59493d3e4d";
  }

Note that currently it's not supported to set `flake = false` or to
use `follows` (because lockFlake() doesn't support that for CLI
overrides), but it could be implemented in the future.

Fixes NixOS#9154.
@edolstra edolstra linked a pull request Nov 25, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request or proposal flakes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants