treefmt icon indicating copy to clipboard operation
treefmt copied to clipboard

"segmentation violation" error when running on nixpkgs

Open l0b0 opened this issue 3 months ago • 2 comments

Describe the bug

nix fmt crashed with a segfault when running on a fork of nixpkgs which needed some minor formatting. Unfortunately the crash was somehow not raised to the system, so there's no core dump, and I can't reproduce it.

To Reproduce

How it happened initially:

  1. Check out a copy of nixpkgs at commit 858310f86722b2dc0ed6b11819264e59046925ff.

  2. Change some Nix file indentation, for example by reverse-applying the following patch:

    diff --git i/nixos/modules/virtualisation/nixos-containers.nix w/nixos/modules/virtualisation/nixos-containers.nix
    index 049950638888..3966b91b69e0 100644
    --- i/nixos/modules/virtualisation/nixos-containers.nix
    +++ w/nixos/modules/virtualisation/nixos-containers.nix
    @@ -955,12 +955,12 @@ in
                 config.nix.package
               ];
    
    -        enableStrictShellChecks = true;
    +          enableStrictShellChecks = true;
    
    -        environment = {
    -          root = "${stateDirectory}/%i";
    -          INSTANCE = "%i";
    -        };
    +          environment = {
    +            root = "${stateDirectory}/%i";
    +            INSTANCE = "%i";
    +          };
    
               preStart = preStartScript dummyConfig;
    
  3. Run nix fmt, which runs treefmt and then crashes.

Expected behavior

treefmt should not crash.

System information

❯ treefmt --version
treefmt v2.3.1
❯ nix-info --markdown | sed "s/$USER/username/" # package metadata
 - system: `"x86_64-linux"`
 - host os: `Linux 6.12.48, NixOS, 25.11 (Xantusia), 25.11.20250921.554be64`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.28.5`
 - channels(root): `"home-manager, nixos, nixos-hardware, nixos-stable-24.05"`
 - nixpkgs: `/nix/store/yw0wijix50n0y2ii15sk8kvnwgalpq6f-source`

Additional context

Log

I tried to reproduce in a few ways, but none of them worked:

  • nix fmt
  • treefmt --clear-cache && nix fmt
  • git checkout . && nix fmt
  • git checkout . && treefmt --clear-cache && nix fmt
  • treefmt --clear-cache && git checkout . && nix fmt after realizing treefmt --clear-cache doesn't just clear the cache

l0b0 avatar Sep 26 '25 08:09 l0b0

I'm afraid that without a reproducer or a core dump, there's not much I have to go on.

I'll leave this issue open for a while in case it recurs and you capture some more context.

brianmcgee avatar Sep 27 '25 06:09 brianmcgee

I'll leave this issue open for a while in case it recurs and you capture some more context.

I'm not sure how I can capture a core dump if the program catches SIGSEGV.

l0b0 avatar Sep 27 '25 07:09 l0b0