about summary refs log tree commit diff
path: root/users/wpcarro/emacs/default.nix
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2022-11-21T03·20-0800
committerclbot <clbot@tvl.fyi>2022-12-01T19·29+0000
commite5b9eafb8d169d25f97073e32ecbf3673b433afe (patch)
treef451d60f41d7f851d847dfda028b5a3f604a0d26 /users/wpcarro/emacs/default.nix
parent4cd4111d0d0bf6078030d17c629184cb5bc1dd43 (diff)
feat(wpcarro/emacs): Package emacs GUI for OSX r/5358
Did a little reverse-engineering to try and figure out how to package GUIs for
OSX, which where I learned about:
- `Info.plist`
- `version.plist`
- `pkgs.lib.generators.toPlist`

I'm sure there is more to do to make idiomatically pkg this, but this is enough
to get started, and I need to move-on.

Change-Id: I5168eada32223c5cc2f20defd3d27bccaceb3775
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7317
Autosubmit: wpcarro <wpcarro@gmail.com>
Tested-by: BuildkiteCI
Reviewed-by: wpcarro <wpcarro@gmail.com>
Diffstat (limited to 'users/wpcarro/emacs/default.nix')
-rw-r--r--users/wpcarro/emacs/default.nix80
1 files changed, 66 insertions, 14 deletions
diff --git a/users/wpcarro/emacs/default.nix b/users/wpcarro/emacs/default.nix
index 4ba737d75282..3af7d2648cc8 100644
--- a/users/wpcarro/emacs/default.nix
+++ b/users/wpcarro/emacs/default.nix
@@ -3,7 +3,7 @@
 # - Darwin
 #
 # USAGE:
-#   $ mg build //users/wpcarro/emacs:osx
+#   $ nix-build -A users.wpcarro.emacs.osx -o /Applications/BillsEmacs.app
 { depot, pkgs, lib, ... }:
 
 # TODO(wpcarro): See if it's possible to expose emacsclient on PATH, so that I
@@ -32,10 +32,10 @@ let
       rust-analyzer
       rustc
       rustfmt
+      xorg.xset
     ] ++
     (if pkgs.stdenv.isLinux then [
       scrot
-      xorg.xset
     ] else [ ]))
   );
 
@@ -174,25 +174,75 @@ let
         ${concatStringsSep "\n  " (map (el: "--load ${el} \\") load)}
         "$@"
     '';
+
+  # I can't figure out how to augment LSEnvironment.PATH such that it inherits
+  # the default $PATH and adds the things that I need as well, so let's
+  # hardcode the desired outcome in the meantime.
+  osxDefaultPath = builtins.concatStringsSep ":" [
+    "/Users/bill/.nix-profile/bin"
+    "/nix/var/nix/profiles/default/bin"
+    "/opt/homebrew/bin"
+    "/opt/homebrew/sbin"
+    "/usr/local/bin"
+    "/usr/bin"
+    "/bin"
+    "/usr/sbin"
+    "/sbin"
+    "/opt/X11/bin"
+  ];
+
+  infoPlist = pkgs.writeText "Info.plist" (pkgs.lib.generators.toPlist { } {
+    LSEnvironment = {
+      PATH = "${emacsBinPath}:${osxDefaultPath}";
+    };
+    CFBundleExecutable = "BillsEmacs";
+    CFBundleDisplayName = "BillsEmacs";
+    CFBundleIconFile = "AppIcon";
+    CFBundleIconName = "AppIcon";
+  });
+
+  versionPlist = pkgs.writeText "version.plist" (pkgs.lib.generators.toPlist { } {
+    ProjectName = "OSXPlatformSupport";
+  });
 in
-depot.nix.readTree.drvTargets {
+{
   # TODO(wpcarro): Support this with base.overrideAttrs or something similar.
   nixos = { load ? [ ] }: withEmacsPath {
     inherit load;
     emacsBin = "${wpcarrosEmacs}/bin/emacs";
   };
 
-  osx = writeShellScriptBin "wpcarros-emacs" ''
-    export PATH="${emacsBinPath}:$PATH"
-    export EMACSLOADPATH="${loadPath}"
-    exec ${wpcarrosEmacs}/bin/emacs \
-      --debug-init \
-      --no-init-file \
-      --no-site-file \
-      --no-site-lisp \
-      --load ${./.emacs.d/init.el} \
-      "$@"
-  '';
+  # To install GUI:
+  # $ nix-build -A users.wpcarro.emacs.osx -o /Applications/BillsEmacs.app
+  osx = pkgs.stdenv.mkDerivation {
+    pname = "bills-emacs";
+    version = "0.0.1";
+    src = ./.;
+    dontFixup = true;
+    installPhase = ''
+      runHook preInstall
+      APP="$out"
+      mkdir -p "$APP/Contents/MacOS"
+      mkdir -p "$APP/Contents/Resources"
+      cp ${infoPlist}      "$APP/Contents/Info.plist"
+      cp ${versionPlist}   "$APP/Contents/version.plist"
+      cp ${./AppIcon.icns} "$APP/Contents/Resources/AppIcon.icns"
+      echo "APPL????"  > "$APP/Contents/PkgInfo"
+      cat << EOF > "$APP/Contents/MacOS/BillsEmacs"
+      #!${pkgs.stdenvNoCC.shell}
+      export EMACSLOADPATH="${loadPath}"
+      exec ${wpcarrosEmacs}/bin/emacs \
+        --debug-init \
+        --no-init-file \
+        --no-site-file \
+        --no-site-lisp \
+        --load ${./.emacs.d/init.el}
+      EOF
+      chmod +x "$APP/Contents/MacOS/BillsEmacs"
+      runHook postInstall
+    '';
+    meta.platforms = [ "aarch64-darwin" ];
+  };
 
   # Script that asserts my Emacs can initialize without warnings or errors.
   check = runCommand "check-emacs" { } ''
@@ -209,4 +259,6 @@ depot.nix.readTree.drvTargets {
       ${./.emacs.d/init.el} && \
     touch $out
   '';
+
+  meta.ci.targets = [ "check" ];
 }