Skip to content

Nix expressions for building Carla simulator and related software

License

Notifications You must be signed in to change notification settings

CTU-IIG/carla-simulator.nix

Repository files navigation

Nix expressions for the CARLA simulator

This is a work-in-progress. The interface can change any time.

To use this repository, you have to install Nix.

The repository contains a Nix flake with the CARLA simulator and related tools. An easy way to test it to run:

nix run github:CTU-IIG/carla-simulator.nix#carla-bin-0_9_15

and in another terminal:

nix shell github:CTU-IIG/carla-simulator.nix#carla-py-scripts-0_9_15 --command carla-example-manual_control.py

The full content of the flake is:

carla-simulator.nix
├───checks
│   └───x86_64-linux
│       └───ci: derivation 'carla-all'
├───devShells
│   └───x86_64-linux
│       ├───carla-cpp: development environment 'Shell-for-building-CARLA-C++-examples'
│       ├───carla-py: development environment 'Shell-for-running-CARLA-PythonAPI-examples'
│       └───default: development environment 'carla-build-shell-env'
├───legacyPackages
│   └───x86_64-linux omitted (use '--legacy' to show)
├───overlays
│   ├───"0.9.12": Nixpkgs overlay
│   ├───"0.9.13": Nixpkgs overlay
│   ├───"0.9.14": Nixpkgs overlay
│   └───"0.9.15": Nixpkgs overlay
└───packages
    └───x86_64-linux
        ├───carla-bin-0_9_12: package 'CarlaUE4.sh'
        ├───carla-bin-0_9_13: package 'CarlaUE4.sh'
        ├───carla-bin-0_9_14: package 'CarlaUE4.sh'
        ├───carla-bin-0_9_15: package 'CarlaUE4.sh'
        ├───carla-py-0_9_12: package 'python3.11-carla-py-0.9.12'
        ├───carla-py-0_9_13: package 'python3.11-carla-py-0.9.13'
        ├───carla-py-0_9_14: package 'python3.11-carla-py-0.9.14'
        ├───carla-py-0_9_15: package 'python3.11-carla-py-0.9.15'
        ├───carla-py-scripts-0_9_12: package 'carla-py-scripts-0.9.12'
        ├───carla-py-scripts-0_9_13: package 'carla-py-scripts-0.9.13'
        ├───carla-py-scripts-0_9_14: package 'carla-py-scripts-0.9.14'
        ├───carla-py-scripts-0_9_15: package 'carla-py-scripts-0.9.15'
        ├───carla-src-0_9_12: package 'source'
        ├───carla-src-0_9_13: package 'source'
        ├───carla-src-0_9_14: package 'source'
        ├───carla-src-0_9_15: package 'source'
        ├───libcarla-client-0_9_12: package 'libcarla-client-0.9.12'
        ├───libcarla-client-0_9_13: package 'libcarla-client-0.9.13'
        ├───libcarla-client-0_9_14: package 'libcarla-client-0.9.14'
        ├───libcarla-client-0_9_15: package 'libcarla-client-0.9.15'
        ├───opencv-python-0_9_12: package 'python3.11-opencv-python-4.8.1.78'
        ├───opencv-python-0_9_13: package 'python3.11-opencv-python-4.8.1.78'
        ├───opencv-python-0_9_14: package 'python3.11-opencv-python-4.8.1.78'
        ├───opencv-python-0_9_15: package 'python3.11-opencv-python-4.8.1.78'
        ├───osm2odr-0_9_12: package 'osm2odr-0.pre+date=2022-08-30'
        ├───osm2odr-0_9_13: package 'osm2odr-0.pre+date=2022-08-30'
        ├───osm2odr-0_9_14: package 'osm2odr-0.pre+date=2022-08-30'
        ├───osm2odr-0_9_15: package 'osm2odr-0.pre+date=2022-08-30'
        ├───recast-0_9_12: package 'recast-0.pre+date=2022-08-30'
        ├───recast-0_9_13: package 'recast-0.pre+date=2022-08-30'
        ├───recast-0_9_14: package 'recast-0.pre+date=2022-08-30'
        ├───recast-0_9_15: package 'recast-0.pre+date=2023-02-21'
        ├───rpclib-0_9_12: package 'rpclib-0.pre+date=2022-08-30'
        ├───rpclib-0_9_13: package 'rpclib-0.pre+date=2022-08-30'
        ├───rpclib-0_9_14: package 'rpclib-0.pre+date=2022-08-30'
        ├───rpclib-0_9_15: package 'rpclib-0.pre+date=2022-08-30'
        ├───scenario-runner-0_9_12: package 'python3.11-scenario-runner-0.9.13'
        ├───scenario-runner-0_9_13: package 'python3.11-scenario-runner-0.9.13'
        ├───scenario-runner-0_9_14: package 'python3.11-scenario-runner-0.9.13'
        ├───scenario-runner-0_9_15: package 'python3.11-scenario-runner-0.9.13'
        ├───scenic-0_9_12: package 'python3.11-scenic-2.1.0'
        ├───scenic-0_9_13: package 'python3.11-scenic-2.1.0'
        ├───scenic-0_9_14: package 'python3.11-scenic-2.1.0'
        ├───scenic-0_9_15: package 'python3.11-scenic-2.1.0'
        └───ue4: package 'ue4-carla-0.9.13-wrapper'

The outputs are documented in more detail below. Unfinished (experimental) outputs are omitted.

devShells

Python

To quickly try CARLA Python bindings from this repository, execute CARLA (e.g. via a package in this repo) and then run:

nix develop .#carla-py
cd <CARLA_SOURCES>/PythonAPI/examples
./manual_control.py

If you have trouble getting graphical output on non-NixOS distribution, use NixGL, e.g.:

NIXPKGS_ALLOW_UNFREE=1 nix run --impure github:guibou/nixGL -- ./manual_control.py

C++

To compile CARLA CppClient example, run:

nix develop .#carla-cpp
cd <CARLA_SOURCES>/Examples/CppClient
g++ -std=c++14 -pthread -fPIC -O3 -DNDEBUG -Werror -Wall -Wextra -o cpp_client main.cpp \
    -Wl,-Bstatic -lcarla_client -lrpc \
    -Wl,-Bdynamic -lpng -ltiff -ljpeg -lRecast -lDetour -lDetourCrowd -lboost_filesystem

Instead of running g++ manually, you can use the Makefile coming with the example, but you need to modify it not to use hardcoded compiler paths, not to build libcarla and to link boost_filesystem dynamically.

overlays

Overlays output contains Nixpkgs overlays for different CARLA versions. Use these in you Nix expressions or NixOS configurations.

A minimalist flake-based NixOS configuration with CARLA could look like this:

{
  inputs = {
    nixpkgs.url = "nixpkgs";
    carla = { url = "github:CTU-IIG/carla-simulator.nix"; inputs.nixpkgs.follows = "nixpkgs"; };
  };
  outputs = { self, nixpkgs, carla }: {
    nixosConfigurations."carla-box" = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        ({ config, pkgs, ... }: {
          nixpkgs.overlays = [ carla.overlays."0.9.14" ];
          environment.systemPackages = [ pkgs.carla-bin ];
          boot.isContainer = true;
        })
      ];
    };
  };
}

packages

The packages output contains CARLA binary releases as well as the packages from all CARLA version overlays applied to a random nixpkgs version (locked in flake.lock).

Use these, for example, to run or install the packages on your computer, e.g.:

  • nix run github:CTU-IIG/carla-simulator.nix#carla-bin-0_9_14
  • nix profile install github:CTU-IIG/carla-simulator.nix#scenic-0_9_14

If CARLA fails to display anything using the command above, you may need override flake's nixpkgs input to use the same glibc version as your system (this is for compatibility with your system's libvulkan etc.). For example:

nix run --override-input nixpkgs nixpkgs/nixos-23.11 .#carla-bin-0_9_14

On non-NixOS systems, you may also need to use NixGL.

carla-bin.withAssets

Packages carla-bin-* can be extended by custom assets such as additional maps and/or vehicles. You can use carla-bin.withAssets function for that. The assets parameter should be a list of tarballs, zip files or derivations with assets. Using derivations has the advantage that the same asset can be reused in multiple versions of CARLA without consuming additional storage space.

See the following example (try it with nix repl and :lf .):

let
  pkgs = import inputs.nixpkgs {};
  carla-bin = packages.x86_64-linux.carla-bin-0_9_15;
  maps-tar = pkgs.fetchurl {
    url = "https://carla-releases.s3.us-east-005.backblazeb2.com/Linux/AdditionalMaps_0.9.15.tar.gz";
    sha256 = "0hz11k26jp2rm9xfh9z6n5g53y799hzab5hz69x0y9j6rs04xbac";
  };
  maps = pkgs.runCommand "carla-maps" { } ''mkdir $out && cd $out && tar xf ${maps-tar}'';
in {
  carla-with-maps = carla-bin.withAssets [ maps-tar ];
  carla-with-maps2 = carla-bin.withAssets [ maps ];
}

TODO

We wanted to build Carla and Unreal Engine from source via Nix. However, this is tricky and currently, it's not our top priority. It should work as follows:

  • Building Unreal Engine:

    cd build-env
    nix-shell

    Then follow the official Carla build instructions. Note that this is not yet complete and compilation will likely fail at some stage.

Contact

Feel free to contact us by submitting issues.

About

Nix expressions for building Carla simulator and related software

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published