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

stdenv: wrap phase running actions of genericBuild #230874

Merged
merged 1 commit into from
Nov 7, 2023

Conversation

Ninlives
Copy link
Contributor

@Ninlives Ninlives commented 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

Description of changes
Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.05 Release Notes (or backporting 22.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@@ -1539,6 +1539,44 @@ showPhaseFooter() {
}


runPhase() {
local curPhase="${1%Phase}Phase"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not do this

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
Copy link
Member

@Artturin Artturin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello> somePhase
hello> build failed in somePhase with exit code 1
hello> To attach install cntr and run the following command as root:
hello>    cntr attach -t command cntr-/nix/store/x82brk9g33fhnq33nwb9hl6s2zqmfzzh-hello-2.12.1
diff --git a/pkgs/by-name/he/hello/package.nix b/pkgs/by-name/he/hello/package.nix
index f1b056faf640..c632ba1e9835 100644
--- a/pkgs/by-name/he/hello/package.nix
+++ b/pkgs/by-name/he/hello/package.nix
@@ -5,6 +5,7 @@
 , nixos
 , testers
 , hello
+, breakpointHook
 }:
 
 stdenv.mkDerivation (finalAttrs: {
@@ -28,6 +29,14 @@ stdenv.mkDerivation (finalAttrs: {
         (nixos { environment.noXlibs = true; }).pkgs.hello;
   };
 
+  nativeBuildInputs = [ breakpointHook ];
+
+  buildPhase = ''
+    runPhase somePhase
+  '';
+
+  somePhase = ''exit 1'';
+
   passthru.tests.run = callPackage ./test.nix { hello = finalAttrs.finalPackage; };
 
   meta = with lib; {

breakpointHook uses $curPhase and it works

@Artturin Artturin merged commit 71f42b7 into NixOS:staging Nov 7, 2023
19 of 22 checks passed
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/nix-build-phases-run-nix-build-phases-interactively/36090/4

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

Successfully merging this pull request may close these issues.

None yet

3 participants