Code Monkey home page Code Monkey logo

carla-simulator.nix's Introduction

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.

carla-simulator.nix's People

Contributors

wentasah avatar

Stargazers

 avatar aemogie. avatar  avatar Alexander Kutsan avatar  avatar  avatar GHOSCHT avatar

Watchers

 avatar  avatar  avatar Jaroslav Klapálek avatar  avatar

Forkers

junyang0412

carla-simulator.nix's Issues

Provided nix run command fails

I'm trying to run the CARLA binary with the command provided by the Readme:

nix run github:CTU-IIG/carla-simulator.nix#carla-bin_0_9_14

However this fails with following output:

error: flake 'github:CTU-IIG/carla-simulator.nix' does not provide attribute 'apps.x86_64-linux.carla-bin_0_9_14', 'packages.x86_64-linux.carla-bin_0_9_14', 'legacyPackages.x86_64-linux.carla-bin_0_9_14' or 'carla-bin_0_9_14'

Something similar happens with the other command you provided:

nix profile install github:CTU-IIG/carla-simulator.nix#scenic
error: flake 'github:CTU-IIG/carla-simulator.nix' does not provide attribute 'packages.x86_64-linux.scenic', 'legacyPackages.x86_64-linux.scenic' or 'scenic'

How would you recommend I should run CARLA on Nix? And since I'm still relatively new to Nix/NixOS, could you elaborate how I could install this without nix profile install (I'm using flakes for my own NixOS setup if that's important).

Update: It's running now, since I simply extracted the packaging code in /carla-bin into my own .nix files, but still it would be a good idea to have some up-to date instructions in the Readme.

Python module "carla" not registered by interpreter

Hey it's me again. First of all thanks for the quick answer right before Christmas.

Right now I'm trying to get the python module from this flake to work. I tried both 0.9.14 and 0.9.15 by running e.g. this in the repo-root to get the example python devshell:

nix develop .#carla-py-0_9_15

I am able to get into the shell as expected.
Logs:

nix develop .#carla-py-0_9_15
Executing setuptoolsShellHook
Finished executing setuptoolsShellHook

However when I enter the interpreter with python I cannot use the "carla" module:

python

Python 3.11.6 (main, Oct  2 2023, 13:45:54) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import carla
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'carla'

It looks like somehow the packaging of the module changed which stops python from recognizing it. When running help("modules") inside the interpreter, "carla" is nowhere to be seen in the list of present modules. I also tried using the module in the dev shell of my own project, but I got the same error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.