packages/jlink: bring from personal config

This commit is contained in:
Artemis Tosini 2023-12-02 00:20:35 +00:00
parent 6400d73e5f
commit b0d398ca8c
Signed by: artemist
GPG key ID: ADFFE553DCBB831E
5 changed files with 117 additions and 4 deletions

View file

@ -2,11 +2,11 @@
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1699343069,
"narHash": "sha256-s7BBhyLA6MI6FuJgs4F/SgpntHBzz40/qV0xLPW6A1Q=",
"lastModified": 1701336116,
"narHash": "sha256-kEmpezCR/FpITc6yMbAh4WrOCiT2zg5pSjnKrq51h5Y=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "ec750fd01963ab6b20ee1f0cb488754e8036d89d",
"rev": "f5c27c6136db4d76c30e533c20517df6864c46ee",
"type": "github"
},
"original": {

View file

@ -14,7 +14,10 @@
overlays = [ (final: prev: self.packages."${system}") ];
};
in {
packages = { zephyr = pkgs.callPackage ./packages/zephyr { }; };
packages = {
jlink = pkgs.callPackage ./packages/jlink { };
zephyr = pkgs.callPackage ./packages/zephyr { };
};
devShells = { zephyr = pkgs.callPackage ./shells/zephyr { }; };

View file

@ -0,0 +1,57 @@
{ stdenv, lib, fetchurl, autoPatchelfHook, fontconfig, freetype, libusb, libICE
, libSM, ncurses5, udev, libX11, libXext, libXcursor, libXfixes, libXrender
, libXrandr }:
let
conf = (lib.importJSON ./version.json).${stdenv.hostPlatform.system} or (throw
"unsupported system ${stdenv.hostPlatform.system}");
in stdenv.mkDerivation rec {
pname = "jlink";
version = conf.version;
src = fetchurl { inherit (conf) url hash curlOpts; };
dontConfigure = true;
dontBuild = true;
dontStrip = true;
preferLocalBuild = true;
nativeBuildInputs = [ autoPatchelfHook ];
buildInputs = [
fontconfig
freetype
libusb
libICE
libSM
ncurses5
udev
libX11
libXext
libXcursor
libXfixes
libXrender
libXrandr
];
runtimeDependencies = [ udev ];
installPhase = ''
mkdir -p $out/{JLink,bin}
cp -R * $out/JLink
ln -s $out/JLink/J* $out/bin/
install -D -t $out/lib/udev/rules.d 99-jlink.rules
'';
preFixup = ''
patchelf --add-needed libudev.so.1 $out/JLink/libjlinkarm.so
'';
passthru.updateScript = ./update.py;
meta = with lib; {
homepage = "https://www.segger.com/downloads/jlink";
description = "SEGGER J-Link";
license = licenses.unfree;
platforms = [ "x86_64-linux" "i686-linux" "armv7l-linux" "aarch64-linux" ];
maintainers = with maintainers; [ artemist ];
};
}

52
packages/jlink/update.py Executable file
View file

@ -0,0 +1,52 @@
#!/usr/bin/env nix-shell
#! nix-shell -i python3 -p "python3.withPackages (ps: with ps; [ beautifulsoup4 requests lxml ] )" nix-prefetch
import requests
import bs4
import json
import subprocess
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
URL_FORMAT = "https://www.segger.com/downloads/jlink/JLink_Linux_V{version}_{arch}.tgz"
CURL_OPTS = "-d accept_license_agreement=accepted -d submit=Download+software"
page = requests.get("https://www.segger.com/downloads/jlink").text
elem = (
bs4.BeautifulSoup(page, features="lxml")
.find("select", {"class": "version"})
.find("option")
)
version = elem.children.__next__().lstrip("V")
arches = [
("x86_64-linux", "x86_64"),
("i686-linux", "i686"),
("armv7l-linux", "arm"),
("aarch64-linux", "arm64"),
]
out_obj = {}
for nix_arch, jlink_arch in arches:
url = URL_FORMAT.format(version=version.replace(".", ""), arch=jlink_arch)
out = subprocess.run(
[
"nix-prefetch",
f'{{fetchurl}}: fetchurl {{ url = "{url}"; curlOpts = "{CURL_OPTS}"; }}',
],
stdout=subprocess.PIPE,
check=True,
)
file_hash = out.stdout.decode("utf8").strip()
out_obj[nix_arch] = {
"url": url,
"version": version,
"curlOpts": CURL_OPTS,
"hash": file_hash,
}
out_file = open(os.path.join(BASE_DIR, "version.json"), "w")
json.dump(out_obj, out_file)
out_file.close()

View file

@ -0,0 +1 @@
{"x86_64-linux": {"url": "https://www.segger.com/downloads/jlink/JLink_Linux_V794_x86_64.tgz", "version": "7.94", "curlOpts": "-d accept_license_agreement=accepted -d submit=Download+software", "hash": "sha256-6Gvmz/EsEBK7VZ+EW4RMiCiA0mauLBgdmKvU1FyfODY="}, "i686-linux": {"url": "https://www.segger.com/downloads/jlink/JLink_Linux_V794_i686.tgz", "version": "7.94", "curlOpts": "-d accept_license_agreement=accepted -d submit=Download+software", "hash": "sha256-lYDxkNIwuCZ9qkeZ9clBQEMx5283DgoU13SLROdr2bs="}, "armv7l-linux": {"url": "https://www.segger.com/downloads/jlink/JLink_Linux_V794_arm.tgz", "version": "7.94", "curlOpts": "-d accept_license_agreement=accepted -d submit=Download+software", "hash": "sha256-9jCd9w7TBasvP+rk6z/3E2tgOvpGOfLiYWiHxAYtAA0="}, "aarch64-linux": {"url": "https://www.segger.com/downloads/jlink/JLink_Linux_V794_arm64.tgz", "version": "7.94", "curlOpts": "-d accept_license_agreement=accepted -d submit=Download+software", "hash": "sha256-VPxD8FlPvlLQM+lFsgK88ksXbrGDkZYlR5FYl8A550s="}}