Skip to content

darwin: go: cycle detected in the references of ... (a private go package) #18131

@mstone

Description

@mstone

Overview

I was just bit by the same issue as #10599 while building a private go package on Darwin and as a result, I'd like to document my debugging efforts so that others who encounter similar problems may find my workaround between now and whenever we decide how to fix the issue for real.

Issue description

The symptom of the issue was that while running nix-build -K -I nixpkgs=~/nixpkgs -j2 --cores 2 shell.nix with a recent checkout of nixpkgs (5120af0) on a nix-expression using buildGoPackage to define a multiple-output derivation, I got a cyclic reference error like this one:

cycle detected in the references of ‘/nix/store/43wwl5kgh0z9yd92ydc7jahy1yjipmwk-go1.6-whist-20160816-ca1fec0-bin’

The fix, as in #10599, is to use install_name_tool to repoint the offending LC_RPATH tag.

Diagnosis

To diagnose the cause(s) of the problem, I rebuilt nix-1.11.3 with a custom backport of NixOS/nix@c87a56f (temporarily published at mstone/nix@a715d9e) which gave me the following clue:

cycle detected in the references of ‘/nix/store/43wwl5kgh0z9yd92ydc7jahy1yjipmwk-go1.6-whist-20160816-ca1fec0-bin’ from ‘/nix/store/baswj95p801zlfhjxarran4xdyjgz4g8-go1.6-whist-20160816-ca1fec0’

Using this clue, I cd'ed to the build directory I kept with nix-build -K and grepped env-vars for the values of out= and bin= and then, using the $bin directory, I ran grep -r baswj95p801zlfhjxarran4xdyjgz4g8 /nix/store/43wwl5kgh0z9yd92ydc7jahy1yjipmwk-go1.6-whist-20160816-ca1fec0-bin to find out which files contained cyclic references, which produced one output:

Binary file /nix/store/43wwl5kgh0z9yd92ydc7jahy1yjipmwk-go1.6-whist-20160816-ca1fec0-bin/bin/.whist-wrapped matches

Next, to find out why this file contained a cyclic reference, I fiddled with otool until I ran otool -l /nix/store/43wwl5kgh0z9yd92ydc7jahy1yjipmwk-go1.6-whist-20160816-ca1fec0-bin/bin/.whist-wrapped | grep -C 5 baswj95p801zlfhjxarran4xdyjgz4g8 which indicated that the problem was an inappropriate LC_RPATH setting:

Load command 16
          cmd LC_RPATH
      cmdsize 96
         path /nix/store/baswj95p801zlfhjxarran4xdyjgz4g8-go1.6-whist-20160816-ca1fec0/lib (offset 12)

just as in #10599.

Finally, to fix the problem locally, I applied the fixes proposed in 86dae70 and 4e1fdad to my own nix expression and, thankfully, they worked just fine for me once I adapted them to repoint LC_RPATH from $lib to $bin (since buildGoPackage produces derivations with outputs named out and bin, but not lib).

/cc @pikajude @vcunat @ttuegel

Metadata

Metadata

Assignees

No one assigned

    Labels

    6.topic: darwinRunning or building packages on Darwin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions