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

Using flakes with go.mod replace directives #101

Open
albertkoch opened this issue Jan 26, 2023 · 0 comments
Open

Using flakes with go.mod replace directives #101

albertkoch opened this issue Jan 26, 2023 · 0 comments

Comments

@albertkoch
Copy link

When building a go application with buildGoApplication, replace directives are always treated as relative values. Unfortunately with flakes, this means they are relative to the source's path in the nix store. E.g. /nix/store/i0mx81w7qj13i90f9xkzk0dzhk6h0hwv-source

{
  inputs = {
    gomod2nix = {
      inputs.nixpkgs.follows = "nixpkgs";
      url = "github:nix-community/gomod2nix";
    };
    nixpkgs.url = "github:NixOS/nixpkgs/master";
  };
  outputs = { self, gomod2nix, nixpkgs }:
    let
      pkgs = import nixpkgs {
        system = "x86_64-linux";
        overlays = [
          gomod2nix.overlays.default
        ];
      };
    in {
      packages.x86_64-linux.default = pkgs.buildGoApplication {
        modules = ./gomod2nix.toml;
        name = "demo";
        pwd = ./.;
        src = pkgs.lib.cleanSource ./.;
      };
    };
}
nix build --impure

This works with a replace directive such as:

replace github.com/owner/example => ../../../home/username/projects/example

But fails with a replace directive such as:

replace github.com/owner/example => /home/username/projects/example
/nix/store/i0mx81w7qj13i90f9xkzk0dzhk6h0hwv-source/home/username/projects/example': No such file or directory

Conversely, when running go mod tidy and gomod2nix to generate gomod2nix.toml, the replace directive must either be absolute, or relative to the source in my home directory. This means I maintain two replace directives, one for building, and one for updating dependencies, and swap between the two.

It would be nice if absolute paths were not concatenated with the nix store directory when building, so an absolute path could be used in both scenarios without constantly swapping directives.

I think this is the nix flakes variant of the issue that was addressed in #2.

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

1 participant