Skip to content

"segmentation violation" error when running on nixpkgs #637

@l0b0

Description

@l0b0

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.1nix-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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions