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

error: unable to execute /nix/store/goo-bar-0.0.1/bin/foo No such file or directory #144

Open
milosgajdos opened this issue Dec 24, 2023 · 5 comments

Comments

@milosgajdos
Copy link

milosgajdos commented Dec 24, 2023

I have the following flake that attempts to use this module:

{
  description = "A basic gomod2nix flake";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.gomod2nix.url = "github:nix-community/gomod2nix";
  inputs.gomod2nix.inputs.nixpkgs.follows = "nixpkgs";
  inputs.gomod2nix.inputs.flake-utils.follows = "flake-utils";

  outputs = { self, nixpkgs, flake-utils, gomod2nix }:
    (flake-utils.lib.eachDefaultSystem
      (system:
        let
          pkgs = nixpkgs.legacyPackages.${system};

          # The current default sdk for macOS fails to compile go projects, so we use a newer one for now.
          # This has no effect on other platforms.
          callPackage = pkgs.darwin.apple_sdk_11_0.callPackage or pkgs.callPackage;
        in
        {
          packages.default = callPackage ./. {
            inherit (gomod2nix.legacyPackages.${system}) buildGoApplication;
          };
          devShells.default = callPackage ./shell.nix {
            inherit (gomod2nix.legacyPackages.${system}) mkGoEnv gomod2nix;
          };
        })
    );
}

Here is the default.nix

{ pkgs ? (
    let
      inherit (builtins) fetchTree fromJSON readFile;
      inherit ((fromJSON (readFile ./flake.lock)).nodes) nixpkgs gomod2nix;
    in
    import (fetchTree nixpkgs.locked) {
      overlays = [
        (import "${fetchTree gomod2nix.locked}/overlay.nix")
      ];
    }
  )
, buildGoApplication ? pkgs.buildGoApplication
}:

buildGoApplication {
  pname = "foo";
  version = "0.0.1";
  pwd = ./.;
  src = ./.;
  modules = ./gomod2nix.toml;
  doCheck = false;
}

When I try to run nix run I get an error

$ nix run . -- -help
error: unable to execute '/nix/store/pypjdy02h7ydx9zsccng8a7vbay2j70y-foo-0.0.1/bin/foo': No such file or directory

Running nix develop and nix shell work fine. Equally I'd expect nix build to generate the binary but the result is linked to an empty directory. I'm sure I'm missing something but I'm not sure what.

This is a simple project that has main.go file in the root of it.

@hmajid2301
Copy link

What does your go.mod file look like, does it the module end in foo?

@milosgajdos
Copy link
Author

@hmajid2301 ah, sorry for the late reply -- I was away for a while and my GH notifications got outta control in the meantime. I'm only just getting through them now.

What does your go.mod file look like, does the module end in foo?

In this specific case, yes the module name did indeed end in foo, but I'm now not sure what was going on; my memory is fading. I'm now battling a different issue: how to build Go projects that embed static files 😓 (using this flake)

Log
$ nix run . -- -help
path '.../src/github.com/milosgajdos/embeviz/ui' does not contain a 'flake.nix', searching up
warning: Git tree '.../src/github.com/milosgajdos/embeviz' is dirty
error: builder for '/nix/store/iiivb74x8kp3s1zza2x6paqllrrqrclg-embeviz-0.0.1.drv' failed with exit code 1;
       last 9 log lines:
       > Running phase: unpackPhase
       > unpacking source archive /nix/store/sjvp7350vd8q962329q2w1b9h8w20skb-z8jqan9hfl6j19id7g7cl1gmpi1jmyw1-source
       > source root is z8jqan9hfl6j19id7g7cl1gmpi1jmyw1-source
       > Running phase: patchPhase
       > Running phase: updateAutotoolsGnuConfigScriptsPhase
       > Running phase: configurePhase
       > Running phase: buildPhase
       > Building subPackage .
       > main.go:40:12: pattern ui/dist/*: no matching files found
       For full logs, run 'nix log /nix/store/iiivb74x8kp3s1zza2x6paqllrrqrclg-embeviz-0.0.1.drv'.

But that's a whole another issue I concur!

@hmajid2301
Copy link

Yeh no idea about embedding static files 😢. I had the same issue as you with the module name!

@milosgajdos
Copy link
Author

How did you resolve it? The original repo that led to this report is on a machine I no longer have access to

@hmajid2301
Copy link

I had to match the name here https://gitlab.com/hmajid2301/optinix/-/blob/main/default.nix?ref_type=heads#L16 to the one in go.mod that fixed what was causing your original issue.

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