From 6d4e6c1721ed518b215ccec6013b06189a0607f2 Mon Sep 17 00:00:00 2001
From: Benjamin Koch <bbbsnowball@gmail.com>
Date: Mon, 29 May 2023 18:03:16 +0200
Subject: [PATCH] refactor devShells: default shell contains kibot+rust, now

---
 flake.nix | 103 ++++++++++++++++++++++++++++++++----------------------
 1 file changed, 61 insertions(+), 42 deletions(-)

diff --git a/flake.nix b/flake.nix
index d09bb70..c4b1230 100644
--- a/flake.nix
+++ b/flake.nix
@@ -116,48 +116,67 @@
           kibot = flake-utils.lib.mkApp { drv = self.packages.${system}.kibot; };
           default = kibot;
         };
-        devShells.default = with self.packages.${system}; pkgs.mkShell {
-          packages = [
-            (python3.withPackages (p: [ kibot ]))
-            kibot
-          ];
-
-          shellHook = ''
-            # KiAuto wants to run stuff inside xvfb so let's make sure that we don't leak windows to our Wayland desktop.
-            unset WAYLAND_DISPLAY
-
-            # The Kicad package puts several paths into environment variables but only in the wrapper script.
-            # KiAuto needs some of them, e.g. to find footprint that are available locally.
-            source ${kicad-vars}
-
-            # Fix crash in Gtk save dialog, e.g. start eeschema, open ERC window, click save.
-            # https://github.com/NixOS/nixpkgs/issues/149812#issuecomment-1004387735
-            export XDG_DATA_DIRS="${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}:$XDG_DATA_DIRS"
-
-            # The interposer causes a crash and KiBot doesn't seem to have any way to disable it or pass extra parameters to
-            # eeschema_do but we can disable it with an environment variable.
-            export KIAUTO_INTERPOSER_DISABLE=1
-
-            # Cache 3d models
-            # -> README says that the default is not to cache but in fact it uses a sensible default.
-            #if [ -z "$KIBOT_3D_MODELS" ] ; then
-            #  if [ -n "$XDG_CACHE_HOME" ] ; then
-            #    export KIBOT_3D_MODELS="$XDG_CACHE_HOME/kibot/3d"
-            #  else
-            #    export KIBOT_3D_MODELS="$HOME/.cache/kibot/3d"
-            #  fi
-            #  if ! mkdir -p "$KIBOT_3D_MODELS" ; then
-            #    echo "WARN: I cannot create the cache directory for 3D models so they won't be cached."
-            #    unset KIBOT_3D_MODELS
-            #  fi
-            #fi
-          '';
-        };
-        devShells.rust = with self.packages.${system}; pkgs.mkShell {
-          packages = with pkgs; [
-            rustup udev.dev pkg-config openssl.dev picotool
-            (self.packages.${system}.python3.withPackages (p: with p; [ pymodbus3 pyserial modbus-tk ]))
-          ];
+        devShells = let
+          flakePkgs = self.packages.${system};
+        in rec {
+          kibot = with flakePkgs; pkgs.mkShell rec {
+            passthru.packages = [ flakePkgs.kibot ];
+            passthru.pythonPackages = p: [ flakePkgs.kibot ];
+
+            packages = passthru.packages ++ [
+              (python3.withPackages passthru.pythonPackages)
+            ];
+
+            shellHook = ''
+              # KiAuto wants to run stuff inside xvfb so let's make sure that we don't leak windows to our Wayland desktop.
+              unset WAYLAND_DISPLAY
+
+              # The Kicad package puts several paths into environment variables but only in the wrapper script.
+              # KiAuto needs some of them, e.g. to find footprint that are available locally.
+              source ${kicad-vars}
+
+              # Fix crash in Gtk save dialog, e.g. start eeschema, open ERC window, click save.
+              # https://github.com/NixOS/nixpkgs/issues/149812#issuecomment-1004387735
+              export XDG_DATA_DIRS="${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}:$XDG_DATA_DIRS"
+
+              # The interposer causes a crash and KiBot doesn't seem to have any way to disable it or pass extra parameters to
+              # eeschema_do but we can disable it with an environment variable.
+              export KIAUTO_INTERPOSER_DISABLE=1
+
+              # Cache 3d models
+              # -> README says that the default is not to cache but in fact it uses a sensible default.
+              #if [ -z "$KIBOT_3D_MODELS" ] ; then
+              #  if [ -n "$XDG_CACHE_HOME" ] ; then
+              #    export KIBOT_3D_MODELS="$XDG_CACHE_HOME/kibot/3d"
+              #  else
+              #    export KIBOT_3D_MODELS="$HOME/.cache/kibot/3d"
+              #  fi
+              #  if ! mkdir -p "$KIBOT_3D_MODELS" ; then
+              #    echo "WARN: I cannot create the cache directory for 3D models so they won't be cached."
+              #    unset KIBOT_3D_MODELS
+              #  fi
+              #fi
+            '';
+          };
+
+          rust = with flakePkgs; pkgs.mkShell rec {
+            passthru.packages = with pkgs; [
+              rustup udev.dev pkg-config openssl.dev picotool
+            ];
+            passthru.pythonPackages = p: with p; [ pymodbus3 pyserial modbus-tk ];
+
+            packages = passthru.packages ++ [
+              (python3.withPackages passthru.pythonPackages)
+            ];
+          };
+
+          default = pkgs.mkShell {
+            #packages = kibot.nativeBuildInputs ++ rust.nativeBuildInputs;
+            packages = kibot.passthru.packages ++ rust.passthru.packages ++ [
+              (flakePkgs.python3.withPackages (p: kibot.passthru.pythonPackages p ++ rust.passthru.pythonPackages p))
+            ];
+            shellHook = kibot.shellHook;
+          };
         };
       }
     );
-- 
GitLab