Add zephyr host tools

This commit is contained in:
Artemis Tosini 2023-11-11 23:03:50 +00:00
commit bfd6338ec6
Signed by: artemist
GPG key ID: EE5227935FE3FF18
8 changed files with 190 additions and 0 deletions

13
.editorconfig Normal file
View file

@ -0,0 +1,13 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
[*.py]
indent_style = space
indent_size = 4
[*.nix]
indent_style = space
indent_size = 2

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
result
result-*

61
flake.lock Normal file
View file

@ -0,0 +1,61 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1699343069,
"narHash": "sha256-s7BBhyLA6MI6FuJgs4F/SgpntHBzz40/qV0xLPW6A1Q=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "ec750fd01963ab6b20ee1f0cb488754e8036d89d",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"utils": "utils"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

21
flake.nix Normal file
View file

@ -0,0 +1,21 @@
{
description = "artemist's NixOS packages and shells for development";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, utils }: utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
in
{
packages = {
zephyr = pkgs.callPackage ./packages/zephyr { };
};
formatter = pkgs.nixfmt;
});
}

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,8 @@
{ callPackage, stdenv, lib }:
let assets = lib.importJSON ./assets.json;
in {
host-tools = callPackage ./host-tools.nix {
inherit (assets) version hosts;
sources = assets.host_tools;
};
}

View file

@ -0,0 +1,29 @@
{ stdenv, fetchurl, hosts, lib, python3, sources, version, which }:
stdenv.mkDerivation rec {
pname = "zephyr-host-tools";
inherit version;
nativeBuildInputs = [ python3 which ];
src = fetchurl (sources."${stdenv.hostPlatform.system}");
dontUnpack = true;
installPhase = ''
runHook preInstall
# Extract outer archive (no directories so nixpkgs can't unpack)
tar xvf ${src}
cp *.sh $TEMP/installer.sh
chmod +x $TEMP/installer.sh
$TEMP/installer.sh -D -n -y -d "$out"
runHook postInstall
'';
meta = with lib; {
homepage = "https://www.zephyrproject.org/";
description = "Host tools for building the Zephyr RTOS";
license = licenses.asl20;
platforms = hosts;
maintainers = with maintainers; [ artemist ];
};
}

55
packages/zephyr/update.py Executable file
View file

@ -0,0 +1,55 @@
#!/usr/bin/env nix-shell
#! nix-shell -i python3 -p python3 python3Packages.requests
import requests
import json
import subprocess
import os
import re
def prefetch_file(url: str) -> str:
out = subprocess.run(
["nix", "store", "prefetch-file", "--json", url],
stdout=subprocess.PIPE,
check=True,
)
return json.loads(out.stdout.decode("utf-8"))["hash"]
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
HOSTS = ["aarch64", "x86_64"]
release = requests.get(
"https://api.github.com/repos/zephyrproject-rtos/sdk-ng/releases/latest"
).json()
tag = release["tag_name"]
targets = []
for asset in release["assets"]:
if (
match := re.fullmatch(
r"toolchain_linux-aarch64_([a-zA-Z0-9_-]+)\.tar\.xz", asset["name"]
)
) is not None:
targets.append(match.group(1))
host_tools = {}
for host in HOSTS:
url = f"https://github.com/zephyrproject-rtos/sdk-ng/releases/download/{tag}/hosttools_linux-{host}.tar.xz"
host_tools[host + "-linux"] = {"url": url, "hash": prefetch_file(url)}
toolchains = {}
for target in targets:
toolchains[target] = {}
for host in HOSTS:
url = f"https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.3/toolchain_linux-{host}_{target}.tar.xz"
toolchains[target][host + "-linux"] = {"url": url, "hash": prefetch_file(url)}
out_obj = {
"version": tag[1:],
"hosts": list(map(lambda arch: arch + "-linux", HOSTS)),
"host_tools": host_tools,
"toolchains": toolchains,
}
with open(os.path.join(BASE_DIR, "assets.json"), "w") as out_file:
json.dump(out_obj, out_file)