From 0e220a058782516c1c64f7c3f3d3f322672348c4 Mon Sep 17 00:00:00 2001 From: Anthony Rodriguez Date: Wed, 30 Oct 2024 08:31:31 +0100 Subject: [PATCH] treewide: add custom packages + mcuxpesso IDE --- flake.nix | 1 + home/programs/default.nix | 10 +++- pkgs/default.nix | 3 + pkgs/mcuxpresso/config-tools.nix | 49 +++++++++++++++ pkgs/mcuxpresso/default.nix | 3 + pkgs/mcuxpresso/ide.nix | 100 +++++++++++++++++++++++++++++++ system/core/users.nix | 1 + system/nix/nixpkgs.nix | 8 ++- system/services/default.nix | 8 +++ 9 files changed, 180 insertions(+), 3 deletions(-) create mode 100644 pkgs/default.nix create mode 100644 pkgs/mcuxpresso/config-tools.nix create mode 100644 pkgs/mcuxpresso/default.nix create mode 100644 pkgs/mcuxpresso/ide.nix diff --git a/flake.nix b/flake.nix index 72a20d2..028b60f 100644 --- a/flake.nix +++ b/flake.nix @@ -26,6 +26,7 @@ formatter = eachSystem (pkgs: treefmtEval.${pkgs.system}.config.build.wrapper); nixosModules = import ./modules; nixosConfigurations = import ./hosts {inherit self inputs;}; + packages = eachSystem (pkgs: import ./pkgs pkgs); deploy.nodes = import ./nodes {inherit self inputs;}; }; inputs = { diff --git a/home/programs/default.nix b/home/programs/default.nix index 86ca8f2..5053a3b 100644 --- a/home/programs/default.nix +++ b/home/programs/default.nix @@ -1,4 +1,8 @@ -{pkgs, ...}: { +{ + inputs, + pkgs, + ... +}: { imports = [ ./browsers ./media @@ -35,5 +39,9 @@ nautilus simple-scan entr + inputs.self.packages.${pkgs.system}.mcuxpresso.ide + dfu-util + segger-jlink + # inputs.self.packages.${pkgs.system}.mcuxpresso.config-tools ]; } diff --git a/pkgs/default.nix b/pkgs/default.nix new file mode 100644 index 0000000..452e07d --- /dev/null +++ b/pkgs/default.nix @@ -0,0 +1,3 @@ +pkgs: { + mcuxpresso = import ./mcuxpresso pkgs; +} diff --git a/pkgs/mcuxpresso/config-tools.nix b/pkgs/mcuxpresso/config-tools.nix new file mode 100644 index 0000000..7ea094f --- /dev/null +++ b/pkgs/mcuxpresso/config-tools.nix @@ -0,0 +1,49 @@ +{ + eclipses, + stdenv, + requireFile, + ... +}: let + name = "mcuxpressotools"; + version = "v16-1"; + description = "MCUXpresso Config Tools"; + filename = "mcuxpresso-config-tools-${version}_amd64.deb"; + + src = stdenv.mkDerivation { + inherit version description; + name = "${name}-src"; + src = requireFile { + url = "https://www.nxp.com/design/software/development-software/mcuxpresso-config-tools-pins-clocks-and-peripherals:MCUXpresso-Config-Tools"; + name = "${filename}.bin"; + sha256 = "sha256-BbEwxm1urV2IrgUiTiMBEAPvonQGwdL4fpqFftGgRxI="; + }; + + buildCommand = '' + # Unpack tarball. + mkdir -p deb + sh $src --target deb || true + ar -xv deb/${filename} + tar xfvz data.tar.gz -C . + + mkdir -p ./final/eclipse + mv ./opt/nxp/MCUX_CFG_v13/bin/.* final/eclipse + mv ./usr final/ + mv final/eclipse/tools final/eclipse/eclipse + mv final/eclipse/tools.ini final/eclipse/eclipse.ini + + # Create custom .eclipseproduct file + echo "name=${name} + id=com.nxp.${name} + version=${version} + " > final/eclipse/.eclipseproduct + + # Additional files + mkdir -p final/usr/share/mime + mv ./opt/nxp/MCUX_CFG_v13/mcu_data final/mcu_data + + cd ./final + tar -czf $out ./ + ''; + }; +in + eclipses.buildEclipse {inherit description name src;} diff --git a/pkgs/mcuxpresso/default.nix b/pkgs/mcuxpresso/default.nix new file mode 100644 index 0000000..4ec6d46 --- /dev/null +++ b/pkgs/mcuxpresso/default.nix @@ -0,0 +1,3 @@ +pkgs: { + ide = pkgs.callPackage ./ide.nix {}; +} diff --git a/pkgs/mcuxpresso/ide.nix b/pkgs/mcuxpresso/ide.nix new file mode 100644 index 0000000..fa49330 --- /dev/null +++ b/pkgs/mcuxpresso/ide.nix @@ -0,0 +1,100 @@ +# https://github.com/KoviRobi/nixos-config/blob/3ab3f8372d1fd021a235de4d314ef7147846513e/overlays/mcuxpresso.nix +{pkgs, ...}: let + name = "mcuxpressoide"; + version = "24.9.25"; + description = "MCUXpresso IDE"; + filename = "${name}-${version}.x86_64.deb"; + mcuxpressoideSrc = pkgs.stdenv.mkDerivation { + inherit version description; + name = "${name}-src"; + src = pkgs.requireFile { + url = "https://www.nxp.com/design/design-center/software/development-software/mcuxpresso-software-and-tools-/mcuxpresso-integrated-development-environment-ide:MCUXpresso-IDE"; + name = "${filename}.bin"; + hash = "sha256-e3g7rzZQ1WFLcUakkjaufpHMtw3qkw5lwxJuCKs6L+k="; + }; + buildCommand = '' + # Unpack tarball. + mkdir -p deb + sh $src --target deb || true + ar -xv deb/${filename} + tar xfvz data.tar.gz -C . + mkdir -p ./final/eclipse + mv ./usr/local/${name}-${version}/ide/* ./usr/local/${name}-${version}/ide/.* final/eclipse + mv final/eclipse/mcuxpressoide final/eclipse/eclipse + mv final/eclipse/mcuxpressoide.ini final/eclipse/eclipse.ini + # Create custom .eclipseproduct file + rm final/eclipse/.eclipseproduct + echo "name=${name} + id=com.nxp.${name} + version=${version} + " > final/eclipse/.eclipseproduct + # Install udev rules + mkdir -p final/lib/udev/rules.d + mv ./lib/udev/rules.d/56-pemicro.rules ./lib/udev/rules.d/85-mcuxpresso.rules final/lib/udev/rules.d/ + # Additional files + mv ./usr/local/${name}-${version}/mcu_data final/mcu_data + cd ./final + tar -czf $out ./ + ''; + }; + mcuxpressoide = pkgs.eclipses.buildEclipse { + name = "mcuxpresso-eclipse"; + inherit description; + src = mcuxpressoideSrc; + }; + + # needed because of the integrated toolchain + mcuxpressoFhsEnv = pkgs.buildFHSEnv { + name = "mcuxpresso-env"; + targetPkgs = pkgs: [ + pkgs.stdenv.cc.cc.lib + pkgs.gcc + pkgs.libgcc + pkgs.libstdcxx5 + pkgs.xorg.libXext + pkgs.xorg.libX11 + pkgs.xorg.libXrender + pkgs.xorg.libXtst + pkgs.xorg.libXi + pkgs.freetype + pkgs.alsa-lib + pkgs.ncurses + pkgs.ncurses5 + pkgs.libusb1 + pkgs.readline + pkgs.libffi + pkgs.zlib + pkgs.tcl + pkgs.libxcrypt + pkgs.libxcrypt-legacy + pkgs.libusb-compat-0_1 + ]; + + runScript = "${mcuxpressoide}/bin/eclipse"; + }; +in + # wrapper with desktop entry and udev rules + pkgs.stdenv.mkDerivation { + inherit name version description; + dontUnpack = true; + dontConfigure = true; + dontBuild = true; + nativeBuildInputs = [pkgs.copyDesktopItems]; + desktopItems = [ + (pkgs.makeDesktopItem { + inherit name; + type = "Application"; + desktopName = "MCUXpresso IDE"; + exec = "mcuxpresso"; + }) + ]; + installPhase = '' + runHook preInstall + mkdir -p $out/bin $out/lib/udev/rules.d $out/eclipse $out/mcu_data + + cp ${mcuxpressoide}/lib/udev/rules.d/85-mcuxpresso.rules ${mcuxpressoide}/lib/udev/rules.d/56-pemicro.rules $out/lib/udev/rules.d/ + + ln -s ${mcuxpressoFhsEnv}/bin/mcuxpresso-env $out/bin/mcuxpresso + runHook postInstall + ''; + } diff --git a/system/core/users.nix b/system/core/users.nix index 815b366..33e12ca 100644 --- a/system/core/users.nix +++ b/system/core/users.nix @@ -7,6 +7,7 @@ "audio" "video" "wheel" + "plugdev" ]; }; } diff --git a/system/nix/nixpkgs.nix b/system/nix/nixpkgs.nix index 07b22ca..ccc951d 100644 --- a/system/nix/nixpkgs.nix +++ b/system/nix/nixpkgs.nix @@ -1,6 +1,5 @@ {pkgs, ...}: { nixpkgs = { - config.allowUnfree = true; overlays = [ (_: prev: { lib = @@ -10,6 +9,11 @@ }; }) ]; - config.permittedInsecurePackages = ["cinny-4.2.2" "cinny-unwrapped-4.2.2"]; + + config = { + allowUnfree = true; + permittedInsecurePackages = ["cinny-4.2.2" "cinny-unwrapped-4.2.2" "segger-jlink-qt4-796s"]; + segger-jlink.acceptLicense = true; + }; }; } diff --git a/system/services/default.nix b/system/services/default.nix index 81b0815..0185c1e 100644 --- a/system/services/default.nix +++ b/system/services/default.nix @@ -1,3 +1,11 @@ { + inputs, + pkgs, + ... +}: { imports = [./docker.nix ./gnupg.nix ./pipewire.nix ./kmscon.nix]; + services.udev.packages = [pkgs.segger-jlink inputs.self.packages.${pkgs.system}.mcuxpresso.ide]; + services.udev.extraRules = '' + SUBSYSTEM=="usb", ATTR{idVendor}=="1fc9", ATTR{idProduct}=="0132", MODE="0666" + ''; }