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

nix develop --build and phases confusion #6202

Open
thufschmitt opened this issue Mar 3, 2022 · 6 comments
Open

nix develop --build and phases confusion #6202

thufschmitt opened this issue Mar 3, 2022 · 6 comments
Labels
new-cli Relating to the "nix" command nix-shell nix-shell, nix develop, nix print-dev-env, etc

Comments

@thufschmitt
Copy link
Member

When buildPhase is defined, nix develop --build does not work due to confusion between the variable and function during stdenv eval.

{
  description = "A flake that uses Hello World";
  # inputs.flake01.url = "/tmp/flake01";
  outputs = { self, nixpkgs }: {
    defaultPackage.x86_64-linux =
      with import nixpkgs { system = "x86_64-linux"; };
      stdenv.mkDerivation {
        name = "flake02";
        src = ./d;
        buildInputs = [ hello ];
        buildPhase = ''
          hello >> ./hello.txt
        '';
        installPhase = ''
          mkdir -p $out
          install -m 644 -t $out/ hello.txt
        '';
      };
  };
}

need feedback:
flox@c03252c

Or change the order here in stdenv? https://github.com/NixOS/nixpkgs/blob/master/pkgs/stdenv/generic/setup.sh#L72-L80

@tomjnixon
Copy link

I ran into this too, and it was a bit confusing. This also applies to using nix-shell. Three possible resolutions for this:

  1. Add a function in the default builder that you could run with runPhase buildPhase (or runPhase build?), which would have the same behavior as this line, and update all the documentation to say to use this rather than buildPhase.

  2. Change the default phase definitions to evaluate the contents of the corresponding variable, and have default definitions of those variables with the current behavior.

  3. Just update the documentation to say that you might need to run eval "$buildPhase" rather than buildPhase if it's overridden, and add a change in nix to make --build etc. work properly.

IMO 1 is the cleanest, but is annoying to type and there will be lots of tutorials etc. that will never be fixed. 2 is pragmatic, but still results in some confusion with user-defined (or non-default) phases, or where buildPhase is re-defined as a function. 3 is lowest risk but is a bad user experience.

@stale stale bot added the stale label Oct 30, 2022
@roberth roberth added the nix-shell nix-shell, nix develop, nix print-dev-env, etc label Dec 19, 2022
@stale stale bot removed the stale label Dec 19, 2022
@Ninlives
Copy link
Contributor

Ninlives commented May 4, 2023

Any progress? I ran into this problem too, which is very confusing to me.

@thufschmitt
Copy link
Member Author

Not really. I think this could be somewhat easily be worked around in Nix by replacing the runHook call here by something like what stdenv does. Do you want to open a PR with that?

@Ninlives
Copy link
Contributor

Ninlives commented May 5, 2023

But which implementation is preferred? The commit mentioned has already done this but it's not accepted.

@thufschmitt
Copy link
Member Author

The commit mentioned has already done this but it's not accepted.

Oh, I'd forgotten about that 🤦‍♂️
It never made it to a PR actually. But it looks good to me. @tomberek was there any specific reason why you didn't submit it?

Ninlives added a commit to Ninlives/nixpkgs that referenced this issue May 7, 2023
Provide a `runPhase` function which wraps the phase running action of
genericBuild. The new function can be used as an interface by `nix
develop`, i.e. `nix develop some#flake --build` may just call `runPhase
build`, which makes its behavior more consistent with `nix build`.
In preparation of fixing NixOS/nix#6202
@Ninlives
Copy link
Contributor

Ninlives commented May 7, 2023

@thufschmitt I've created a PR for nixpkgs in preparation of fixing this issue, please take a look at it.

Ninlives added a commit to Ninlives/nixpkgs that referenced this issue May 9, 2023
Provide a `runPhase` function which wraps the phase running action of
genericBuild. The new function can be used as an interface by `nix
develop`, i.e. `nix develop some#flake --build` may just call `runPhase
build`, which makes its behavior more consistent with `nix build`.
In preparation of fixing NixOS/nix#6202
Artturin pushed a commit to Ninlives/nixpkgs that referenced this issue Nov 7, 2023
Provide a `runPhase` function which wraps the phase running action of
genericBuild. The new function can be used as an interface by `nix
develop`, i.e. `nix develop some#flake --build` may just call `runPhase
build`, which makes its behavior more consistent with `nix build`.
In preparation of fixing NixOS/nix#6202
Artturin pushed a commit to Ninlives/nixpkgs that referenced this issue Nov 7, 2023
Provide a `runPhase` function which wraps the phase running action of
genericBuild. The new function can be used as an interface by `nix
develop`, i.e. `nix develop some#flake --build` may just call `runPhase
build`, which makes its behavior more consistent with `nix build`.
In preparation of fixing NixOS/nix#6202
@fricklerhandwerk fricklerhandwerk added the new-cli Relating to the "nix" command label Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-cli Relating to the "nix" command nix-shell nix-shell, nix develop, nix print-dev-env, etc
Projects
Status: Backlog
Development

No branches or pull requests

5 participants