Skip to content

goimports: nix flake check no longer works #318

@jaredmontoya

Description

@jaredmontoya

Describe the bug
With the new release of GO and goimports in nixpkgs the goimports formatter in treefmt-nix now fails to execute nix flake check

To Reproduce

Steps to reproduce the behavior:

  1. Create a repository that has go code in it
  2. set up a nix flake with treefmt-nix
  3. you can use this lockfile to get the old nixpkgs version with the old working go/goimports release
{
  "nodes": {
    "flake-utils": {
      "inputs": {
        "systems": "systems"
      },
      "locked": {
        "lastModified": 1694529238,
        "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
        "owner": "numtide",
        "repo": "flake-utils",
        "rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
        "type": "github"
      },
      "original": {
        "owner": "numtide",
        "repo": "flake-utils",
        "type": "github"
      }
    },
    "gomod2nix": {
      "inputs": {
        "flake-utils": "flake-utils",
        "nixpkgs": [
          "nixpkgs"
        ]
      },
      "locked": {
        "lastModified": 1733668782,
        "narHash": "sha256-tPsqU00FhgdFr0JiQUiBMgPVbl1jbPCY5gbFiJycL3I=",
        "owner": "nix-community",
        "repo": "gomod2nix",
        "rev": "514283ec89c39ad0079ff2f3b1437404e4cba608",
        "type": "github"
      },
      "original": {
        "owner": "nix-community",
        "repo": "gomod2nix",
        "type": "github"
      }
    },
    "nixpkgs": {
      "locked": {
        "lastModified": 1736344531,
        "narHash": "sha256-8YVQ9ZbSfuUk2bUf2KRj60NRraLPKPS0Q4QFTbc+c2c=",
        "owner": "nixos",
        "repo": "nixpkgs",
        "rev": "bffc22eb12172e6db3c5dde9e3e5628f8e3e7912",
        "type": "github"
      },
      "original": {
        "owner": "nixos",
        "ref": "nixos-unstable",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
    "root": {
      "inputs": {
        "gomod2nix": "gomod2nix",
        "nixpkgs": "nixpkgs",
        "systems": "systems_2",
        "treefmt-nix": "treefmt-nix"
      }
    },
    "systems": {
      "locked": {
        "lastModified": 1681028828,
        "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
        "owner": "nix-systems",
        "repo": "default",
        "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
        "type": "github"
      },
      "original": {
        "owner": "nix-systems",
        "repo": "default",
        "type": "github"
      }
    },
    "systems_2": {
      "locked": {
        "lastModified": 1681028828,
        "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
        "owner": "nix-systems",
        "repo": "default",
        "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
        "type": "github"
      },
      "original": {
        "owner": "nix-systems",
        "repo": "default",
        "type": "github"
      }
    },
    "treefmt-nix": {
      "inputs": {
        "nixpkgs": [
          "nixpkgs"
        ]
      },
      "locked": {
        "lastModified": 1736154270,
        "narHash": "sha256-p2r8xhQZ3TYIEKBoiEhllKWQqWNJNoT9v64Vmg4q8Zw=",
        "owner": "numtide",
        "repo": "treefmt-nix",
        "rev": "13c913f5deb3a5c08bb810efd89dc8cb24dd968b",
        "type": "github"
      },
      "original": {
        "owner": "numtide",
        "repo": "treefmt-nix",
        "type": "github"
      }
    }
  },
  "root": "root",
  "version": 7
}
  1. try doing nix flake check and it will work
  2. execute nix flake update to update inputs
  3. try nix flake check and you should get an output similar to this:
ERRO formatter | goimports: failed to apply with options '[-w]': exit status 2

err: go command required, not found: exec: "go": executable file not found in $PATH: stderr: 
err: go command required, not found: exec: "go": executable file not found in $PATH: stderr: 
err: go command required, not found: exec: "go": executable file not found in $PATH: stderr: 
err: go command required, not found: exec: "go": executable file not found in $PATH: stderr: 
err: go command required, not found: exec: "go": executable file not found in $PATH: stderr: 

Instead of setting up a project from scratch you can also just perform nix flake check test before and after nix flake update on a real life example: https://github.com/danielmiessler/fabric

Expected behavior
It should work as it worked before

System information
NixOS unstable

Additional context

Maintainer ping
@gabyx

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