Nix ohne NixOS:

nix-shell


piegames

📧 · Mastodon Logo · Matrix chat logo
# Übersicht 1. Installation 2. Nix shell ad-hoc 3. Shells für Projekte 4. Shells mit Libraries 5. Cross-Compiling 6. Nixpkgs pinnen 7. Direnv-Integration 8. Fazit

Installation

# Shell mit Libraries ```nix [|13-15|6-7,16|] let pkgs = import <nixpkgs> {}; myPackages = [ opencv libhandy # 👇❸ llvmPackages.libclang ]; in pkgs.mkShell { buildInputs = myPackages; shellHook = '' export LD_LIBRARY_PATH=\ "${lib.makeLibraryPath myPackages}:''${LD_LIBRARY_PATH}" # 👆❶ 👆❷ export LIBCLANG_PATH="${llvmPackages.libclang}/lib" ''; } ``` Note: 0. buildInputs extrahieren 1. LD_LIBRARY_PATH überschreiben (anfügen): makeLibraryPath 2. Nix quoting Syntax (auch: optional) 3. Bonusbeispiel: libclang
# Python-Libraries ```nix [|3-9|12-15|] let pkgs = import <nixpkgs> {}; # 👇❶ myPythonPackages = pyPkgs: [ # 👇❷ pyPkgs.pandas pyPkgs.pillow pyPkgs.requests ]; in pkgs.mkShell { buildInputs = [ # 👇❸ (pkgs.python38.withPackages myPythonPackages) ]; } ``` Note: - Packageset mit Python-Paketen (lambda) - python.withPackages - 38 ist optional
# Cross-GCC ```nix let pkgs = import <nixpkgs> {}; in pkgs.mkShell { buildInputs = [ # ❶ pkgs.stdenv.cc # x86_64-unknown-linux-gnu # armv7l-unknown-linux-gnueabihf, alternatively: raspberryPi => armv6l-unknown-linux-gnueabihf pkgs.pkgsCross.armv7l-hf-multiplatform.stdenv.cc pkgs.pkgsCross.arm-embedded.stdenv.cc # arm-none-eabi pkgs.pkgsCross.avr.stdenv.cc # arduino pkgs.arduino # ❷ pkgs.pkgsCross.raspberryPi.alsaLib pkgs.pkgsCross.raspberryPi.dbus ]; … } ``` Note: 1. Verschiedene CCs installieren (Pi, Cortex-M0, Arduino) 2. Libraries installieren - shellHook nicht vergessen (für Libs und CC) - Ich setze den CC in der Makefile - Evt. separate shell.nix nötig (z.B. bei Libraries)
# Bonus: Rust ♥ ```nix let # 👇❶ moz_overlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz); pkgs = import <nixpkgs> { overlays = [ moz_overlay ]; }; # 👇❹ myRust = (pkgs.latest.rustChannels.nightly.rust.override { targets = [ # ❷ Cross-compile for a Pi with NixOS "armv7-unknown-linux-gnueabihf" # ❸ Cross-compile for a Pi with Raspbian "armv7-unknown-linux-musleabihf" ]; extensions = [ "rust-src" ]; # 👈❺ }) in pkgs.mkShell { buildInputs = [ myRust ]; } ``` Note: 1. Overlay anwenden 2. Targets 4. Toolchain 5. Für Quellcode & Docs