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

mkGoEnv cannot find go package in nixpkgs #140

Open
iamfraggle opened this issue Nov 30, 2023 · 1 comment
Open

mkGoEnv cannot find go package in nixpkgs #140

iamfraggle opened this issue Nov 30, 2023 · 1 comment

Comments

@iamfraggle
Copy link

With the following flake:

{
  description = "A reimplementation of Sandstorm in Go";

  inputs = {
    nixpkgs.url = "nixpkgs/nixos-23.05";
    gomod2nix.url = "github:nix-community/gomod2nix";
  };

  outputs = { self, nixpkgs, gomod2nix }:
    let
      supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
      forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
      nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
    in
    {
      packages = forAllSystems (system:
        let
          pkgs = nixpkgsFor.${system};
          gonix = (gomod2nix.legacyPackages.${system});
          tempest-src = pkgs.fetchFromGitHub {
            name = "tempest-src";
            owner = "troyjfarrell";
            repo = "tempest";
            rev = "main";
            hash = "sha256-V2+4VXqxbUpTWYrfzxpblzbsJKhAPXe5SoCii3+zxow=";
          };
        in
        {
          tempest = gonix.mkGoEnv {
            pwd = "${tempest-src}";
            modules = ./gomod2nix.toml;
          };
        });

      defaultPackage = forAllSystems (system: self.packages.${system}.tempest);
    };
}

evaluation during nix build fails with:
error: go.mod specified Go version 1.20, but no compatible Go attribute could be found.

Yet the following works in the repl:

nix-repl> :l <nixpkgs>
Added 19222 variables.

nix-repl> :t buildPackages
a set

nix-repl> lib.reverseList (builtins.filter (attr: lib.hasPrefix "go_" attr && lib.versionAtLeast buildPackages.${attr}.version "1.20")(lib.attrNames buildPackages))
[ "go_1_20" ]
@ninjapanzer
Copy link

So I don't exactly know why this was complaining since the current go version is 1.23 and I am using 1.22 which according to the comments on https://github.com/nix-community/gomod2nix/blob/master/builder/default.nix#L129

but I did this to resolve the error and make it happy

I added a go attribute pointing to the correct go package for the project

 devShells = forEachSupportedSystem ({ pkgs, gomod2nix }: {
   default = pkgs.mkShell {
     packages = with pkgs; [
       (gomod2nix.mkGoEnv { pwd = ./.; go = go_1_22; })
       gnumake
       gomod2nix
     ];
   };
 });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants