Golang delve debugger with Nix Flake issue

Hi, when I try to run delve inside a nix shell, I get the following error message after running command dlv debug:

# runtime/cgo
In file included from /nix/store/2zgwnn9hc3v9c6pippmrh730rlb9apv2-glibc-2.35-163-dev/include/bits/libc-header-start.h:33,
                 from /nix/store/2zgwnn9hc3v9c6pippmrh730rlb9apv2-glibc-2.35-163-dev/include/stdlib.h:26,
                 from _cgo_export.c:3:
/nix/store/2zgwnn9hc3v9c6pippmrh730rlb9apv2-glibc-2.35-163-dev/include/features.h:412:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]
  412 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
      |    ^~~~~~~
cc1: all warnings being treated as errors
exit status 2

My Nix shell is:

{ pkgs ? import <nixpkgs> {} }:

with pkgs;


mkShell {
  nativeBuildInputs = [
    go_1_18
    delve
  ];
}

And flake.nix is:

{
  description = "golang development";

  inputs.flake-utils.url = "github:numtide/flake-utils";

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem
      (system:
        let pkgs = nixpkgs.legacyPackages.${system}; in
        {
          devShell = import ./shell.nix { inherit pkgs; };
        }
      );
}

Running nix-shell then dlv debug works fine - just inside the flake it fails with that error message. If I comment out the line pointed to in the error message it works just fine too. Though that’s not much of a Nix-like solution! Anyone know what I could do to fix this?

Hi there,

I ran into this issue too, and while I didn’t have the chance to figure out the root cause, I was able to work around it by disabling CGO via an environment variable. This can be done by adding CGO_ENABLED = 0; to the mkShell invocation.

Via this bug report, It looks like another way to work around it is by adding hardeningDisable = [ "all" ];.

Hope this helps!

1 Like