treefmt-nix
                                
                                 treefmt-nix copied to clipboard
                                
                                    treefmt-nix copied to clipboard
                            
                            
                            
                        flake-parts module breaks nix flake show
Describe the bug
When imported, nix flake show throws an error like: error: The option `perSystem.x86_64-linux.treefmt' is used but not defined. Running nix flake show again says error: 'checks.x86_64-linux' is not an attribute set
To Reproduce
This is a minimal flake.nix triggering the issue
{
  description = "Description for the project";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    treefmt-nix.url = "github:numtide/treefmt-nix";
  };
  outputs = inputs@{ flake-parts, ... }:
    flake-parts.lib.mkFlake { inherit inputs; } {
      imports = [
        inputs.treefmt-nix.flakeModule
      ];
      systems = ["x86_64-linux"];
    };
}
Error is encountered by running nix flake show or also by running nix fmt
Expected behavior
If there's a mandatory option to set in order to not have errors, have it printed in the error message or documented in the flake-parts website
System information
These are the commits in the lockfile at the moment of writing as obtained with nix flake metadata
treefmt-nix: github:numtide/treefmt-nix/42045102f90cfd23ca44ae4ef8362180fefcd7fd
flake-parts: github:hercules-ci/flake-parts/006c75898cf814ef9497252b022e91c946ba8e17
Running on x86_64-linux
I think this was fixed. At least I couldn't repro.
I'll close the issue but let me know if you still have that problem.
@zimbatm this is still happening with these inputs:
Inputs:
├───flake-parts: github:hercules-ci/flake-parts/8e8d955c22df93dbe24f19ea04f47a74adbdc5ec
│   └───nixpkgs-lib: github:NixOS/nixpkgs/4bc72cae107788bf3f24f30db2e2f685c9298dc9?dir=lib
├───nixpkgs: github:NixOS/nixpkgs/6cee3b5893090b0f5f0a06b4cf42ca4e60e5d222
└───treefmt-nix: github:numtide/treefmt-nix/719c2977f958c41fa60a928e2fbc50af14844114
    └───nixpkgs: github:nixos/nixpkgs/d9f759f2ea8d265d974a6e1259bd510ac5844c5d
The weird thing it that some nix caching is involved because it returns two different errors if I run nix flake show twice:
[zarel@playa:~/code/nix examples/linting]$ nix flake show
path:/home/zarel/code/nix examples/linting?lastModified=1689771602&narHash=sha256-l2k02g4W%2fh0c2MdgBYRwDxYqVk4Xq2%2fQjX1sP2ab%2fWc=
├───apps
│   └───x86_64-linux
├───checks
│   └───x86_64-linux
error: The option `perSystem.x86_64-linux.treefmt' is used but not defined.
(use '--show-trace' to show detailed location information)
[zarel@playa:~/code/nix examples/linting]$ nix flake show
path:/home/zarel/code/nix examples/linting?lastModified=1689771602&narHash=sha256-l2k02g4W%2fh0c2MdgBYRwDxYqVk4Xq2%2fQjX1sP2ab%2fWc=
├───apps
│   └───x86_64-linux
├───checks
│   └───x86_64-linux
error: 'checks.x86_64-linux' is not an attribute set
I'm going to open a repository for you to try this out, if it's not reproducible then I don't know what's happening since I don't have any special configuration (it's Nix 2.13.3 with sandbox and flakes enabled) and that's it
This is the minimal example that breaks the show for me https://github.com/zarelit/repro-treefmt-issue-78
I'm getting a different error on your repo:
$ nix flake show
git+file:///home/zimbatm/go/src/github.com/zarelit/repro-treefmt-issue-78?ref=refs/heads/main&rev=c4f05b1b50f3b7376169f5e91dd79626a0881a76
├───checks
│   └───x86_64-linux
error: 'checks.x86_64-linux' is not an attribute set
@zimbatm I can reproduce both error messages on my laptop.
$ nix flake show github:zarelit/repro-treefmt-issue-78
github:zarelit/repro-treefmt-issue-78/c4f05b1b50f3b7376169f5e91dd79626a0881a76
├───checks
│   └───x86_64-linux
error: 'checks.x86_64-linux' is not an attribute set
$ nix repl
Welcome to Nix 2.18.4. Type :? for help.
nix-repl> builtins.getFlake "github:zarelit/repro-treefmt-issue-78"
{ _type = "flake"; apps = { ... }; checks = { ... }; devShells = { ... }; formatter = «error: error:
       … while calling the 'head' builtin
         at /nix/store/xpnpp1sq0gmzf72r0iy2ky6r4h4i6vvb-source/lib/attrsets.nix:784:11:
          783|         || pred here (elemAt values 1) (head values) then
          784|           head values
             |           ^
          785|         else
       … while evaluating the attribute 'value'
         at /nix/store/xpnpp1sq0gmzf72r0iy2ky6r4h4i6vvb-source/lib/modules.nix:753:9:
          752|     in warnDeprecation opt //
          753|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          754|         inherit (res.defsFinal') highestPrio;
       (stack trace truncated; use '--show-trace' to show the full trace)
       error: The option `perSystem.x86_64-linux.treefmt' is used but not defined.»; inputs = { ... }; lastModified = 1689772090; lastModifiedDate = "20230719130810"; legacyPackages = { ... }; narHash = "sha256-XhdwkahFiLiwpRXIx4e2rd/i9dsNsDTQjsaaAg6Lpio="; nixosConfigurations = { ... }; nixosModules = { ... }; outPath = "/nix/store/857ncqhxma0wnrl6w4qbqz9aih9xjrd2-source"; outputs = { ... }; overlays = { ... }; packages = { ... }; rev = "c4f05b1b50f3b7376169f5e91dd79626a0881a76"; shortRev = "c4f05b1"; sourceInfo = { ... }; }
Thank you @ShamrockLee