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
|
## Features
|
||||||
|
|
||||||
- SDK packaging
|
* SDK packaging
|
||||||
- Host tools 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
|
## Basic usage
|
||||||
|
|
||||||
|
@ -29,11 +55,11 @@ mkShell {
|
||||||
ninja
|
ninja
|
||||||
];
|
];
|
||||||
|
|
||||||
env.ZEPHYR_SDK_INSTALL_DIR = zephyr.sdk.overrideAttrs(old: {
|
env.ZEPHYR_SDK_INSTALL_DIR = zephyr.sdk.override {
|
||||||
targets = old.targets ++ [
|
targets = [
|
||||||
"arm-zephyr-eabi"
|
"arm-zephyr-eabi"
|
||||||
];
|
];
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
175
default.nix
175
default.nix
|
@ -1,28 +1,21 @@
|
||||||
{ callPackage
|
{ callPackage
|
||||||
, stdenv
|
|
||||||
, zephyr-src
|
, zephyr-src
|
||||||
, pyproject-nix
|
, pyproject-nix
|
||||||
, lib
|
, lib
|
||||||
, fetchurl
|
, fetchurl
|
||||||
, which
|
|
||||||
, autoPatchelfHook
|
|
||||||
, cmake
|
|
||||||
, python38
|
, python38
|
||||||
, pkgs
|
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
sdk = lib.importJSON ./sdk.json;
|
sdk' = lib.importJSON ./sdk.json;
|
||||||
inherit (sdk) version;
|
inherit (sdk') version;
|
||||||
|
|
||||||
python3 = python38;
|
getPlatform = stdenv:
|
||||||
|
|
||||||
platform =
|
|
||||||
if stdenv.isLinux then "linux"
|
if stdenv.isLinux then "linux"
|
||||||
else if stdenv.isDarwin then "macos"
|
else if stdenv.isDarwin then "macos"
|
||||||
else throw "Unsupported platform";
|
else throw "Unsupported platform";
|
||||||
|
|
||||||
arch =
|
getArch = stdenv:
|
||||||
if stdenv.isLinux then stdenv.hostPlatform.linuxArch
|
if stdenv.isLinux then stdenv.hostPlatform.linuxArch
|
||||||
else if stdenv.isDarwin then stdenv.hostPlatform.darwinArch
|
else if stdenv.isDarwin then stdenv.hostPlatform.darwinArch
|
||||||
else throw "Unsupported arch";
|
else throw "Unsupported arch";
|
||||||
|
@ -31,11 +24,15 @@ let
|
||||||
|
|
||||||
fetchSDKFile = file: fetchurl {
|
fetchSDKFile = file: fetchurl {
|
||||||
url = "${baseURL}/${file}";
|
url = "${baseURL}/${file}";
|
||||||
sha256 = sdk.files.${file};
|
sha256 = sdk'.files.${file};
|
||||||
|
};
|
||||||
|
|
||||||
|
sdkArgs = {
|
||||||
|
python3 = python38;
|
||||||
};
|
};
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
rec {
|
||||||
# Zephyr/west Python environment.
|
# Zephyr/west Python environment.
|
||||||
pythonEnv = callPackage ./python.nix {
|
pythonEnv = callPackage ./python.nix {
|
||||||
inherit zephyr-src;
|
inherit zephyr-src;
|
||||||
|
@ -43,80 +40,126 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
# Pre-package Zephyr SDK.
|
# Pre-package Zephyr SDK.
|
||||||
sdk = stdenv.mkDerivation (finalAttrs: {
|
sdk = callPackage
|
||||||
pname = "zephyr-sdk";
|
({ stdenv
|
||||||
inherit version;
|
, which
|
||||||
|
, cmake
|
||||||
|
, autoPatchelfHook
|
||||||
|
, python3
|
||||||
|
, targets ? [ ]
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
platform = getPlatform stdenv;
|
||||||
|
arch = getArch stdenv;
|
||||||
|
in
|
||||||
|
stdenv.mkDerivation {
|
||||||
|
pname = "zephyr-sdk";
|
||||||
|
inherit version;
|
||||||
|
|
||||||
srcs = [
|
srcs = [
|
||||||
(fetchSDKFile "zephyr-sdk-${version}_${platform}-${arch}_minimal.tar.xz")
|
(fetchSDKFile "zephyr-sdk-${version}_${platform}-${arch}_minimal.tar.xz")
|
||||||
] ++ map fetchSDKFile (map (target: "toolchain_${platform}-${arch}_${target}.tar.xz") finalAttrs.targets);
|
] ++ 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;
|
dontBuild = true;
|
||||||
dontUseCmakeConfigure = true;
|
dontUseCmakeConfigure = true;
|
||||||
|
|
||||||
sourceRoot = ".";
|
sourceRoot = ".";
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
runHook preInstall
|
runHook preInstall
|
||||||
|
|
||||||
rm zephyr-sdk-$version/zephyr-sdk-${arch}-hosttools-standalone-*.sh
|
rm zephyr-sdk-$version/zephyr-sdk-${arch}-hosttools-standalone-*.sh
|
||||||
rm zephyr-sdk-$version/setup.sh;
|
rm zephyr-sdk-$version/setup.sh;
|
||||||
|
|
||||||
mv zephyr-sdk-$version $out
|
mv zephyr-sdk-$version $out
|
||||||
mv $(ls | grep -v env-vars) $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.
|
# Binary host tools provided by the Zephyr project.
|
||||||
hosttools = stdenv.mkDerivation {
|
hosttools = callPackage
|
||||||
pname = "zephyr-sdk-hosttools";
|
({ stdenv
|
||||||
inherit version;
|
, 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 = ''
|
installPhase = ''
|
||||||
runHook preInstall
|
runHook preInstall
|
||||||
mkdir -p $out/usr/share/zephyr/hosttools
|
mkdir -p $out/usr/share/zephyr/hosttools
|
||||||
./zephyr-sdk-${arch}-hosttools-standalone-*.sh -d $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
|
ln -s $out/usr/share/zephyr/hosttools/sysroots/${arch}-pokysdk-${platform}/usr/bin $out/bin
|
||||||
runHook postInstall
|
runHook postInstall
|
||||||
'';
|
'';
|
||||||
};
|
})
|
||||||
|
sdkArgs;
|
||||||
|
|
||||||
# A variant of hosttools, but all tools are taken from nixpkgs.
|
# A variant of hosttools, but all tools are taken from nixpkgs.
|
||||||
hosttools-nix = stdenv.mkDerivation {
|
hosttools-nix = callPackage
|
||||||
name = "zephyr-sdk-hosttools-nix";
|
({ stdenv
|
||||||
|
, bossa
|
||||||
|
, dtc
|
||||||
|
, nettle
|
||||||
|
, openocd
|
||||||
|
, qemu_full
|
||||||
|
, shared-mime-info
|
||||||
|
}: stdenv.mkDerivation {
|
||||||
|
name = "zephyr-sdk-hosttools-nix";
|
||||||
|
|
||||||
dontUnpack = true;
|
dontUnpack = true;
|
||||||
dontBuild = true;
|
dontBuild = true;
|
||||||
|
|
||||||
propagatedBuildInputs = with pkgs; [
|
propagatedBuildInputs = [
|
||||||
bossa
|
bossa
|
||||||
dtc
|
dtc
|
||||||
nettle
|
nettle
|
||||||
openocd
|
openocd
|
||||||
qemu_full
|
qemu_full
|
||||||
shared-mime-info
|
shared-mime-info
|
||||||
];
|
];
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
mkdir $out
|
mkdir $out
|
||||||
'';
|
'';
|
||||||
};
|
})
|
||||||
|
{ };
|
||||||
}
|
}
|
||||||
|
|
21
flake.nix
21
flake.nix
|
@ -18,16 +18,17 @@
|
||||||
{
|
{
|
||||||
packages =
|
packages =
|
||||||
forAllSystems
|
forAllSystems
|
||||||
(
|
(
|
||||||
system:
|
system:
|
||||||
let
|
let
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
in
|
in
|
||||||
pkgs.callPackages ./. {
|
builtins.removeAttrs
|
||||||
zephyr-src = zephyr;
|
(pkgs.callPackage ./. {
|
||||||
inherit pyproject-nix;
|
zephyr-src = zephyr;
|
||||||
}
|
inherit pyproject-nix;
|
||||||
);
|
}) [ "override" "overrideDerivation" ]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue