diff --git a/modules/services/emacs.nix b/modules/services/emacs.nix index d319abf01..e280b3219 100644 --- a/modules/services/emacs.nix +++ b/modules/services/emacs.nix @@ -41,7 +41,6 @@ let # to work without wrapping it. socketDir = "%t/emacs"; socketPath = "${socketDir}/server"; - in { meta.maintainers = [ maintainers.tadfisher ]; @@ -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"; @@ -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"; @@ -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; + }; + }; + }; + }) ]); } diff --git a/tests/default.nix b/tests/default.nix index 2eaaaa436..8fac3280a 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -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 diff --git a/tests/modules/services/emacs-darwin/basic.nix b/tests/modules/services/emacs-darwin/basic.nix new file mode 100644 index 000000000..dac7c2d63 --- /dev/null +++ b/tests/modules/services/emacs-darwin/basic.nix @@ -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} + ''; +} diff --git a/tests/modules/services/emacs-darwin/default.nix b/tests/modules/services/emacs-darwin/default.nix new file mode 100644 index 000000000..11de5fc79 --- /dev/null +++ b/tests/modules/services/emacs-darwin/default.nix @@ -0,0 +1 @@ +{ emacs-service-basic = ./basic.nix; } diff --git a/tests/modules/services/emacs-darwin/expected-agent.plist b/tests/modules/services/emacs-darwin/expected-agent.plist new file mode 100644 index 000000000..819457582 --- /dev/null +++ b/tests/modules/services/emacs-darwin/expected-agent.plist @@ -0,0 +1,22 @@ + + + + + KeepAlive + + Crashed + + SuccessfulExit + + + Label + org.nix-community.home.emacs + ProgramArguments + + @emacs@/bin/emacs + --fg-daemon + + RunAtLoad + + + \ No newline at end of file