numtide / treefmt-nix

treefmt nix configuration
https://numtide.github.io/treefmt/
MIT License
270 stars 83 forks source link

nixfmt always updates mtime #99

Closed felschr closed 12 months ago

felschr commented 1 year ago

Describe the bug

Running nixfmt always sets the mtime to the current date even if the contents didn't change.

To Reproduce

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

    flake-parts.url = "github:hercules-ci/flake-parts";
    flake-parts.inputs.nixpkgs.follows = "nixpkgs";

    treefmt-nix.url = "github:numtide/treefmt-nix";
    treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = inputs@{ flake-parts, ... }:
    flake-parts.lib.mkFlake { inherit inputs; } {
      imports = [
        inputs.treefmt-nix.flakeModule
      ];
      systems = ["x86_64-linux"];
      perSystem = { pkgs, ... }: {
        treefmt = {
          programs.nixfmt.enable = true;
          programs.nixfmt.package = pkgs.nixfmt;
        };
      };
    };
}

Add some nix files to the workspace and observe the mtime each time treefmt --no-cache is run.

Expected behavior

treefmt-nix should not support nixfmt since it changes mtime and thus doesn't comply with idempotence requirement of the formatter specification.

Additionally it would be nice to have a list on https://numtide.github.io/treefmt/formatters/ with known unsupported formatters and their reasons for not being supported.

System information

Inputs:
├───flake-parts: github:hercules-ci/flake-parts/8e8d955c22df93dbe24f19ea04f47a74adbdc5ec
│   └───nixpkgs-lib follows input 'nixpkgs'
├───nixpkgs: github:NixOS/nixpkgs/6cee3b5893090b0f5f0a06b4cf42ca4e60e5d222
└───treefmt-nix: github:numtide/treefmt-nix/f4ce7d8660f57fe94092cf113c1f550acf16be53
    └───nixpkgs follows input 'nixpkgs'
zimbatm commented 1 year ago

/cc @SebTM that added the formatter.

Fixing that issue upstream is generally relatively easy so I would suggest contacting them and asking if they can make the formatter compliant with the treefmt formatter spec.

SebTM commented 1 year ago

See referenced issue, I summarized the report and issue but I can't address it due to lack of Haskell knowledge myself.

SebTM commented 1 year ago

Resolved with v0.6.0 - but I can't close the issue :v:

zimbatm commented 1 year ago

nixos-unstable is still on nixfmt 0.5.0 at the moment

SebTM commented 1 year ago

NixOS 23.11 got released and includes nixfmt v0.6.0 by default ✌🏻