about summary refs log tree commit diff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/eaglemode/default.nix53
-rw-r--r--tools/eaglemode/plugins/example.nix17
2 files changed, 69 insertions, 1 deletions
diff --git a/tools/eaglemode/default.nix b/tools/eaglemode/default.nix
index 0b0c0caa8ba8..30983f5d5018 100644
--- a/tools/eaglemode/default.nix
+++ b/tools/eaglemode/default.nix
@@ -68,6 +68,52 @@ rec {
     ${pkgs.imagemagick}/bin/convert ${path} $out
   '';
 
+  buildPlugin = lib.makeOverridable (
+    { name
+    , src
+    , version
+    , eaglemode ? pkgs.eaglemode
+    , target ? name
+    , extraNativeBuildInputs ? [ ]
+    , extraBuildInputs ? [ ]
+    }:
+    pkgs.stdenv.mkDerivation {
+      pname = "eaglemode-plugin-${name}";
+      inherit src version;
+      # inherit (eaglemode.drvAttrs) dontPatchELF;
+
+      nativeBuildInputs = eaglemode.drvAttrs.nativeBuildInputs ++ extraNativeBuildInputs;
+      buildInputs = eaglemode.drvAttrs.buildInputs ++ extraBuildInputs ++ [ eaglemode ];
+
+      buildPhase = ''
+        runHook preBuild
+
+        # merge eaglemode & plugin folders
+        cp -r ${pkgs.srcOnly eaglemode} merged-src && chmod -R u+rw merged-src
+        cp -r $src/* merged-src && chmod -R u+rw merged-src
+        cd merged-src
+
+        export NIX_LDFLAGS="$NIX_LDFLAGS -lXxf86vm -lXext -lXinerama"
+        perl make.pl build projects=${target} continue=no
+
+        runHook postBuild
+      '';
+
+      installPhase = ''
+        runHook preInstall
+
+        mkdir -p $out/lib
+        cp -r lib/lib${target}.so $out/lib
+
+        if [ -d "$src/etc" ]; then
+          cp -r $src/etc/* $out
+        fi
+
+        runHook postInstall
+      '';
+    }
+  );
+
   # etcDir creates a directory layout suitable for use in the EM_USER_CONFIG_DIR
   # environment variable.
   #
@@ -88,8 +134,13 @@ rec {
   # withConfig creates an Eagle Mode wrapper that runs it with the given
   # configuration.
   withConfig = { eaglemode ? pkgs.eaglemode, config }: pkgs.writeShellScriptBin "eaglemode" ''
-    set -ue
     ${configWrapper}/bin/wrapper --em-config "${config}"
+
+    if [ -d "${config}/lib" ]; then
+      export LD_LIBRARY_PATH="${config}/lib:$LD_LIBRARY_PATH"
+      exec ${eaglemode}/bin/eaglemode "$@"
+    fi
+
     exec ${eaglemode}/bin/eaglemode "$@"
   '';
 }
diff --git a/tools/eaglemode/plugins/example.nix b/tools/eaglemode/plugins/example.nix
new file mode 100644
index 000000000000..b361971cc57e
--- /dev/null
+++ b/tools/eaglemode/plugins/example.nix
@@ -0,0 +1,17 @@
+{ depot, pkgs, ... }:
+
+let
+  em = depot.tools.eaglemode;
+  emSrc = with pkgs; srcOnly eaglemode;
+in
+em.buildPlugin {
+  name = "example";
+  version = "canon";
+
+  src = pkgs.runCommand "em-plugin-example-src" { } ''
+    set -ux
+    cp -r ${emSrc}/doc/examples/CppApiExamples/PluginExample $out
+  '';
+
+  target = "PlEx";
+}