I have a very simple flake, that exports some packages. Now a build step is not working, and I am trying to debug it. With usual package builds I am used to dropping into nix-shell
and being able to run the individual phases one-by-one Nixpkgs Manual. With nix flakes, I can’t get this to work.
Question: How is the debugging flow for package builds with nix-flakes supposed to look like?
I know about nix develop
. It looks like this generally assumes an explicit devShell/mkShell attributes to be defined, to setup a development environment. This environment does not come with the build phase scripts defined – at least not out of the box. Using nix develop .#package
did not work for me either.
Example:
cat flake.nix
{
description = "A simple Nix flake to run Python HTTP server";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05";
};
outputs = { self, nixpkgs, ... } @inputs:
let
system = "x86_64-darwin";
pkgs = nixpkgs.legacyPackages.${system};
in
{
packages.${system} = rec {
hello1 = builtins.derivation {
name = "hello1";
system = "x86_64-darwin";
builder = "${pkgs.bash}/bin/bash";
args = [ "-c" "${pkgs.coreutils}/bin/mkdir -p $out && echo 'Hello X1 World' > $out/hello.txt" ];
};
hello2 = pkgs.stdenv.mkDerivation {
name = "hello2";
phases = [ "buildPhase" ];
buildPhase = ''
mkdir -p $out
echo "Hello X2 World" > $out/hello.txt
'';
outputs = [ "out" ];
};
};
};
}
I purposefully inserted typos “X1” , “X2” that I want to debug into the code. Running nix build .#hello1
and nix build .#hello2
produce expected results.
Now:
; nix develop .#hello1
# 2024-03-20 15:31:05
error: builder for '/nix/store/r37r46xcn7v6wr45a7q2s2nwfmciac4y-hello1-env.drv' failed to produce output path for output 'out' at '/nix/store/19rmk59jv3rdx93j4h5yh9csxaccnbzq-hello1-env'
# FAILED(1) after 3.000s
; nix develop .#hello2
bash-5.1$ buildPhase
no Makefile, doing nothing
bash-5.1$