I got cdogs to compile......but only once!

Ok, as some more learning exercises (the best way to learn something is do something with it) , and my success with super methane brothers, I’d though i’d give cdogs a try.

I got it to compile and run!!! but only once!!! yep you heard it , only once! That was using a nix-shell … however, it would not compile in a pure nix shell.

i suspect some fixed output derivation caused by python3.withPackages or some non-determinism in the actual cdogs build, or impurity in my shell, or the nix-shell causing strange effect in my calling enviroment… yikes!! :slight_smile:

It uses the dreaded google protobuf, and needs python3 with python protobufs binding installed.

I’m probably doing something not quite right here… non-determinism in builds make me shudder, i know it does happen…i’ve fixed many of broken builds.(not mine)…

This is could be do a impurity in my system, or something in the nix-shell modified my environment… quite possible… this maybe broken, but the only thing that’s got me thinking , is why did it compile that one time??? it’s got to be the ordering of the build… and i was lucky!..

maybe it’s bringing it’s own protobufs…but i’ve got to put it down for now.

{ lib
, stdenv
, fetchFromGitHub
, pkg-config
, SDL2
, SDL2_image
, SDL2_mixer
, fontconfig
, freealut
, freeglut
, gettext
, libGL
, libGLU
, openal
, quesoglc
, libXrender
, libmikmod
, alsaLib
, cmake
, gtk3-x11
, python3
, protobuf 
}:

stdenv.mkDerivation rec {
  pname = "cdogs";
  version = "0.11.0";

  src = fetchFromGitHub {
    repo = "cdogs-sdl";
    owner = "cxong";
    rev = "${version}";
    sha256 = "sha256-zWwlcEM2KsYiB48cmRTjou0C86SqeoOLrbacCR0SfIA=";
  };

  nativeBuildInputs = [
    gettext
    pkg-config
    cmake 
    (python3.withPackages (pp: with pp; [ protobuf setuptools ]))
  ];
  buildInputs = [
    SDL2
    SDL2_image
    SDL2_mixer
    fontconfig
    freealut
    freeglut
    libGL
    libGLU
    openal
    quesoglc
    libXrender
    libmikmod
    alsaLib
    gtk3-x11
    protobuf
  ];

  installPhase  = ''
    #runHook preInstall
    #runHook postInstall
  '';

  meta = with lib; {
    homepage = "https://cxong.github.io/cdogs-sdl";
    description = "Open sourcem ckassic overhead run-and-gun game";
    license = licenses.gpl2Only;
    maintainers = with maintainers; [ nixinator ];
    platforms = platforms.unix;
  };
}

saw

[ 10%] Running C++ protocol buffer compiler using nanopb plugin on msg.proto
/build/source/build/src/proto/nanopb/generator/protoc-gen-nanopb: exec: line 13: /build/source/build/src/proto/nanopb/generator/nanopb_generator.py: not found
--nanopb_out: protoc-gen-nanopb: Plugin failed with status code 127.

this is solved with

  postPatch = ''
    patchShebangs src/proto/nanopb/generator/*
  '';

then, I got:

couldn’t import module ‘google’

this is because (python3.withPackages (pp: with pp; [ protobuf setuptools ])) was grabbing the protobuf from the attr set at the top, not from pp

so, fixed with:

(python3.withPackages (pp: with pp; [ pp.protobuf setuptools ]))

then remove the installPhase and let Cmake do it’s thing

-  installPhase  = ''
-    #runHook preInstall
-    #runHook postInstall
-  '';
-

finally, they default the data installation directory to "." for linux https://github.com/cxong/cdogs-sdl/blob/d7502fd53619459144f955c3c9f2bf635139bb07/CMakeLists.txt#L187. So that needs to be set

  cmakeFlags = [ "-DCDOGS_DATA_DIR=${placeholder "out"}/" ];

altogether:

--- a/original.nix
+++ b/tmp.nix
@@ -33,11 +33,17 @@ stdenv.mkDerivation rec {
     sha256 = "sha256-zWwlcEM2KsYiB48cmRTjou0C86SqeoOLrbacCR0SfIA=";
   };

+  postPatch = ''
+    patchShebangs src/proto/nanopb/generator/*
+  '';
+
+  cmakeFlags = [ "-DCDOGS_DATA_DIR=${placeholder "out"}/" ];
+
   nativeBuildInputs = [
     gettext
     pkg-config
     cmake
-    (python3.withPackages (pp: with pp; [ protobuf setuptools ]))
+    (python3.withPackages (pp: with pp; [ pp.protobuf setuptools ]))
   ];
   buildInputs = [
     SDL2
@@ -57,11 +63,6 @@ stdenv.mkDerivation rec {
     protobuf
   ];

-  installPhase  = ''
-    #runHook preInstall
-    #runHook postInstall
-  '';
-
   meta = with lib; {
     homepage = "https://cxong.github.io/cdogs-sdl";
     description = "Open sourcem ckassic overhead run-and-gun game";

was able to launch the game and start a campaign

1 Like

super! Thanks for the fixes…

i need to my head around the scoping here…

(python3.withPackages (pp: with pp; [ pp.protobuf setuptools ]))

i have no idea has i got it compile once… maybe it was just a dream…