Compilation error when using `cbc` package as part of a flake on MacOS

I’m new to Nix, and trying to formulate a flake for a package where I’m part of the development team.

The general package seems to work, but I now want to add some of the optional dependencies. One of these dependencies is the cbc package, which has an old codebase. Because it uses the register type, the package definition contains the following line: https://github.com/NixOS/nixpkgs/blob/d6a0fea30ee3921729a2d62611cd7f097f4d0409/pkgs/applications/science/math/cbc/default.nix#L17

This seems to work correctly, because when I run nix shell nixpkgs#cbc I get an environment with a working cbc executable.

Building my flake, with the definition underneath, without the cbc dependency works. However, trying in my flake with the cbc package dependency, the nix build . command will fail with many errors like:

CoinOslFactorization3.cpp:2594:15: error: ISO C++17 does not allow 'register' storage class specifier 

It seems to me like the rule enforcing C++14 is not taken into account. Am I doing something wrong? How can I resolve this problem?

flake.nix

{
  description = "Medium-level constraint modelling language";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
      in
      {
        packages = {
          minizinc = pkgs.callPackage ./default.nix { };
          default = self.packages.${system}.minizinc;
        };

        devShells.default = pkgs.mkShell {
          name = "minizinc";
          inputsFrom = [ self.packages.${system}.minizinc ];

          packages = with pkgs; [
            bison
            flex
            ccache
          ];
        };
      });
}

default.nix

{ lib, stdenv, cbc, cmake, gecode, mpfr, ninja, zlib }:

stdenv.mkDerivation {
  name = "minizinc";
  src = ./.;

  nativeBuildInputs = [ cmake ninja ];
  buildInputs = [ gecode mpfr zlib cbc ];

  meta = with lib; {
    homepage = "https://www.minizinc.org/";
    description = "A medium-level constraint modelling language";
    longDescription = ''
      MiniZinc is a medium-level constraint modelling
      language. It is high-level enough to express most
      constraint problems easily, but low-level enough
      that it can be mapped onto existing solvers easily and consistently.
    '';
    license = licenses.mpl20;
    platforms = platforms.unix;
  };
}
1 Like

I’m still not sure what is going on, but it seems I’m able to circumvent the issue when adding the cbc derivation directly into my flake codebase.

I’ve copied https://github.com/NixOS/nixpkgs/blob/d6a0fea30ee3921729a2d62611cd7f097f4d0409/pkgs/applications/science/math/cbc/default.nix as ./nix/cbc.nix

Added

cbc = pkgs.callPackage ./nix/cbc.nix { };

to the let expression in flake.nix

and added inherit cbc to the minizinc callPackage, and it now once again seems to build.

Can anyone explain to my what the difference is. Why doesn’t the isClang check work when just using the normal package?