Skip to content

Commit

Permalink
emacs: add darwin service
Browse files Browse the repository at this point in the history
  • Loading branch information
klchen0112 authored and rycee committed Nov 23, 2024
1 parent 16fe781 commit ba9367b
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 9 deletions.
27 changes: 18 additions & 9 deletions modules/services/emacs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ let
# to work without wrapping it.
socketDir = "%t/emacs";
socketPath = "${socketDir}/server";

in {
meta.maintainers = [ maintainers.tadfisher ];

Expand Down Expand Up @@ -112,12 +111,7 @@ in {
};

config = mkIf cfg.enable (mkMerge [
{
assertions = [
(lib.hm.assertions.assertPlatform "services.emacs" pkgs
lib.platforms.linux)
];

(mkIf pkgs.stdenv.isLinux {
systemd.user.services.emacs = {
Unit = {
Description = "Emacs text editor";
Expand Down Expand Up @@ -190,9 +184,9 @@ in {
}/bin/emacsclient "''${@:---create-frame}"'');
};
};
}
})

(mkIf cfg.socketActivation.enable {
(mkIf (cfg.socketActivation.enable && pkgs.stdenv.isLinux) {
systemd.user.sockets.emacs = {
Unit = {
Description = "Emacs text editor";
Expand Down Expand Up @@ -222,5 +216,20 @@ in {
};
};
})

(mkIf pkgs.stdenv.isDarwin {
launchd.agents.emacs = {
enable = true;
config = {
ProgramArguments = [ "${cfg.package}/bin/emacs" "--fg-daemon" ]
++ cfg.extraOptions;
RunAtLoad = true;
KeepAlive = {
Crashed = true;
SuccessfulExit = false;
};
};
};
})
]);
}
1 change: 1 addition & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ in import nmtSrc {
./modules/xresources
] ++ lib.optionals isDarwin [
./modules/launchd
./modules/services/emacs-darwin
./modules/services/espanso-darwin
./modules/services/git-sync-darwin
./modules/services/imapnotify-darwin
Expand Down
23 changes: 23 additions & 0 deletions tests/modules/services/emacs-darwin/basic.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{ lib, pkgs, ... }:

{
nixpkgs.overlays = [
(self: super: rec {
emacs = pkgs.writeShellScriptBin "dummy-emacs-28.0.5" "" // {
outPath = "@emacs@";
};
emacsPackagesFor = _:
lib.makeScope super.newScope (_: { emacsWithPackages = _: emacs; });
})
];

services.emacs = { enable = true; };

nmt.script = ''
serviceFile=LaunchAgents/org.nix-community.home.emacs.plist
assertFileExists "$serviceFile"
assertFileContent "$serviceFile" ${./expected-agent.plist}
'';
}
1 change: 1 addition & 0 deletions tests/modules/services/emacs-darwin/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ emacs-service-basic = ./basic.nix; }
22 changes: 22 additions & 0 deletions tests/modules/services/emacs-darwin/expected-agent.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<dict>
<key>Crashed</key>
<true/>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>Label</key>
<string>org.nix-community.home.emacs</string>
<key>ProgramArguments</key>
<array>
<string>@emacs@/bin/emacs</string>
<string>--fg-daemon</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>

0 comments on commit ba9367b

Please sign in to comment.