Merge pull request #319342 from h7x4/pkgs-segger-jlink-misc-fixups

This commit is contained in:
Sandro 2024-07-04 12:00:35 +02:00 committed by GitHub
commit b8a6b3ff38
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 245 additions and 128 deletions

191
pkgs/by-name/se/segger-jlink/package.nix Executable file → Normal file
View File

@ -1,39 +1,23 @@
{ lib
, stdenv
, fetchurl
, callPackage
, autoPatchelfHook
, udev
, config
, acceptLicense ? config.segger-jlink.acceptLicense or false
, fontconfig
, xorg
, headless ? false
, makeDesktopItem
, copyDesktopItems
}:
let
supported = {
x86_64-linux = {
name = "x86_64";
hash = "sha256-UsDP+wMS7ZeWMQBObwv5RxbwuWU8nLnHes7LEXK6imE=";
};
i686-linux = {
name = "i386";
hash = "sha256-InNHXWAc6QZEWyEcTTUCRMDsKd0RtR8d7O0clWKuFo8=";
};
aarch64-linux = {
name = "arm64";
hash = "sha256-ueIGdqfuIRCuEwaPkgZMgghO9DU11IboLLMryg/mxQ8=";
};
armv7l-linux = {
name = "arm";
hash = "sha256-6nTQGQpkbqQntheQqiUAdVS4rp30nl2KRUn5Adsfeoo=";
};
};
source = import ./source.nix;
supported = removeAttrs source ["version"];
platform = supported.${stdenv.system} or (throw "unsupported platform ${stdenv.system}");
version = "796b";
inherit (source) version;
url = "https://www.segger.com/downloads/jlink/JLink_Linux_V${version}_${platform.name}.tgz";
@ -66,69 +50,7 @@ let
curlOpts = "--data accept_license_agreement=accepted";
};
qt4-bundled = stdenv.mkDerivation {
pname = "segger-jlink-qt4";
inherit src version;
nativeBuildInputs = [
autoPatchelfHook
];
buildInputs = [
stdenv.cc.cc.lib
fontconfig
xorg.libXrandr
xorg.libXfixes
xorg.libXcursor
xorg.libSM
xorg.libICE
xorg.libX11
];
dontConfigure = true;
dontBuild = true;
installPhase = ''
runHook preInstall
# Install libraries
mkdir -p $out/lib
mv libQt* $out/lib
runHook postInstall
'';
meta = with lib; {
description = "Bundled QT4 libraries for the J-Link Software and Documentation pack";
homepage = "https://www.segger.com/downloads/jlink/#J-LinkSoftwareAndDocumentationPack";
license = licenses.lgpl21;
maintainers = with maintainers; [ stargate01 ];
knownVulnerabilities = [
"This bundled version of Qt 4 has reached its end of life after 2015. See https://github.com/NixOS/nixpkgs/pull/174634"
"CVE-2023-43114"
"CVE-2023-38197"
"CVE-2023-37369"
"CVE-2023-34410"
"CVE-2023-32763"
"CVE-2023-32762"
"CVE-2023-32573"
"CVE-2022-25634"
"CVE-2020-17507"
"CVE-2020-0570"
"CVE-2018-21035"
"CVE-2018-19873"
"CVE-2018-19871"
"CVE-2018-19870"
"CVE-2018-19869"
"CVE-2015-1290"
"CVE-2014-0190"
"CVE-2013-0254"
"CVE-2012-6093"
"CVE-2012-5624"
"CVE-2009-2700"
];
};
};
qt4-bundled = callPackage ./qt4-bundled.nix { inherit src version; };
in stdenv.mkDerivation {
pname = "segger-jlink";
@ -136,10 +58,11 @@ in stdenv.mkDerivation {
nativeBuildInputs = [
autoPatchelfHook
] ++ lib.optionals (!headless) [
copyDesktopItems
];
buildInputs = [
buildInputs = lib.optionals (!headless) [
qt4-bundled
];
@ -151,55 +74,60 @@ in stdenv.mkDerivation {
dontConfigure = true;
dontBuild = true;
desktopItems = map (entry:
(makeDesktopItem {
name = entry;
exec = entry;
icon = "applications-utilities";
desktopName = entry;
genericName = "SEGGER ${entry}";
categories = [ "Development" ];
type = "Application";
terminal = false;
startupNotify = false;
})
) [
"JFlash"
"JFlashLite"
"JFlashSPI"
"JLinkConfig"
"JLinkGDBServer"
"JLinkLicenseManager"
"JLinkRTTViewer"
"JLinkRegistration"
"JLinkRemoteServer"
"JLinkSWOViewer"
"JLinkUSBWebServer"
"JMem"
];
desktopItems = lib.optionals (!headless) (
map (entry:
(makeDesktopItem {
name = entry;
exec = entry;
icon = "applications-utilities";
desktopName = entry;
genericName = "SEGGER ${entry}";
categories = [ "Development" ];
type = "Application";
terminal = false;
startupNotify = false;
})
) [
"JFlash"
"JFlashLite"
"JFlashSPI"
"JLinkConfig"
"JLinkGDBServer"
"JLinkLicenseManager"
"JLinkRTTViewer"
"JLinkRegistration"
"JLinkRemoteServer"
"JLinkSWOViewer"
"JLinkUSBWebServer"
"JMem"
]
);
installPhase = ''
runHook preInstall
# Install binaries and runtime files into /opt/
mkdir -p $out/opt
mv J* ETC GDBServer Firmwares $out/opt
# Link executables into /bin/
mkdir -p $out/bin
for binr in $out/opt/*Exe; do
binrlink=''${binr#"$out/opt/"}
ln -s $binr $out/bin/$binrlink
# Create additional symlinks without "Exe" suffix
binrlink=''${binrlink/%Exe}
ln -s $binr $out/bin/$binrlink
done
${lib.optionalString (!headless) ''
# Install binaries and runtime files into /opt/
mv J* ETC GDBServer Firmwares $out/opt
# Copy special alias symlinks
for slink in $(find $out/opt/. -type l); do
cp -P -n $slink $out/bin || true
rm $slink
done
# Link executables into /bin/
mkdir -p $out/bin
for binr in $out/opt/*Exe; do
binrlink=''${binr#"$out/opt/"}
ln -s $binr $out/bin/$binrlink
# Create additional symlinks without "Exe" suffix
binrlink=''${binrlink/%Exe}
ln -s $binr $out/bin/$binrlink
done
# Copy special alias symlinks
for slink in $(find $out/opt/. -type l); do
cp -P -n $slink $out/bin || true
rm $slink
done
''}
# Install libraries
install -Dm444 libjlinkarm.so* -t $out/lib
@ -218,11 +146,18 @@ in stdenv.mkDerivation {
runHook postInstall
'';
passthru.updateScript = ./update.py;
meta = with lib; {
description = "J-Link Software and Documentation pack";
homepage = "https://www.segger.com/downloads/jlink/#J-LinkSoftwareAndDocumentationPack";
changelog = "https://www.segger.com/downloads/jlink/ReleaseNotes_JLink.html";
license = licenses.unfree;
platforms = attrNames supported;
maintainers = with maintainers; [ FlorianFranzen stargate01 ];
maintainers = with maintainers; [
FlorianFranzen
h7x4
stargate01
];
};
}

View File

@ -0,0 +1,74 @@
{
lib
, stdenv
, src
, version
, autoPatchelfHook
, fontconfig
, xorg
}:
stdenv.mkDerivation {
pname = "segger-jlink-qt4";
inherit src version;
nativeBuildInputs = [
autoPatchelfHook
];
buildInputs = [
stdenv.cc.cc.lib
fontconfig
xorg.libXrandr
xorg.libXfixes
xorg.libXcursor
xorg.libSM
xorg.libICE
xorg.libX11
];
dontConfigure = true;
dontBuild = true;
installPhase = ''
runHook preInstall
# Install libraries
mkdir -p $out/lib
mv libQt* $out/lib
runHook postInstall
'';
meta = with lib; {
description = "Bundled QT4 libraries for the J-Link Software and Documentation pack";
homepage = "https://www.segger.com/downloads/jlink/#J-LinkSoftwareAndDocumentationPack";
license = licenses.lgpl21;
maintainers = with maintainers; [ stargate01 ];
knownVulnerabilities = [
"This bundled version of Qt 4 has reached its end of life after 2015. See https://github.com/NixOS/nixpkgs/pull/174634"
"CVE-2023-43114"
"CVE-2023-38197"
"CVE-2023-37369"
"CVE-2023-34410"
"CVE-2023-32763"
"CVE-2023-32762"
"CVE-2023-32573"
"CVE-2022-25634"
"CVE-2020-17507"
"CVE-2020-0570"
"CVE-2018-21035"
"CVE-2018-19873"
"CVE-2018-19871"
"CVE-2018-19870"
"CVE-2018-19869"
"CVE-2015-1290"
"CVE-2014-0190"
"CVE-2013-0254"
"CVE-2012-6093"
"CVE-2012-5624"
"CVE-2009-2700"
];
};
}

View File

@ -0,0 +1,19 @@
{
version = "796k";
x86_64-linux = {
name = "x86_64";
hash = "sha256-GDmdKjMD9nJLPl4Qaxgrb5+b9CsUdyNqNak1JG4ERjo=";
};
i686-linux = {
name = "i386";
hash = "sha256-8j2UkPtDyIA+mfXl4jIVp89CpGA+T4eU5IQ0GwROgwU=";
};
aarch64-linux = {
name = "arm64";
hash = "sha256-FIzg7vAPlhnjuKEm5uGa7a37srp1U0e4eqlG9C6q26s=";
};
armv7l-linux = {
name = "arm";
hash = "sha256-NceqkV54QVXEJr4pJ3nvY3zxSYb9Er0uQWQ4vaojkv8=";
};
}

View File

@ -0,0 +1,87 @@
#! /usr/bin/env nix-shell
#! nix-shell -i python3 -p python3 python3Packages.beautifulsoup4 python3Packages.requests
import requests
import subprocess
from bs4 import BeautifulSoup
from pathlib import Path
from tempfile import NamedTemporaryFile
from textwrap import indent, dedent
ARCH_MAP = {
'x86_64-linux': 'x86_64',
'i686-linux': 'i386',
'aarch64-linux': 'arm64',
'armv7l-linux': 'arm',
}
def find_latest_jlink_version() -> str:
try:
response = requests.get('https://www.segger.com/downloads/jlink/')
response.raise_for_status()
except requests.RequestException as e:
raise RuntimeError(f"Error fetching J-Link version: {e}")
soup = BeautifulSoup(response.text, 'html.parser')
jlink_download_tile = soup.find(lambda tag: tag.name == 'tbody' and "J-Link Software and Documentation pack" in tag.text)
version_select = jlink_download_tile.find('select')
version = next(o.text for o in version_select.find_all('option'))
if version is None:
raise RuntimeError("Could not find the J-Link version on the download page.")
return version.removeprefix('V').replace('.', '')
def nar_hash(url: str) -> str:
try:
response = requests.post(url, data={'accept_license_agreement': 'accepted'})
response.raise_for_status()
except requests.RequestException as e:
raise RuntimeError(f"Error downloading file from {url}: {e}")
with NamedTemporaryFile() as tmpfile:
tmpfile.write(response.content)
tmpfile.flush()
output = subprocess.check_output([
"nix",
"--extra-experimental-features", "nix-command",
"hash", "file", "--sri", tmpfile.name
]).decode("utf8")
return output.strip()
def calculate_package_hashes(version: str) -> list[tuple[str, str, str]]:
result = []
for (arch_nix, arch_web) in ARCH_MAP.items():
url = f"https://www.segger.com/downloads/jlink/JLink_Linux_V{version}_{arch_web}.tgz";
nhash = nar_hash(url)
result.append((arch_nix, arch_web, nhash))
return result
def update_source(version: str, package_hashes: list[tuple[str, str, str]]):
content = f'version = "{version}";\n'
for arch_nix, arch_web, nhash in package_hashes:
content += dedent(f'''
{arch_nix} = {{
name = "{arch_web}";
hash = "{nhash}";
}};''').strip() + '\n'
content = '{\n' + indent(content, ' ') + '}\n'
with open(Path(__file__).parent / 'source.nix', 'w') as file:
file.write(content)
if __name__ == '__main__':
version = find_latest_jlink_version()
package_hashes = calculate_package_hashes(version)
update_source(version, package_hashes)

View File

@ -12680,6 +12680,8 @@ with pkgs;
seehecht = callPackage ../tools/text/seehecht { };
segger-jlink-headless = callPackage ../by-name/se/segger-jlink/package.nix { headless = true; };
selectdefaultapplication = libsForQt5.callPackage ../applications/misc/selectdefaultapplication { };
semantic-release = callPackage ../development/tools/semantic-release {