Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nix develop support #1450

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/building-and-flashing/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ You'll need to use either the [Crazyflie VM](https://github.com/bitcraze/bitcraz
[the toolbelt](https://github.com/bitcraze/toolbelt) or
install some ARM toolchain.

There is also experimental support for [building with nix](./nix.md).
This allows to build the firmware in a reproducable way.

### Install a toolchain

#### Toolchain and compiler version policy
Expand Down
29 changes: 29 additions & 0 deletions docs/building-and-flashing/nix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: Building using nix
page_id: nix
---

The [Nix package manager](https://nixos.org) can be used to build the firmware in a reliable way without having to install all the dependencies on your system.
All that is needed is to have the nix package manager installed with [Flake support enabled](https://nixos.wiki/wiki/flakes).
The easiest if nix is not installed yet is to install it from [zero to Nix](https://zero-to-nix.com/start/install/).
Nix support in this project is currently experimental.

## Development shell

To get into a development shell where required tools for building the project are present:

``` bash
nix develop
```

## Building with Nix

The following command will produce a clean build for the Crazyflie 2. The command can be changed to build for other target:

``` bash
nix develop -i --command bash -c 'make mrproper && make cf2_defconfig && make -j`nproc`'
```

## Updating the flake

One great advantage of working with Nix is that the versions are locked in the `nix.lock` file. This means that build are reproducable. Running `nix flake update` can be used to update dependencies. The file `nix.lock` then need to be commited and pushed.
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
description = "Crazyflie firmware development environment";

inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
};

outputs = {
nixpkgs,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem
(
system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
formatter = pkgs.alejandra;

devShells.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
gcc
gnumake
gcc-arm-embedded
python3
git
];
};
}
);
}
2 changes: 1 addition & 1 deletion tools/kbuild/Makefile.kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ ifneq ($(KBUILD_OUTPUT),)
# check that the output directory actually exists
saved-output := $(KBUILD_OUTPUT)
KBUILD_OUTPUT := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) \
&& /bin/pwd)
&& pwd)
$(if $(KBUILD_OUTPUT),, \
$(error failed to create output directory "$(saved-output)"))

Expand Down
Loading