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

Allow non-flake local path for --override-input #4086

Closed
wants to merge 12 commits into from

Conversation

kquick
Copy link
Contributor

@kquick kquick commented Sep 28, 2020

This PR makes it possible to use --override-input for non-flake inputs as well as flake inputs. See 40968dc for a full description of the main change in this PR.

The expected use case here is that a flake has been created for a
third-party project that does not emplace the 'flake.nix' at in that
project's top-level directory.  Then the third-party project is
checked out locally and so the flake.nix (living elsewhere) is being
redirected to that local checkout:

```
$ nix build /local/path/to/flake.nix --override-input project /path/to/project
```

These tests ensure this type of input override works as expected.
Prior to this change, the only way to specify that an input was not a
flake was to use the 'flake = false;' as part of the attribute set
specifying that input.  When using --override-input, it is not
possible to specify that path.

The use case is where a project is not (yet :-) nix-supporting and the
flake.nix has been developed and maintained separately.  The
interesting subset of flake.nix is something like:

```
{
  input.project = {
    type = "github";
    host = "github.com";
    owner = "projowner";
    repo = "project";
    flake = false;
  };

  outputs = { project, ... }:

    packages.x86_64-linux = {

      project = stdenv.mkDerivation {
          src = project;
          ...
      };
   };
}
```

The above works fine, but if the project is checked out locally to be
worked on, the user should be able to do something like:

```
$ nix build /path/to/flake.nix --override-input /local/project/checkout
```

This patch makes this type of override possible (prior to this patch
it would fail because `/local/project/checkout` doesn't contain a
`flake.nix` file).

Note that simply adding the `false` argument (for `allowMissing`) to
the handler for `--override-input` is sufficient to get the above
working, but it also disables treatment of the input as a flake if it
is one.  This change includes logic that examines the input location
to determine if a `flake.nix` is present and treats it accordingly.
The `isFlake` flag in `FlakeInput` is still applied for the
inheritance cases that previously existed, but when the `FlakeInput`
is dynamically constructed from a `FlakeRef`, the target of the
fetched `FlakeRef` is used to make the "is a flake?" determination.
@kquick
Copy link
Contributor Author

kquick commented Oct 6, 2020

This is ready for review @edolstra and would be good get merged to fix flake support for --override-input.

@edolstra edolstra self-assigned this Oct 7, 2020
@colemickens
Copy link
Member

Does this fix #3779? I don't know the Nix codebase well enough to understand the code, but it looks like the test case indicates it might? (Context: Currently there is no way to use --override-input and --no-update-lock-file (and --no-write-lock-file doesn't help).

@kquick
Copy link
Contributor Author

kquick commented Nov 26, 2020

This does not fix #3779 as I understand it: this PR does not change the stance of flake.lock updates based on command-line --override-input . The main thrust of this is to allow --override-input to reference a target that does not contain a flake.nix. Non-flake inputs supported in the flake file via input.foo = { ...; flake = false; }, but prior to this PR, specifying nix build --override-input foo other-location would fail if other-location/flake.nix didn't exist.

@edolstra , I updated this from master to resolve the merge conflict, so it's in mergeable state again.

@bqv
Copy link
Contributor

bqv commented Dec 3, 2020

I also desire this.

@edolstra by self assigning this, do you mean you're going to implement it yourself elsewhere?

Edit: fwiw, no response will indicate a yes

@kquick
Copy link
Contributor Author

kquick commented Feb 16, 2021

Re-synchronized changes with master again, ready for merging, @edolstra .

@bqv
Copy link
Contributor

bqv commented Feb 16, 2021

AIUI when he blanks you like this it's cause he either doesn't care or he's going to do it better himself

@jtojnar
Copy link
Contributor

jtojnar commented Feb 16, 2021

Or just busy with other work.

@stale
Copy link

stale bot commented Aug 17, 2021

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

@stale stale bot added the stale label Aug 17, 2021
@L-as
Copy link
Member

L-as commented Jan 13, 2022

This is still needed AFAICT?

@stale stale bot removed the stale label Jan 13, 2022
@cstml
Copy link

cstml commented Jan 13, 2022

This is still needed AFAICT?

Very much so.

@thufschmitt
Copy link
Member

So I’ve spent a bit of time trying to merge this with master to review it (there’s quite a bunch of conflicts :( ), only to realize that as far as I can tell, the underlying issue is already fixed in master (and apparently by me 🤦‍♂️ ). So I’ll close this.

That being said,

  1. the split of getFlake in this branch might still be valuable
  2. (to my shame) the fix didn’t include any test for it, while this one does

@kquick , do you think you could open a couple of PRs for just these?

@thufschmitt
Copy link
Member

(just ftr, the manual test I ran to make sure that it was indeed working on master was:

$ cat <<EOF > flake.nix
{
  inputs.foo = {
    url = "path:./a";
    flake = false;
  };

  outputs = { self, foo }: {
    foo = builtins.readFile "\${foo}/foo";
  };
}
EOF
$ mkdir -p a && echo a > a/foo
$ mkdir -p b && echo b > b/foo
$ nix eval .#foo
"a\n"
$ nix eval .#foo --override-input foo $PWD/b
warning: not writing modified lock file of flake 'path:/tmp/tmp.HB372FSu5F':
• Updated input 'foo':
    'path:./a?lastModified=1&narHash=sha256-Nep3gAa7Eq4+Dv9plpoqx%2f+AJ+gWeV7U9lEiGCPRrR4=' (1970-01-01)
  → 'path:/tmp/tmp.HB372FSu5F/b?lastModified=1652775844&narHash=sha256-lGQM58%2frdQGqiOUqjGIYvo4nwaoVuGFnFx813YbaA5Y=' (2022-05-17)
"b\n"

)

@L-as
Copy link
Member

L-as commented May 17, 2022

FWIW this still doesn't work for me

@thufschmitt
Copy link
Member

FWIW this still doesn't work for me

Mh strange 🤔

Is the exact repro I sent broken or are you doing something slightly different? I just noticed that @colemickens mentioned some time ago that my fix was broken, so maybe it just works under some very specific conditions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

None yet

8 participants