Refactor & add sdkFull
This commit is contained in:
parent
c2a268a4a0
commit
509e3da4d9
36
README.md
36
README.md
|
@ -4,8 +4,34 @@ Develop Zephyr projects using Nix
|
|||
|
||||
## Features
|
||||
|
||||
- SDK packaging
|
||||
- Host tools packaging
|
||||
* SDK packaging
|
||||
* `sdk`
|
||||
|
||||
The minimal SDK.
|
||||
Can be overriden with additional targets.
|
||||
|
||||
``` nix
|
||||
sdk.override {
|
||||
targets = [
|
||||
"arm-zephyr-eabi"
|
||||
];
|
||||
}
|
||||
```
|
||||
|
||||
* `sdkFull`
|
||||
|
||||
SDK with all targets enabled.
|
||||
|
||||
* Host tools packaging
|
||||
|
||||
* `hosttools`
|
||||
|
||||
Binary `hosttools` from the Zephyr SDK.
|
||||
Because of libc incompatibilities not all binaries in this derivation actually works.
|
||||
|
||||
* `hosttools-nix`
|
||||
|
||||
A re-packaging of the Zephyr SDK hosttools using nixpkgs packages.
|
||||
|
||||
## Basic usage
|
||||
|
||||
|
@ -29,11 +55,11 @@ mkShell {
|
|||
ninja
|
||||
];
|
||||
|
||||
env.ZEPHYR_SDK_INSTALL_DIR = zephyr.sdk.overrideAttrs(old: {
|
||||
targets = old.targets ++ [
|
||||
env.ZEPHYR_SDK_INSTALL_DIR = zephyr.sdk.override {
|
||||
targets = [
|
||||
"arm-zephyr-eabi"
|
||||
];
|
||||
});
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
|
|
175
default.nix
175
default.nix
|
@ -1,28 +1,21 @@
|
|||
{ callPackage
|
||||
, stdenv
|
||||
, zephyr-src
|
||||
, pyproject-nix
|
||||
, lib
|
||||
, fetchurl
|
||||
, which
|
||||
, autoPatchelfHook
|
||||
, cmake
|
||||
, python38
|
||||
, pkgs
|
||||
}:
|
||||
|
||||
let
|
||||
sdk = lib.importJSON ./sdk.json;
|
||||
inherit (sdk) version;
|
||||
sdk' = lib.importJSON ./sdk.json;
|
||||
inherit (sdk') version;
|
||||
|
||||
python3 = python38;
|
||||
|
||||
platform =
|
||||
getPlatform = stdenv:
|
||||
if stdenv.isLinux then "linux"
|
||||
else if stdenv.isDarwin then "macos"
|
||||
else throw "Unsupported platform";
|
||||
|
||||
arch =
|
||||
getArch = stdenv:
|
||||
if stdenv.isLinux then stdenv.hostPlatform.linuxArch
|
||||
else if stdenv.isDarwin then stdenv.hostPlatform.darwinArch
|
||||
else throw "Unsupported arch";
|
||||
|
@ -31,11 +24,15 @@ let
|
|||
|
||||
fetchSDKFile = file: fetchurl {
|
||||
url = "${baseURL}/${file}";
|
||||
sha256 = sdk.files.${file};
|
||||
sha256 = sdk'.files.${file};
|
||||
};
|
||||
|
||||
sdkArgs = {
|
||||
python3 = python38;
|
||||
};
|
||||
|
||||
in
|
||||
{
|
||||
rec {
|
||||
# Zephyr/west Python environment.
|
||||
pythonEnv = callPackage ./python.nix {
|
||||
inherit zephyr-src;
|
||||
|
@ -43,80 +40,126 @@ in
|
|||
};
|
||||
|
||||
# Pre-package Zephyr SDK.
|
||||
sdk = stdenv.mkDerivation (finalAttrs: {
|
||||
pname = "zephyr-sdk";
|
||||
inherit version;
|
||||
sdk = callPackage
|
||||
({ stdenv
|
||||
, which
|
||||
, cmake
|
||||
, autoPatchelfHook
|
||||
, python3
|
||||
, targets ? [ ]
|
||||
}:
|
||||
let
|
||||
platform = getPlatform stdenv;
|
||||
arch = getArch stdenv;
|
||||
in
|
||||
stdenv.mkDerivation {
|
||||
pname = "zephyr-sdk";
|
||||
inherit version;
|
||||
|
||||
srcs = [
|
||||
(fetchSDKFile "zephyr-sdk-${version}_${platform}-${arch}_minimal.tar.xz")
|
||||
] ++ map fetchSDKFile (map (target: "toolchain_${platform}-${arch}_${target}.tar.xz") finalAttrs.targets);
|
||||
srcs = [
|
||||
(fetchSDKFile "zephyr-sdk-${version}_${platform}-${arch}_minimal.tar.xz")
|
||||
] ++ map fetchSDKFile (map (target: "toolchain_${platform}-${arch}_${target}.tar.xz") targets);
|
||||
|
||||
targets = [ ]; # Zephyr targets
|
||||
passthru = {
|
||||
inherit platform arch targets;
|
||||
};
|
||||
|
||||
nativeBuildInputs = [ which cmake autoPatchelfHook ];
|
||||
nativeBuildInputs = [ which cmake autoPatchelfHook ];
|
||||
|
||||
buildInputs = [ stdenv.cc.cc python38 ];
|
||||
buildInputs = [ stdenv.cc.cc python3 ];
|
||||
|
||||
dontBuild = true;
|
||||
dontUseCmakeConfigure = true;
|
||||
dontBuild = true;
|
||||
dontUseCmakeConfigure = true;
|
||||
|
||||
sourceRoot = ".";
|
||||
sourceRoot = ".";
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
|
||||
rm zephyr-sdk-$version/zephyr-sdk-${arch}-hosttools-standalone-*.sh
|
||||
rm zephyr-sdk-$version/setup.sh;
|
||||
rm zephyr-sdk-$version/zephyr-sdk-${arch}-hosttools-standalone-*.sh
|
||||
rm zephyr-sdk-$version/setup.sh;
|
||||
|
||||
mv zephyr-sdk-$version $out
|
||||
mv $(ls | grep -v env-vars) $out/
|
||||
mv zephyr-sdk-$version $out
|
||||
mv $(ls | grep -v env-vars) $out/
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
});
|
||||
runHook postInstall
|
||||
'';
|
||||
})
|
||||
sdkArgs;
|
||||
|
||||
# # SDK with all targets selected
|
||||
sdkFull =
|
||||
let
|
||||
inherit (sdk.passthru) platform arch;
|
||||
mToolchain = builtins.match "toolchain_${platform}-${arch}_(.+)\.tar\.xz";
|
||||
allTargets = map (x: builtins.head (mToolchain x)) (builtins.filter (f: mToolchain f != null) (lib.attrNames sdk'.files));
|
||||
in
|
||||
sdk.override {
|
||||
targets = allTargets;
|
||||
};
|
||||
|
||||
# Binary host tools provided by the Zephyr project.
|
||||
hosttools = stdenv.mkDerivation {
|
||||
pname = "zephyr-sdk-hosttools";
|
||||
inherit version;
|
||||
hosttools = callPackage
|
||||
({ stdenv
|
||||
, which
|
||||
, autoPatchelfHook
|
||||
, python3
|
||||
}:
|
||||
let
|
||||
platform = getPlatform stdenv;
|
||||
arch = getArch stdenv;
|
||||
in
|
||||
stdenv.mkDerivation {
|
||||
pname = "zephyr-sdk-hosttools";
|
||||
inherit version;
|
||||
|
||||
src = fetchSDKFile "hosttools_${platform}-${arch}.tar.xz";
|
||||
src = fetchSDKFile "hosttools_${platform}-${arch}.tar.xz";
|
||||
|
||||
nativeBuildInputs = [ which autoPatchelfHook ];
|
||||
nativeBuildInputs = [ which autoPatchelfHook ];
|
||||
|
||||
buildInputs = [ python3 ];
|
||||
buildInputs = [ python3 ];
|
||||
|
||||
dontBuild = true;
|
||||
dontBuild = true;
|
||||
|
||||
sourceRoot = ".";
|
||||
sourceRoot = ".";
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
mkdir -p $out/usr/share/zephyr/hosttools
|
||||
./zephyr-sdk-${arch}-hosttools-standalone-*.sh -d $out/usr/share/zephyr/hosttools
|
||||
ln -s $out/usr/share/zephyr/hosttools/sysroots/${arch}-pokysdk-${platform}/usr/bin $out/bin
|
||||
runHook postInstall
|
||||
'';
|
||||
};
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
mkdir -p $out/usr/share/zephyr/hosttools
|
||||
./zephyr-sdk-${arch}-hosttools-standalone-*.sh -d $out/usr/share/zephyr/hosttools
|
||||
ln -s $out/usr/share/zephyr/hosttools/sysroots/${arch}-pokysdk-${platform}/usr/bin $out/bin
|
||||
runHook postInstall
|
||||
'';
|
||||
})
|
||||
sdkArgs;
|
||||
|
||||
# A variant of hosttools, but all tools are taken from nixpkgs.
|
||||
hosttools-nix = stdenv.mkDerivation {
|
||||
name = "zephyr-sdk-hosttools-nix";
|
||||
hosttools-nix = callPackage
|
||||
({ stdenv
|
||||
, bossa
|
||||
, dtc
|
||||
, nettle
|
||||
, openocd
|
||||
, qemu_full
|
||||
, shared-mime-info
|
||||
}: stdenv.mkDerivation {
|
||||
name = "zephyr-sdk-hosttools-nix";
|
||||
|
||||
dontUnpack = true;
|
||||
dontBuild = true;
|
||||
dontUnpack = true;
|
||||
dontBuild = true;
|
||||
|
||||
propagatedBuildInputs = with pkgs; [
|
||||
bossa
|
||||
dtc
|
||||
nettle
|
||||
openocd
|
||||
qemu_full
|
||||
shared-mime-info
|
||||
];
|
||||
propagatedBuildInputs = [
|
||||
bossa
|
||||
dtc
|
||||
nettle
|
||||
openocd
|
||||
qemu_full
|
||||
shared-mime-info
|
||||
];
|
||||
|
||||
installPhase = ''
|
||||
mkdir $out
|
||||
'';
|
||||
};
|
||||
installPhase = ''
|
||||
mkdir $out
|
||||
'';
|
||||
})
|
||||
{ };
|
||||
}
|
||||
|
|
21
flake.nix
21
flake.nix
|
@ -18,16 +18,17 @@
|
|||
{
|
||||
packages =
|
||||
forAllSystems
|
||||
(
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
in
|
||||
pkgs.callPackages ./. {
|
||||
zephyr-src = zephyr;
|
||||
inherit pyproject-nix;
|
||||
}
|
||||
);
|
||||
(
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
in
|
||||
builtins.removeAttrs
|
||||
(pkgs.callPackage ./. {
|
||||
zephyr-src = zephyr;
|
||||
inherit pyproject-nix;
|
||||
}) [ "override" "overrideDerivation" ]
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue