From cdd6ddad6f6efb4874b83ac08c9616daafe07293 Mon Sep 17 00:00:00 2001 From: Artemis Tosini Date: Sun, 12 Nov 2023 01:16:34 +0000 Subject: [PATCH] Able to build zephyr toolchains --- flake.nix | 21 ++++++++---------- packages/zephyr/default.nix | 8 ++++++- packages/zephyr/toolchain.nix | 42 +++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 packages/zephyr/toolchain.nix diff --git a/flake.nix b/flake.nix index d86b028..53e6f9a 100644 --- a/flake.nix +++ b/flake.nix @@ -1,21 +1,18 @@ { 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 { }; - }; + outputs = { self, nixpkgs, utils }: + utils.lib.eachDefaultSystem (system: + let pkgs = import nixpkgs { inherit system; }; + in { + packages = { zephyr = pkgs.callPackage ./packages/zephyr { }; }; - formatter = pkgs.nixfmt; - }); - } + formatter = pkgs.nixfmt; + }); +} diff --git a/packages/zephyr/default.nix b/packages/zephyr/default.nix index 19fe43e..6844833 100644 --- a/packages/zephyr/default.nix +++ b/packages/zephyr/default.nix @@ -1,8 +1,14 @@ { callPackage, stdenv, lib }: let assets = lib.importJSON ./assets.json; -in { +in rec { host-tools = callPackage ./host-tools.nix { inherit (assets) version hosts; sources = assets.host_tools; }; + + toolchains = lib.mapAttrs (target: sources: + callPackage ./toolchain.nix { + inherit target sources; + inherit (assets) version hosts; + }) assets.toolchains; } diff --git a/packages/zephyr/toolchain.nix b/packages/zephyr/toolchain.nix new file mode 100644 index 0000000..e59c52e --- /dev/null +++ b/packages/zephyr/toolchain.nix @@ -0,0 +1,42 @@ +{ stdenv, lib, fetchurl, autoPatchelfHook, target, sources, version, hosts }: + +stdenv.mkDerivation { + pname = "zephyr-toolchain-${target}"; + inherit version; + + src = fetchurl (sources."${stdenv.hostPlatform.system}"); + + dontConfigure = true; + dontUnpack = true; + dontBuild = true; + # If we're building the same architecture as the target it will mess with files like + # crt1.o, so use autopatchelf and only some files + dontPatchELF = true; + dontAutoPatchelf = true; + nativeBuildInputs = [ autoPatchelfHook ]; + autoPatchelfIgnoreMissingDeps = [ "libpython*" ]; + + installPhase = '' + runHook preInstall + mkdir -p "$out" + tar -C "$out" -xvf "$src" + runHook postInstall + ''; + + preFixup = '' + autoPatchelf ${target}/bin + autoPatchelf ${target}/${target}/bin + autoPatchelf ${target}/lib/bfd-plugins + autoPatchelf ${target}/lib/gcc/${target}/*/plugin ${target}/libexec/gcc/${target} + echo "done with my autopatchelf" + ''; + + meta = with lib; { + homepage = "https://www.zephyrproject.org/"; + description = + "Toolchain for building Zephyr for the ${target} architecture"; + license = licenses.asl20; + platforms = hosts; + maintainers = with maintainers; [ artemist ]; + }; +}