first commit
All checks were successful
build / check (push) Successful in 27s
build / build (push) Successful in 2m10s

This commit is contained in:
Sebastian Wendel 2023-09-11 17:33:19 +02:00
commit 92a1367216
15 changed files with 604 additions and 0 deletions

10
.editorconfig Normal file
View file

@ -0,0 +1,10 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
[*.nix]
indent_size = 2

4
.envrc Normal file
View file

@ -0,0 +1,4 @@
use flake
watch_file flake.*
watch_file **/*.nix

View file

@ -0,0 +1,14 @@
---
name: Install Nix
description: Install Nix package manager using the Determinante Systems installer
runs:
using: composite
steps:
- uses: https://github.com/DeterminateSystems/nix-installer-action@v4
with:
init: none
planner: linux
github-token: ${{ secrets.GH_TOKEN }}
extra-conf: |
accept-flake-config = true
experimental-features = nix-command flakes recursive-nix

View file

@ -0,0 +1,30 @@
---
name: build
on: push
jobs:
check:
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Nix
uses: ./.gitea/actions/setup-nix
- name: Nix check
run: nix flake check
build:
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Nix
uses: ./.gitea/actions/setup-nix
- name: Nix build
run: nix build .#

18
.gitignore vendored Normal file
View file

@ -0,0 +1,18 @@
# General
*~
*.dll
*.log
*.so
*.swp
*.000
*.bak
*.bck
*.tmp
# macOS
.DS_Store
# Nix
.direnv
.pre-commit-config.yaml
result

17
.reuse/dep5 Normal file
View file

@ -0,0 +1,17 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: nix-zephyr-sdk
Upstream-Contact: Sebastian Wendel <nix-zephyr-sdk@srx.dev>
Source: https://code.srx.dev/srx/nix-zephyr-sdk
Files:
.gitignore
.editorconfig
.envrc
.gitea
packages/*
shells/*
*.lock
*.nix
*.md
Copyright: 2023 Sebastian Wendel <nix-zephyr-sdk@srx.dev>
License: MIT

9
LICENSES/MIT.txt Normal file
View file

@ -0,0 +1,9 @@
MIT License
Copyright (c) 2023 Sebastian Wendel
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

67
README.md Normal file
View file

@ -0,0 +1,67 @@
# Nix Zephyr SDK
[Nix Flake](https://zero-to-nix.com/concepts/flakes) Collection for [Zephyr SDK](https://docs.zephyrproject.org/latest/develop/toolchains/zephyr_sdk.html) Toolchain
## Description
This repository provides a [Nix Flake](https://zero-to-nix.com/concepts/flakes) collection for the Zephyr SDK toolchain. The [Zephyr SDK](https://docs.zephyrproject.org/latest/develop/toolchains/zephyr_sdk.html) is a collection of tools and libraries for developing applications for the [Zephyr RTOS](https://zephyrproject.org/). This [Nix Flake](https://zero-to-nix.com/concepts/flakes) makes it easy to install and manage the Zephyr SDK toolchain in a reproducible manner across different systems.
## Features
- Easy installation of Zephyr SDK toolchain using Nix.
- Reproducible builds to ensure consistent behavior across different systems.
- Flexible configurations to suit various development environments.
- Ability to pin specific versions of Zephyr SDK.
- Support for multiple platforms including Linux and macOS.
## Prerequisites
- [Nix package manager](https://nixos.org/download.html)
- [Basic knowledge of Zephyr SDK and RTOS development](https://docs.zephyrproject.org/latest/index.html)
## Installation
Firstly, make sure you have [Nix with flakes support enabled](https://nixos.wiki/wiki/Flakes#Enable_flakes). Then you can add this flake as an input to your own flake, or install the tools globally.
### Activating the Flake
To use this flake in your own project:
```nix
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
zephyr-sdk.url = "git+https://code.srx.dev/srx/nix-zephyr-sdk";
};
outputs = { self, zephyr-sdk, nixpkgs }: {
devShells.default = zephyr-sdk.devShells.zephyr;
};
}
```
### Direct Installation
To install the Zephyr SDK globally:
```sh
nix profile install git+https://code.srx.dev/srx/nix-zephyr-sdk
```
## Usage
Once installed, the Zephyr SDK tools should be available in your shell. For example, to build a Zephyr application:
```sh
west build -b <BOARD> <SOURCE_DIRECTORY>
```
Please consult the [Zephyr documentation](https://docs.zephyrproject.org/latest/index.html) for full usage instructions.
## Contributing
Contributions are welcome! Please submit Pull Requests or Issues to help improve the project.
## License
This project follows the [REUSE Specification](https://reuse.software/spec/) and is licensed under the [MIT License - see the LICENSE file](./LICENSES/MIT.txt) for details.

14
default.nix Normal file
View file

@ -0,0 +1,14 @@
(import
(
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{
src = ./.;
})
.defaultNix

158
flake.lock Normal file
View file

@ -0,0 +1,158 @@
{
"nodes": {
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1673956053,
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-compat_2": {
"flake": false,
"locked": {
"lastModified": 1673956053,
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1692799911,
"narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1660459072,
"narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=",
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "a20de23b925fd8264fd7fad6454652e142fd7f73",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1694183432,
"narHash": "sha256-YyPGNapgZNNj51ylQMw9lAgvxtM2ai1HZVUu3GS8Fng=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "db9208ab987cdeeedf78ad9b4cf3c55f5ebd269b",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1685801374,
"narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "c37ca420157f4abc31e26f436c1145f8951ff373",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-23.05",
"repo": "nixpkgs",
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat_2",
"flake-utils": [
"flake-utils"
],
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1694364351,
"narHash": "sha256-oadhSCqopYXxURwIA6/Anpe5IAG11q2LhvTJNP5zE6o=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "4f883a76282bc28eb952570afc3d8a1bf6f481d7",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"pre-commit-hooks": "pre-commit-hooks"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

61
flake.nix Normal file
View file

@ -0,0 +1,61 @@
{
description = "Nix Flake Collection for Zephyr SDK Toolchain";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
};
outputs = {
self,
nixpkgs,
flake-utils,
pre-commit-hooks,
...
} @ inputs:
flake-utils.lib.eachSystem [
"x86_64-linux"
"x86_64-darwin"
"aarch64-linux"
"aarch64-darwin"
] (system: {
pkgs = import nixpkgs {
inherit system;
config = {allowUnfree = true;};
};
packages = {
zephyr-sdk = self.pkgs.${system}.callPackage ./packages/zephyr-sdk inputs;
default = self.packages.${system}.zephyr-sdk;
};
devShells = {
zephyr = import ./shells/zephyr.nix inputs system;
nix = import ./shells/nix.nix inputs system;
default = self.devShells.${system}.nix;
};
checks = {
pre-commit-check =
pre-commit-hooks.lib.${system}.run
{
src = self.pkgs.${system}.lib.cleanSource ./.;
hooks = {
editorconfig-checker.enable = true;
statix.enable = true;
deadnix.enable = true;
alejandra.enable = true;
};
};
};
});
}

View file

@ -0,0 +1,136 @@
{
autoPatchelfHook,
gmp,
gnutls,
hidapi,
libftdi1,
libusb,
libxml2,
pixman,
python38,
readline,
cmake,
dtc,
fetchurl,
glib,
glibcLocales,
lib,
libfaketime,
nettle,
python3,
stdenv,
unzip,
which,
xz,
...
}: let
hosttools.version = "0.9";
in
stdenv.mkDerivation rec {
pname = "zephyr-sdk";
version = "0.16.1";
src = let
getHash = arch:
{
"linux-x86_64" = "sha256-UTONUapM6iUWZBzg2dwLUbdjd58A3EVkorwN1xPfIsc=";
"linux-aarch64" = "sha256-BiuytcR8pW3Sm3+S3X8Hpc4iulE3WdK2lgvGWFMesAw=";
"macos-x86_64" = "sha256-sEbHviuQ7qMPH9kHr+DwgCFnAw62NWCxKfJj2aV1Tdo=";
"macos-aarch64" = "sha256-Vf/Gtzdv21x7+20zyEYEnmwPitYmL4ZClPxC1AWbGiY=";
}
.${arch};
getArch =
{
"x86_64-linux" = "linux-x86_64";
"aarch64-linux" = "linux-aarch64";
"x86_64-darwin" = "macos-x86_64";
"aarch64-darwin" = "macos-aarch64";
}
.${stdenv.system}
or (throw "${pname}-${version}: ${stdenv.system} is unsupported.");
getUrl = arch: "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${version}/${pname}-${version}_${arch}.tar.xz";
in
fetchurl {
url = getUrl getArch;
sha256 = getHash getArch;
};
nativeBuildInputs = [
autoPatchelfHook
glib
glibcLocales
libfaketime
python3.pythonForBuild
unzip
which
xz
];
buildInputs = [
cmake
dtc
gmp
gnutls
hidapi
libftdi1
libusb
libxml2
nettle
pixman
python38
readline
];
postUnpack = ''
$sourceRoot/zephyr-sdk-$(uname -m)-hosttools-standalone-${hosttools.version}.sh \
-y -p -d $sourceRoot
rm -f $sourceRoot/{setup,zephyr-sdk-$(uname -m)-hosttools-standalone-*}.sh \
$sourceRoot/{version,environment-setup}-$(uname -m)-pokysdk-linux
'';
patchPhase = ''
patchShebangs .
substituteInPlace cmake/zephyr/host-tools.cmake \
--replace "/usr/share" "/share" \
--replace "/sysroots/\*-pokysdk-linux" ""
'';
dontConfigure = true;
dontBuild = true;
installPhase = ''
runHook preInstall
mkdir -p $out/{share,lib}
# remove deprecated symbolic links
find ./sysroots/$(uname -m)-pokysdk-linux/usr/bin -type l -exec unlink {} \;
# add zephyr-sdk standalone hosttools
mv ./sysroots/$(uname -m)-pokysdk-linux/usr/{bin,libexec,share} $out/
mv ./sysroots/$(uname -m)-pokysdk-linux/usr/synopsys/bin/qemu-system-* $out/bin/
mv ./sysroots/$(uname -m)-pokysdk-linux/usr/xilinx/bin/qemu-system-aarch64 \
$out/bin/qemu-system-xilinx-aarch64
mv ./sysroots/$(uname -m)-pokysdk-linux/usr/xilinx/bin/qemu-system-microblazeel \
$out/bin/qemu-system-xilinx-microblazeel
# add zephyr-sdk cmake modules
mv ./cmake $out/lib/cmake
# add zephyr-sdk cross compilers
mv ./*zephyr*/bin/* $out/bin/
runHook postInstall
'';
setupHook = ./setup-hook.sh;
meta = with lib; {
description = "Zephyr SDK (Toolchains, Development Tools)";
homepage = "https://github.com/zephyrproject-rtos/sdk-ng/";
license = licenses.asl20;
platforms = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
};
}

View file

@ -0,0 +1,12 @@
addZephyrSDKCEnvVars() {
cmakeFlagsArray+=(-DCMAKE_MODULE_PATH=@out@/lib/cmake)
cmakeFlagsArray+=(-DZEPHYR_TOOLCHAIN_VARIANT=zephyr)
cmakeFlagsArray+=(-DZEPHYR_SDK_INSTALL_DIR=@out@)
cmakeFlagsArray+=(-DHOST_TOOLS_HOME=@out@)
export ZEPHYR_TOOLCHAIN_VARIANT=zephyr
export ZEPHYR_SDK_INSTALL_DIR=@out@
export HOST_TOOLS_HOME=@out@
}
addEnvHooks "$hostOffset" addZephyrSDKCEnvVars

18
shells/nix.nix Normal file
View file

@ -0,0 +1,18 @@
{self, ...}: system:
with self.pkgs.${system};
mkShell {
name = "nix-dev";
buildInputs = [
alejandra
deadnix
git
nil
nixUnstable
pre-commit
reuse
statix
];
shellHook = ''
${self.checks.${system}.pre-commit-check.shellHook}
'';
}

36
shells/zephyr.nix Normal file
View file

@ -0,0 +1,36 @@
{self, ...}: system:
with self.pkgs.${system};
with self.packages.${system};
mkShell {
name = "zephyr-dev";
buildInputs = [
# C/CPP
bear
bison
ccache
clang
clang-tools
clangStdenv
cmake
cmake-format
cmake-language-server
dfu-util
flex
gdb
gnumake
gperf
gtest
libffi
libusb
ncurses
ninja
# # Zephyr
python310Packages.west
zephyr-sdk
# ESP
espup
esptool
];
}