From 0424efd304e56e46feb1be8c838d137e568dddfb Mon Sep 17 00:00:00 2001 From: Francesco Gazzetta Date: Wed, 29 Mar 2023 18:13:03 +0200 Subject: [PATCH] Add nix development shell Signed-off-by: Francesco Gazzetta --- docs/install.rst | 29 +++++++++++++++++++++++++++++ tools/nix/flake.nix | 20 ++++++++++++++++++++ tools/nix/shell.nix | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 tools/nix/flake.nix create mode 100644 tools/nix/shell.nix diff --git a/docs/install.rst b/docs/install.rst index 7cb4f95..08d36e2 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -77,6 +77,35 @@ All ``make`` commands should be usable from this shell, including ``make sim`` and ``make check``. Some commands that interact with bluetooth such as ``wasptool`` may not work, for now. +Install prerequisites via Nix +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. note:: + + This setup method does not use the GCC version wasp-os is tested with, + but the gcc-arm-embedded package available from nixpkgs. + Though this usually works fine, if you encounter any problems please try the + manual installation above and report the issue in the issue tracker. + +To build wasp-os with `Nix `_, ensure it is installed +then open a terminal and run the following command in the wasp-os repository: + +.. code-block:: sh + + nix-shell tools/nix/shell.nix + +Or if you are using the experimental flake commands: + +.. code-block:: sh + + nix develop ./tools/nix + +You will be dropped in a shell where all required dependencies are available. +All ``make`` commands should be usable from this shell. + +Build +~~~~~ + We can compile the modules required with the following commands: .. code-block:: sh diff --git a/tools/nix/flake.nix b/tools/nix/flake.nix new file mode 100644 index 0000000..ae05556 --- /dev/null +++ b/tools/nix/flake.nix @@ -0,0 +1,20 @@ +# NOTE: The officially tested toolchain is the one mentioned at +# https://wasp-os.readthedocs.io/en/latest/install.html#install-prerequisites +# So let's not add a flake.lock unless we test (and maintain) this thoroughly too. +{ + description = "A MicroPython based development environment for smart watches"; + outputs = { self, nixpkgs }: + let + supportedSystems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + forAllSupportedSystems = nixpkgs.lib.genAttrs supportedSystems; + in { + devShells = forAllSupportedSystems (system: { + default = import ./shell.nix { pkgs = nixpkgs.legacyPackages."${system}"; }; + }); + }; +} diff --git a/tools/nix/shell.nix b/tools/nix/shell.nix new file mode 100644 index 0000000..f940442 --- /dev/null +++ b/tools/nix/shell.nix @@ -0,0 +1,36 @@ +{ pkgs ? import {} }: + +let + # wasptool and ota-dfu only work on linux, and their dependencies prevent the + # shell to evaluate on darwin + ifLinux = pkgs.lib.optionals pkgs.stdenv.isLinux; + +in pkgs.mkShell { + nativeBuildInputs = [ + (pkgs.python3.withPackages (pp: with pp; [ + cbor + click + cryptography + dbus-python + numpy + pexpect + pillow + pygobject3 + pysdl2 + pyserial + tomli + + pytest + + # Docs + recommonmark + sphinx + ] ++ ifLinux [ + bluepy + ])) + pkgs.gcc-arm-embedded + pkgs.graphviz + ] ++ ifLinux [ + pkgs.bluez + ]; +}