Skip to content

Devbox build unable to handle different versions of Go #33

Closed

Description

@RickyGrassmuck

Issue

When adding go_1_19 to my projects Devbox configuration, the devbox build command fails with the error

#0 38.04 error: collision between `/nix/store/i0rdvlkvc5sz0dr87s379j0i4xmnwrp5-go-1.18.4/bin/go' and `/nix/store/w205lbrnh8cm9680pqzw2pc07rhi43an-go-1.19/bin/go'
#0 38.15 error: builder for '/nix/store/9vrr8h6l7n1gjrl8ybb24qrvpbirvd33-devbox.drv' failed with exit code 25
------
error: failed to solve: executor failed running [/bin/sh -eux -o pipefail -c nix-env -if ./.devbox/gen/default.nix]: exit code: 100

Expected Result

A devbox container image that includes Go version 1.19

Additional Information

I dug into the code a bit and the issue is being caused by the language detection feature for Go. The Go planner builder does not contain any logic for detecting that a golang nix package has already been requested which results in both the go_1_19 and go Nix packages being added to the list of packages used for populating the default.nix and shell.nix template files.

Contents of devbox.json

{
  "packages": [
    "go_1_19"
  ]
}

Generated default.nix

let
  pkgs = import (fetchTarball {
    # Commit hash as of 2022-08-16
    # `git ls-remote https://github.com/nixos/nixpkgs nixos-unstable`
    url = "https://github.com/nixos/nixpkgs/archive/af9e00071d0971eb292fd5abef334e66eda3cb69.tar.gz";
    sha256 = "1mdwy0419m5i9ss6s5frbhgzgyccbwycxm5nal40c8486bai0hwy";
  }) {};
in with pkgs;
buildEnv {
  name = "devbox";
  paths = [
    go_1_19
  
    go
  ];
  pathsToLink = [ "/bin" ];
}

Generated shell.nix

let
  pkgs = import (fetchTarball {
    # Commit hash as of 2022-08-16
    # `git ls-remote https://github.com/nixos/nixpkgs nixos-unstable`
    url = "https://github.com/nixos/nixpkgs/archive/af9e00071d0971eb292fd5abef334e66eda3cb69.tar.gz";
    sha256 = "1mdwy0419m5i9ss6s5frbhgzgyccbwycxm5nal40c8486bai0hwy";
  }) {};
in with pkgs;
mkShell {
  shellHook =
    ''
      echo "Starting a devbox shell..."
      export name="devbox"
      export IN_NIX_SHELL=0
      export DEVBOX_SHELL_ENABLED=1
    '';
  packages = [
    go_1_19
  
    go
  ];
}

Possible Solutions

I started poking around at a solution for handling this and at first I was going to just add a check in the Go planner's IsRelevant() method when I realized that this problem will not be limited to just Golang. I can think of 2 different methods for addressing this:

  1. Modify the Planner interface in a way that forwards user-specified packages to each languages Planner in a way that allows it to create it's build plan using the user-specified language version and removing that entry from the user-specified packages list
  2. Implement language version detection in each planner (ie. parsing go.mod/pyproject.toml for versions) and add collision checking for user-specified packages elsewhere.

I figured I'd forgo sending in a PR since this probably warrants a discussion before deciding on how this situation is handled.

Activity

  1. loreto commented on Aug 30, 2022

    @loreto
    Contributor

    Thanks @RickyGrassmuck

    We're discussing internally – we're leaning towards option 2.

  2. loreto commented on Aug 31, 2022

    @loreto
    Contributor

    This PR: #49 should fix this issue. It should make it in this week's release.

  3. loreto commented on Aug 31, 2022

    @loreto
    Contributor

    To be specific: it'll make it so you don't have to add go_1_19 manually, since devbox itself will use the right package based on your go.mod.

  4. loreto commented on Sep 1, 2022

    @loreto
    Contributor

    PR Merged. Closing. It'll come out in a release tomorrow.

    I know there's still an issue around improving package collisions overall, but we'll deal with that separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions