Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixfmt always updates mtime #99

Closed
felschr opened this issue Jul 31, 2023 · 5 comments
Closed

nixfmt always updates mtime #99

felschr opened this issue Jul 31, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@felschr
Copy link

felschr commented Jul 31, 2023

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'
@felschr felschr added the bug Something isn't working label Jul 31, 2023
@zimbatm
Copy link
Member

zimbatm commented Jul 31, 2023

/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
Copy link
Contributor

SebTM commented Sep 24, 2023

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

@SebTM
Copy link
Contributor

SebTM commented Nov 9, 2023

Resolved with v0.6.0 - but I can't close the issue ✌️

@zimbatm
Copy link
Member

zimbatm commented Nov 10, 2023

nixos-unstable is still on nixfmt 0.5.0 at the moment

@SebTM
Copy link
Contributor

SebTM commented Dec 4, 2023

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

@zimbatm zimbatm closed this as completed Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants