Need help getting Zephyr RTOS native_posix target working from an x86_64 host

This page summarizes the projects mentioned and recommended in the original post on /r/NixOS

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • non-c-on-zephyr

    Code from the Non-C Languages on Zephyr

    I've got a Nix shell (adapted from here with updates to a newer Zephyr SDK) that works to build for ARM, but doesn't work for the native_posix Zephyr target board (which is 32-bit). It can't find 32-bit libraries to link against (asan is the first that fails).

  • nixpkgs

    Nix Packages collection & NixOS

    # Basic configuration for Zephyr development. { pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/refs/tags/23.05.tar.gz") { } }: let pp = pkgs.python3.pkgs; imgtool = pp.buildPythonPackage rec { version = "1.10.0"; pname = "imgtool"; src = pp.fetchPypi { inherit pname version; sha256 = "sha256-A7NOdZNKw9lufEK2vK8Rzq9PRT98bybBfXJr0YMQS0A="; }; propagatedBuildInputs = with pp; [ cbor2 click intelhex cryptography ]; doCheck = false; pythonImportsCheck = [ "imgtool" ]; }; python-packages = pkgs.python3.withPackages (p: with p; [ autopep8 pyelftools pyyaml pykwalify canopen packaging progress psutil anytree intelhex west imgtool cryptography intelhex click cbor2 # For mcuboot CI toml # For twister tabulate ply # For TFM pyasn1 graphviz jinja2 requests beautifulsoup4 # These are here because pip stupidly keeps trying to install # these in /nix/store. wcwidth sortedcontainers ]); # Build the Zephyr SDK as a nix package. new-zephyr-sdk-pkg = { stdenv , fetchurl , which , python38 , wget , file , cmake , libusb , autoPatchelfHook }: let version = "0.15.0"; arch = "arm"; sdk = fetchurl { url = "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${version}/zephyr-sdk-${version}_linux-x86_64_minimal.tar.gz"; hash = "sha256-dn+7HVBtvDs2EyXSLMb12Q+Q26+x6HYyPP69QdLKka8="; }; armToolchain = fetchurl { url = "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${version}/toolchain_linux-x86_64_arm-zephyr-eabi.tar.gz"; hash = "sha256-B7YIZEyuqE+XNI7IWnN6WiC1k9UdFEt4YN4Yr7Vn3Po="; }; in stdenv.mkDerivation { name = "zephyr-sdk"; inherit version; srcs = [ sdk armToolchain ]; srcRoot = "."; nativeBuildInputs = [ which wget file python38 autoPatchelfHook cmake libusb ]; phases = [ "installPhase" "fixupPhase" ]; installPhase = '' runHook preInstall echo out=$out mkdir -p $out set $srcs tar -xf $1 -C $out --strip-components=1 tar -xf $2 -C $out (cd $out; bash ./setup.sh -h) rm $out/zephyr-sdk-x86_64-hosttools-standalone-0.9.sh runHook postInstall ''; }; zephyr-sdk = pkgs.callPackage new-zephyr-sdk-pkg { }; packages = with pkgs; [ # Tools for building the languages we are using llvmPackages_16.clang-unwrapped # Newer than base clang gnat zig zls rustup glibc_multi # Dependencies of the Zephyr build system. (python-packages) cmake ninja gperf python3 ccache dtc gmp.dev zephyr-sdk ]; in pkgs.mkShell { nativeBuildInputs = packages; # For Zephyr work, we need to initialize some environment variables, # and then invoke the zephyr setup script. shellHook = '' export ZEPHYR_SDK_INSTALL_DIR=${zephyr-sdk} export PATH=$PATH:${zephyr-sdk}/arm-zephyr-eabi/bin export VIA_WORKSPACE_PATH="$(realpath ./workspace/)" source ./workspace/zephyr/zephyr-env.sh ''; }

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

  • sdk-ng

    Zephyr SDK (Toolchains, Development Tools)

    # Basic configuration for Zephyr development. { pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/refs/tags/23.05.tar.gz") { } }: let pp = pkgs.python3.pkgs; imgtool = pp.buildPythonPackage rec { version = "1.10.0"; pname = "imgtool"; src = pp.fetchPypi { inherit pname version; sha256 = "sha256-A7NOdZNKw9lufEK2vK8Rzq9PRT98bybBfXJr0YMQS0A="; }; propagatedBuildInputs = with pp; [ cbor2 click intelhex cryptography ]; doCheck = false; pythonImportsCheck = [ "imgtool" ]; }; python-packages = pkgs.python3.withPackages (p: with p; [ autopep8 pyelftools pyyaml pykwalify canopen packaging progress psutil anytree intelhex west imgtool cryptography intelhex click cbor2 # For mcuboot CI toml # For twister tabulate ply # For TFM pyasn1 graphviz jinja2 requests beautifulsoup4 # These are here because pip stupidly keeps trying to install # these in /nix/store. wcwidth sortedcontainers ]); # Build the Zephyr SDK as a nix package. new-zephyr-sdk-pkg = { stdenv , fetchurl , which , python38 , wget , file , cmake , libusb , autoPatchelfHook }: let version = "0.15.0"; arch = "arm"; sdk = fetchurl { url = "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${version}/zephyr-sdk-${version}_linux-x86_64_minimal.tar.gz"; hash = "sha256-dn+7HVBtvDs2EyXSLMb12Q+Q26+x6HYyPP69QdLKka8="; }; armToolchain = fetchurl { url = "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${version}/toolchain_linux-x86_64_arm-zephyr-eabi.tar.gz"; hash = "sha256-B7YIZEyuqE+XNI7IWnN6WiC1k9UdFEt4YN4Yr7Vn3Po="; }; in stdenv.mkDerivation { name = "zephyr-sdk"; inherit version; srcs = [ sdk armToolchain ]; srcRoot = "."; nativeBuildInputs = [ which wget file python38 autoPatchelfHook cmake libusb ]; phases = [ "installPhase" "fixupPhase" ]; installPhase = '' runHook preInstall echo out=$out mkdir -p $out set $srcs tar -xf $1 -C $out --strip-components=1 tar -xf $2 -C $out (cd $out; bash ./setup.sh -h) rm $out/zephyr-sdk-x86_64-hosttools-standalone-0.9.sh runHook postInstall ''; }; zephyr-sdk = pkgs.callPackage new-zephyr-sdk-pkg { }; packages = with pkgs; [ # Tools for building the languages we are using llvmPackages_16.clang-unwrapped # Newer than base clang gnat zig zls rustup glibc_multi # Dependencies of the Zephyr build system. (python-packages) cmake ninja gperf python3 ccache dtc gmp.dev zephyr-sdk ]; in pkgs.mkShell { nativeBuildInputs = packages; # For Zephyr work, we need to initialize some environment variables, # and then invoke the zephyr setup script. shellHook = '' export ZEPHYR_SDK_INSTALL_DIR=${zephyr-sdk} export PATH=$PATH:${zephyr-sdk}/arm-zephyr-eabi/bin export VIA_WORKSPACE_PATH="$(realpath ./workspace/)" source ./workspace/zephyr/zephyr-env.sh ''; }

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts