From 8d8dd6fdbf6406c82faee1b3293a0b491b3b3751 Mon Sep 17 00:00:00 2001 From: adisbladis Date: Sat, 1 Apr 2023 19:23:02 +1300 Subject: [PATCH 1/3] platformio: make multi-output Currently udev rules symlinks against platformio sources, pulling in the platformio source tree into the runtime closure. Previous to platformio-core being exposed separately from platformio this also meant that you had no ergonomic way to avoid platformio in the system closure, even though you only wanted the udev rules. We can avoid this by making platformio-core multi output, making it trivial to depend only on the udev rules. --- pkgs/development/embedded/platformio/chrootenv.nix | 6 ++---- pkgs/development/embedded/platformio/core.nix | 9 +++++++++ pkgs/development/embedded/platformio/default.nix | 2 +- .../embedded/platformio/missing-udev-rules-nixos.patch | 4 +--- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pkgs/development/embedded/platformio/chrootenv.nix b/pkgs/development/embedded/platformio/chrootenv.nix index 9e84a8d6ba45..3f4a7e7385dc 100644 --- a/pkgs/development/embedded/platformio/chrootenv.nix +++ b/pkgs/development/embedded/platformio/chrootenv.nix @@ -1,4 +1,4 @@ -{ lib, buildFHSUserEnv, version, src }: +{ lib, buildFHSUserEnv, platformio-core }: let pio-pkgs = pkgs: @@ -34,10 +34,8 @@ buildFHSUserEnv { }; extraInstallCommands = '' - mkdir -p $out/lib/udev/rules.d - ln -s $out/bin/platformio $out/bin/pio - ln -s ${src}/platformio/assets/system/99-platformio-udev.rules $out/lib/udev/rules.d/99-platformio-udev.rules + ln -s ${platformio-core.udev}/lib $out/lib ''; runScript = "platformio"; diff --git a/pkgs/development/embedded/platformio/core.nix b/pkgs/development/embedded/platformio/core.nix index 00ee07a5fc5b..c0127fae5acb 100644 --- a/pkgs/development/embedded/platformio/core.nix +++ b/pkgs/development/embedded/platformio/core.nix @@ -10,6 +10,8 @@ with python3.pkgs; buildPythonApplication rec { pname = "platformio"; inherit version src; + outputs = [ "out" "udev" ]; + patches = [ ./fix-searchpath.patch ./use-local-spdx-license-list.patch @@ -60,6 +62,13 @@ with python3.pkgs; buildPythonApplication rec { pytestCheckHook ]; + # Install udev rules into a separate output so all of platformio-core is not a dependency if + # you want to use the udev rules on NixOS but not install platformio in your system packages. + postInstall = '' + mkdir -p $udev/lib/udev/rules.d/99-platformio-udev.rules + cp platformio/assets/system/99-platformio-udev.rules $udev/lib/udev/rules.d/99-platformio-udev.rules + ''; + disabledTestPaths = [ "tests/commands/pkg/test_install.py" "tests/commands/pkg/test_list.py" diff --git a/pkgs/development/embedded/platformio/default.nix b/pkgs/development/embedded/platformio/default.nix index fbcce7eae60e..70a11f5736f3 100644 --- a/pkgs/development/embedded/platformio/default.nix +++ b/pkgs/development/embedded/platformio/default.nix @@ -16,7 +16,7 @@ let self = { platformio-core = python3Packages.callPackage ./core.nix { inherit version src; }; - platformio-chrootenv = callPackage ./chrootenv.nix { inherit version src; }; + platformio-chrootenv = callPackage ./chrootenv.nix { }; }; in diff --git a/pkgs/development/embedded/platformio/missing-udev-rules-nixos.patch b/pkgs/development/embedded/platformio/missing-udev-rules-nixos.patch index 2a978496a19b..4be06ceac8b1 100644 --- a/pkgs/development/embedded/platformio/missing-udev-rules-nixos.patch +++ b/pkgs/development/embedded/platformio/missing-udev-rules-nixos.patch @@ -6,7 +6,5 @@ index ef1d3bab..445174fc 100644 MESSAGE = ( "Warning! Please install `99-platformio-udev.rules`. \nMore details: " "https://docs.platformio.org/en/latest/core/installation/udev-rules.html" -+ "On NixOS add the platformio package to services.udev.packages" ++ "On NixOS add the platformio-core.udev package to services.udev.packages" ) - - From fcbc5d74e73dbac4d2bb28c628a09630561b52d1 Mon Sep 17 00:00:00 2001 From: adisbladis Date: Sat, 1 Apr 2023 19:30:52 +1300 Subject: [PATCH 2/3] platformio-core: move src & version to main expression --- pkgs/development/embedded/platformio/core.nix | 12 ++++++++++-- pkgs/development/embedded/platformio/default.nix | 12 +----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/pkgs/development/embedded/platformio/core.nix b/pkgs/development/embedded/platformio/core.nix index c0127fae5acb..1ac707f01461 100644 --- a/pkgs/development/embedded/platformio/core.nix +++ b/pkgs/development/embedded/platformio/core.nix @@ -3,12 +3,20 @@ , fetchPypi , git , spdx-license-list-data -, version, src }: with python3.pkgs; buildPythonApplication rec { pname = "platformio"; - inherit version src; + + version = "6.1.6"; + + # pypi tarballs don't contain tests - https://github.com/platformio/platformio-core/issues/1964 + src = fetchFromGitHub { + owner = "platformio"; + repo = "platformio-core"; + rev = "v${version}"; + sha256 = "sha256-BEeMfdmAWqFbQUu8YKKrookQVgmhfZBqXnzeb2gfhms="; + }; outputs = [ "out" "udev" ]; diff --git a/pkgs/development/embedded/platformio/default.nix b/pkgs/development/embedded/platformio/default.nix index 70a11f5736f3..956d7dee06cd 100644 --- a/pkgs/development/embedded/platformio/default.nix +++ b/pkgs/development/embedded/platformio/default.nix @@ -3,18 +3,8 @@ let callPackage = newScope self; - version = "6.1.6"; - - # pypi tarballs don't contain tests - https://github.com/platformio/platformio-core/issues/1964 - src = fetchFromGitHub { - owner = "platformio"; - repo = "platformio-core"; - rev = "v${version}"; - sha256 = "sha256-BEeMfdmAWqFbQUu8YKKrookQVgmhfZBqXnzeb2gfhms="; - }; - self = { - platformio-core = python3Packages.callPackage ./core.nix { inherit version src; }; + platformio-core = python3Packages.callPackage ./core.nix { }; platformio-chrootenv = callPackage ./chrootenv.nix { }; }; From bd3361bcfb3332ed8209a748c350532195267ef0 Mon Sep 17 00:00:00 2001 From: adisbladis Date: Sat, 1 Apr 2023 19:33:08 +1300 Subject: [PATCH 3/3] platformio: ensure coherent python interpreter with platformio-core --- pkgs/development/embedded/platformio/chrootenv.nix | 2 +- pkgs/development/embedded/platformio/core.nix | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/development/embedded/platformio/chrootenv.nix b/pkgs/development/embedded/platformio/chrootenv.nix index 3f4a7e7385dc..b914743f5152 100644 --- a/pkgs/development/embedded/platformio/chrootenv.nix +++ b/pkgs/development/embedded/platformio/chrootenv.nix @@ -3,7 +3,7 @@ let pio-pkgs = pkgs: let - python = pkgs.python3; + inherit (platformio-core) python; in (with pkgs; [ platformio-core diff --git a/pkgs/development/embedded/platformio/core.nix b/pkgs/development/embedded/platformio/core.nix index 1ac707f01461..81ad2354c99a 100644 --- a/pkgs/development/embedded/platformio/core.nix +++ b/pkgs/development/embedded/platformio/core.nix @@ -162,6 +162,10 @@ with python3.pkgs; buildPythonApplication rec { "test_pkgmanifest.py::test_packages" ]); + passthru = { + python = python3; + }; + meta = with lib; { description = "An open source ecosystem for IoT development"; homepage = "https://platformio.org";