1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-26 21:19:45 +01:00

emacs: add darwin service

This commit is contained in:
klchen0112 2024-11-22 23:35:22 +08:00 committed by Robert Helgesson
parent 16fe78182e
commit ba9367b5a9
No known key found for this signature in database
GPG key ID: 96E745BD17AA17ED
5 changed files with 65 additions and 9 deletions

View file

@ -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;
};
};
};
})
]);
}

View file

@ -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

View file

@ -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}
'';
}

View file

@ -0,0 +1 @@
{ emacs-service-basic = ./basic.nix; }

View file

@ -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>