How can I debug this segfault trying to build my system with flakes?

If I do:

[cody@nixos:~]$ nix flake new -t "github:nrdxp/nixflk/bare" flk-bare

[cody@nixos:~]$ cd flk-bare/

[cody@nixos:~/flk-bare]$ rebuild NixOS test
evaluating file '/nix/store/2qc98g8pw1yv3kvh1yczwdjazgj14rw4-nix-2.4pre20200721_ff314f1/share/nix/corepkgs/derivation.nix'
evaluating file '/nix/store/iwn67px8m720v5rl3axj52qcab60p3ng-source/flake.nix'
building '/nix/store/92pvh7yjcycnzhj3v5g28y4n2s6rvz3f-extra-utils.drv'...
error: --- Error --------------------------------------------------- nix
builder for '/nix/store/92pvh7yjcycnzhj3v5g28y4n2s6rvz3f-extra-utils.drv' failed with exit code 139; last 10 log lines:
  warning: working around a Linux kernel bug by creating a hole of 4096 bytes in ‘/nix/store/q9jwr9p86gzrbyb8h5zvl8rg60hm513r-extra-utils/bin/ata_id’
  patching /nix/store/q9jwr9p86gzrbyb8h5zvl8rg60hm513r-extra-utils/bin/busybox...
  patching /nix/store/q9jwr9p86gzrbyb8h5zvl8rg60hm513r-extra-utils/bin/fido_id...
  warning: working around a Linux kernel bug by creating a hole of 4096 bytes in ‘/nix/store/q9jwr9p86gzrbyb8h5zvl8rg60hm513r-extra-utils/bin/fido_id’
  patching /nix/store/q9jwr9p86gzrbyb8h5zvl8rg60hm513r-extra-utils/bin/cdrom_id...
  warning: working around a Linux kernel bug by creating a hole of 4096 bytes in ‘/nix/store/q9jwr9p86gzrbyb8h5zvl8rg60hm513r-extra-utils/bin/cdrom_id’
  testing patched programs...
  hello world
  /build/.attr-0l2nkwhif96f51f4amnlf414lhl4rv9vh8iffyp431v6s28gsr90: line 101:  6309 Done                    $out/bin/mount --help 2>&1
        6310 Segmentation fault      (core dumped) | grep -q "BusyBox"
error: --- Error --------------------------------------------------- nix
1 dependencies of derivation '/nix/store/xin3hp61li5y1xmgij155h5md98qa7kz-stage-1-init.sh.drv' failed to build
error: --- Error --------------------------------------------------- nix
1 dependencies of derivation '/nix/store/dhhcji9jshnsmlbhwp64qlsifhiqclcz-initrd-linux-5.4.54.drv' failed to build
error: --- Error --------------------------------------------------- nix
1 dependencies of derivation '/nix/store/wl9n175ss57zw8wwr6r1n6vxbsxl17qb-nixos-system-NixOS-20.03.20200802.7dc4385.drv' failed to build

I get a segfault. The author of the flk repo is too busy to help right now and I’d like to be able to debug this myself.

It looks like the error happens in “stage 2” while trying to build the linux kernel for some reason.

How could I debug this further?

Hi @codygman,

I ran into similar system with updating my Nixos configuration. Have you figured out how to debug the flake SEGFAULT issue?

panda@anarchy ~> sudo nixos-rebuild --flake '/etc/nixos#' switch
[sudo] password for panda:
building the system configuration...
/run/current-system/sw/bin/nixos-rebuild: line 488:  2040 Segmentation fault      (core dumped) nix "${flakeFlags[@]}" build "$flake#$flakeAttr.config.system.build.toplevel" "${extraBuildFlags[@]}" "${lockFlags[@]}" --out-link $outLink

Here’s my flake.nix:

{
  inputs = {
    nixpkgs.url = github:NixOS/nixpkgs-channels/nixos-unstable;
    home-manager.url = github:nix-community/home-manager;
    # nur.url = github:nix-community/NUR;
  };

  outputs = { nixpkgs, nix, self, ... }@inputs: {
    nixosConfigurations.anarchy = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules =
        [ (import ./configuration.nix) ];
      specialArgs = { inherit inputs; };
    };
  };
}

Perhaps Segmentation fault when building ISO image with nixFlakes · Issue #4246 · NixOS/nix · GitHub