|
| 1 | +# Licensed under the Apache License, Version 2.0 or the MIT License. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 OR MIT |
| 3 | +# Copyright Tock Contributors 2022. |
| 4 | + |
| 5 | +# Shell expression for the Nix package manager |
| 6 | +# |
| 7 | +# This nix expression creates an environment with necessary packages installed: |
| 8 | +# |
| 9 | +# * `tockloader` |
| 10 | +# * rust |
| 11 | +# |
| 12 | +# To use: |
| 13 | +# |
| 14 | +# $ nix-shell |
| 15 | +# |
| 16 | + |
| 17 | +{ pkgs ? import <nixpkgs> { }, withUnfreePkgs ? false }: |
| 18 | + |
| 19 | +with builtins; |
| 20 | +let |
| 21 | + inherit (pkgs) stdenv lib; |
| 22 | + |
| 23 | + # Tockloader v1.11.0 |
| 24 | + tockloader = import (pkgs.fetchFromGitHub { |
| 25 | + owner = "tock"; |
| 26 | + repo = "tockloader"; |
| 27 | + rev = "v1.11.0"; |
| 28 | + sha256 = "sha256-bPEfpfOZOjOiazqRgn1cnqe4ohLPvocuENKoZx/Qw80="; |
| 29 | + }) { inherit pkgs withUnfreePkgs; }; |
| 30 | + |
| 31 | + # Rust toolchain overlay |
| 32 | + rust_overlay = import "${pkgs.fetchFromGitHub { |
| 33 | + owner = "nix-community"; |
| 34 | + repo = "fenix"; |
| 35 | + # Revision hash must correspond with the same date as the nightly version. |
| 36 | + rev = "ffa0a8815be591767f82d42c63d88bfa4026a967"; |
| 37 | + sha256 = "sha256-JOrXleSdEKuymCyxg7P4GTTATDhBdfeyWcd1qQQlIYw="; |
| 38 | + }}/overlay.nix"; |
| 39 | + |
| 40 | + nixpkgs = import <nixpkgs> { overlays = [ rust_overlay ]; }; |
| 41 | + stable = (lib.importTOML ./rust-toolchain.toml).toolchain; |
| 42 | + nightly = (lib.importTOML ./nightly/rust-toolchain.toml).toolchain; |
| 43 | + |
| 44 | + # Use nightly development toolchain because Miri is not supported |
| 45 | + # by the MSRV (Minimum Supported Rust Version) toolchain. |
| 46 | + nightlyToolchain = nixpkgs.fenix.fromToolchainName { |
| 47 | + name = nightly.channel; |
| 48 | + sha256 = "sha256-R/ONZzJaWQr0pl5RoXFIbnxIE3m6oJWy/rr2W0wXQHQ="; |
| 49 | + }; |
| 50 | + |
| 51 | + # Combine the components from the stable and nightly toolchains. |
| 52 | + combinedToolchain = |
| 53 | + nightlyToolchain.withComponents ( |
| 54 | + nightly.components ++ |
| 55 | + stable.components ++ |
| 56 | + [ "cargo" ] |
| 57 | + ); |
| 58 | + # Add the cross-compile target platforms to the environment. |
| 59 | + rustBuild = |
| 60 | + nixpkgs.fenix.combine ( |
| 61 | + foldl' |
| 62 | + (acc: item: acc ++ [ nixpkgs.fenix.targets.${item}.latest.rust-std ]) |
| 63 | + [ combinedToolchain ] |
| 64 | + stable.targets |
| 65 | + ); |
| 66 | + |
| 67 | +in |
| 68 | + pkgs.mkShell { |
| 69 | + name = "tock-dev"; |
| 70 | + |
| 71 | + buildInputs = with pkgs; [ |
| 72 | + # --- Toolchains --- |
| 73 | + rustBuild |
| 74 | + openocd |
| 75 | + |
| 76 | + # --- Convenience and support packages --- |
| 77 | + python3Full |
| 78 | + tockloader |
| 79 | + |
| 80 | + # Required for tools/print_tock_memory_usage.py |
| 81 | + python3Packages.cxxfilt |
| 82 | + |
| 83 | + |
| 84 | + # --- CI support packages --- |
| 85 | + qemu |
| 86 | + |
| 87 | + # --- Flashing tools --- |
| 88 | + # If your board requires J-Link to flash and you are on NixOS, |
| 89 | + # add these lines to your system wide configuration. |
| 90 | + |
| 91 | + # Enable udev rules from segger-jlink package |
| 92 | + # services.udev.packages = [ |
| 93 | + # pkgs.segger-jlink |
| 94 | + # ]; |
| 95 | + |
| 96 | + # Add "segger-jlink" to your system packages and accept the EULA: |
| 97 | + # nixpkgs.config.segger-jlink.acceptLicense = true; |
| 98 | + ]; |
| 99 | + |
| 100 | + LD_LIBRARY_PATH = "${stdenv.cc.cc.lib}/lib64:$LD_LIBRARY_PATH"; |
| 101 | + |
| 102 | + # Instruct the Tock gnumake-based build system to not check for rustup and |
| 103 | + # assume all requirend tools are installed and available in the $PATH |
| 104 | + NO_RUSTUP = "1"; |
| 105 | + |
| 106 | + # The defaults "objcopy" and "objdump" are wrong (stem from the standard |
| 107 | + # environment for x86), use "llvm-obj{copy,dump}" as defined in the makefile |
| 108 | + shellHook = '' |
| 109 | + unset OBJCOPY |
| 110 | + unset OBJDUMP |
| 111 | + ''; |
| 112 | + } |
0 commit comments