home/modules/baremacs:init
move emacs to home-manager
This commit is contained in:
164
home/modules/baremacs.nix
Normal file
164
home/modules/baremacs.nix
Normal file
@@ -0,0 +1,164 @@
|
||||
#modified version of home-manager emacs service module for personal use
|
||||
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.services.baremacs;
|
||||
emacsCfg = config.programs.emacs;
|
||||
emacsBinPath = "${cfg.package}/bin";
|
||||
|
||||
# Match the default socket path for the Emacs version so emacsclient continues
|
||||
# to work without wrapping it.
|
||||
socketDir = "%t/emacs";
|
||||
socketPath = "${socketDir}/server";
|
||||
|
||||
in
|
||||
{
|
||||
options.services.baremacs = {
|
||||
enable = mkEnableOption "the Emacs daemon";
|
||||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = pkgs.emacs;
|
||||
defaultText = literalExpression ''
|
||||
pkgs.emacs
|
||||
'';
|
||||
description = "The Emacs package to use.";
|
||||
};
|
||||
|
||||
socketActivation = {
|
||||
enable = mkEnableOption "systemd socket activation for the Emacs service";
|
||||
};
|
||||
|
||||
defaultEditor = {
|
||||
enable = mkOption rec {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
example = !default;
|
||||
description = "Whether to change the EDITOR environment variable or not";
|
||||
};
|
||||
editor = mkOption rec {
|
||||
type = types.enum [ "emacs" "emacsclient" ];
|
||||
default = null;
|
||||
example = "emacsclient";
|
||||
description = "Whether to change the EDITOR environment variable or not";
|
||||
};
|
||||
};
|
||||
|
||||
copyConfigFiles = {
|
||||
enable = mkOption rec {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
example = !default;
|
||||
description = "Whether to copy the config files to ~/.emacs.d or not";
|
||||
};
|
||||
files = mkOption rec {
|
||||
type = types.attrsOf types.path;
|
||||
default = { };
|
||||
example = { "init.el" = ./init.el; };
|
||||
description = "What files to copy under what name";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable (mkMerge [
|
||||
{
|
||||
assertions = [
|
||||
(lib.hm.assertions.assertPlatform "services.emacs" pkgs
|
||||
lib.platforms.linux)
|
||||
{
|
||||
assertion = cfg.defaultEditor.enable -> cfg.defaultEditor.editor != null;
|
||||
message = ''
|
||||
services.baremacs.defaultEditor.enable requires services.baremacs.defaultEditor.editor to be set
|
||||
'';
|
||||
}
|
||||
];
|
||||
|
||||
systemd.user.services.emacs = {
|
||||
Unit = {
|
||||
Description = "Emacs text editor";
|
||||
Documentation =
|
||||
"info:emacs man:emacs(1) https://gnu.org/software/emacs/";
|
||||
|
||||
# Avoid killing the Emacs session, which may be full of
|
||||
# unsaved buffers.
|
||||
X-RestartIfChanged = false;
|
||||
} // optionalAttrs (cfg.socketActivation.enable) {
|
||||
# Emacs deletes its socket when shutting down, which systemd doesn't
|
||||
# handle, resulting in a server without a socket.
|
||||
# See https://github.com/nix-community/home-manager/issues/2018
|
||||
RefuseManualStart = true;
|
||||
};
|
||||
|
||||
Service = {
|
||||
Type = "notify";
|
||||
|
||||
# We wrap ExecStart in a login shell so Emacs starts with the user's
|
||||
# environment, most importantly $PATH and $NIX_PROFILES. It may be
|
||||
# worth investigating a more targeted approach for user services to
|
||||
# iport the user environment.
|
||||
ExecStart = ''
|
||||
${pkgs.runtimeShell} -l -c "${emacsBinPath}/emacs --fg-daemon${
|
||||
# In case the user sets 'server-directory' or 'server-name' in
|
||||
# their Emacs config, we want to specify the socket path explicitly
|
||||
# so launching 'emacs.service' manually doesn't break emacsclient
|
||||
# when using socket activation.
|
||||
optionalString cfg.socketActivation.enable
|
||||
"=${escapeShellArg socketPath}"
|
||||
}"'';
|
||||
|
||||
# Emacs will exit with status 15 after having received SIGTERM, which
|
||||
# is the default "KillSignal" value systemd uses to stop services.
|
||||
SuccessExitStatus = 15;
|
||||
|
||||
Restart = "on-failure";
|
||||
} // optionalAttrs (cfg.socketActivation.enable) {
|
||||
# Use read-only directory permissions to prevent emacs from
|
||||
# deleting systemd's socket file before exiting.
|
||||
ExecStartPost =
|
||||
"${pkgs.coreutils}/bin/chmod --changes -w ${socketDir}";
|
||||
ExecStopPost =
|
||||
"${pkgs.coreutils}/bin/chmod --changes +w ${socketDir}";
|
||||
};
|
||||
} // optionalAttrs (!cfg.socketActivation.enable) {
|
||||
Install = { WantedBy = [ "default.target" ]; };
|
||||
};
|
||||
|
||||
home = {
|
||||
sessionVariables = mkIf cfg.defaultEditor.enable {
|
||||
EDITOR = let editor = cfg.defaultEditor.editor; in
|
||||
getBin (pkgs.writeShellScript "editor" ''
|
||||
exec ${
|
||||
getBin cfg.package
|
||||
}/bin/'' + editor + head (optional (editor == "emacsclient") '' "''${@:---create-frame}"''));
|
||||
};
|
||||
|
||||
file = mkIf cfg.copyConfigFiles.enable
|
||||
(mapAttrs'
|
||||
(n: v:
|
||||
attrsets.nameValuePair (".emacs.d/" + n) { source = v; })
|
||||
cfg.copyConfigFiles.files);
|
||||
};
|
||||
}
|
||||
|
||||
(mkIf cfg.socketActivation.enable {
|
||||
systemd.user.sockets.emacs = {
|
||||
Unit = {
|
||||
Description = "Emacs text editor";
|
||||
Documentation =
|
||||
"info:emacs man:emacs(1) https://gnu.org/software/emacs/";
|
||||
};
|
||||
|
||||
Socket = {
|
||||
ListenStream = socketPath;
|
||||
FileDescriptorName = "server";
|
||||
SocketMode = "0600";
|
||||
DirectoryMode = "0700";
|
||||
};
|
||||
Install = { WantedBy = [ "sockets.target" ]; };
|
||||
};
|
||||
})
|
||||
]);
|
||||
}
|
@@ -1 +1 @@
|
||||
../../../modules/emacs/init.el
|
||||
../../../../overlays/emacs/init.el
|
@@ -1,38 +1,50 @@
|
||||
{config, pkgs, ...}:
|
||||
{ config, pkgs, ... }:
|
||||
let
|
||||
home = config.home.homeDirectory;
|
||||
in
|
||||
{
|
||||
services = {
|
||||
picom = {
|
||||
experimentalBackends = true;
|
||||
{
|
||||
services = {
|
||||
baremacs = {
|
||||
enable = true;
|
||||
package = pkgs.mymacs;
|
||||
defaultEditor = {
|
||||
enable = true;
|
||||
shadow = true;
|
||||
shadowOffsets = [ (6) (6) ];
|
||||
shadowExclude = [
|
||||
"! name~=''"
|
||||
"window_type = 'dock'"
|
||||
"name = 'Dunst'"
|
||||
"_NET_WM_STATE@:32a *= '_NET_WM_STATE_HIDDEN'"
|
||||
];
|
||||
blur = true;
|
||||
blurExclude = [
|
||||
"window_type = 'dock'"
|
||||
"window_type = 'desktop'"
|
||||
"class_g = 'dwm'"
|
||||
];
|
||||
inactiveOpacity = "0.92";
|
||||
activeOpacity = "0.97";
|
||||
fade = true;
|
||||
fadeSteps = [ "0.04" "0.04" ];
|
||||
backend = "glx";
|
||||
menuOpacity = "0.8";
|
||||
vSync = false;
|
||||
opacityRule = [
|
||||
"100:class_i='Tauon Music Box'"
|
||||
"100:class_g='firefox'"
|
||||
];
|
||||
extraOptions =
|
||||
editor = "emacsclient";
|
||||
};
|
||||
copyConfigFiles = {
|
||||
enable = true;
|
||||
files = { "init.el" = ./config/emacs/init.el; };
|
||||
};
|
||||
};
|
||||
picom = {
|
||||
experimentalBackends = true;
|
||||
enable = true;
|
||||
shadow = true;
|
||||
shadowOffsets = [ (6) (6) ];
|
||||
shadowExclude = [
|
||||
"! name~=''"
|
||||
"window_type = 'dock'"
|
||||
"name = 'Dunst'"
|
||||
"_NET_WM_STATE@:32a *= '_NET_WM_STATE_HIDDEN'"
|
||||
];
|
||||
blur = true;
|
||||
blurExclude = [
|
||||
"window_type = 'dock'"
|
||||
"window_type = 'desktop'"
|
||||
"class_g = 'dwm'"
|
||||
];
|
||||
inactiveOpacity = "0.92";
|
||||
activeOpacity = "0.97";
|
||||
fade = true;
|
||||
fadeSteps = [ "0.04" "0.04" ];
|
||||
backend = "glx";
|
||||
menuOpacity = "0.8";
|
||||
vSync = false;
|
||||
opacityRule = [
|
||||
"100:class_i='Tauon Music Box'"
|
||||
"100:class_g='firefox'"
|
||||
];
|
||||
extraOptions =
|
||||
''
|
||||
shadow-radius = 8;
|
||||
inactive-opacity-override = true;
|
||||
@@ -42,60 +54,60 @@ in
|
||||
detect-rounded-corners = true;
|
||||
detect-client-opacity = true;
|
||||
'';
|
||||
};
|
||||
sxhkd = {
|
||||
enable = false;
|
||||
extraConfig = builtins.readFile ./config/sxhkd/sxhkdrc;
|
||||
};
|
||||
};
|
||||
sxhkd = {
|
||||
enable = false;
|
||||
extraConfig = builtins.readFile ./config/sxhkd/sxhkdrc;
|
||||
};
|
||||
|
||||
mpd = {
|
||||
enable = true;
|
||||
musicDirectory = "${config.home.homeDirectory}/Music";
|
||||
dbFile = "${config.home.homeDirectory}/.config/mpd/database";
|
||||
dataDir = "${config.home.homeDirectory}/.config/mpd";
|
||||
network = {
|
||||
startWhenNeeded = true;
|
||||
listenAddress = "any";
|
||||
port = 6600;
|
||||
};
|
||||
extraConfig = ''
|
||||
log_file "~/.config/mpd/log"
|
||||
pid_file "~/.config/mpd/pid"
|
||||
bind_to_address "0.0.0.0"
|
||||
bind_to_address "~/.config/mpd/socket"
|
||||
restore_paused "yes"
|
||||
input {
|
||||
plugin "curl"
|
||||
}
|
||||
audio_output {
|
||||
type "pulse"
|
||||
name "pulse audio"
|
||||
}
|
||||
audio_output {
|
||||
encoder "vorbis"
|
||||
type "httpd"
|
||||
quality "9"
|
||||
name "Vorbis Stream"
|
||||
port "8000"
|
||||
max_clients "4"
|
||||
}
|
||||
filesystem_charset "UTF-8"
|
||||
'';
|
||||
mpd = {
|
||||
enable = true;
|
||||
musicDirectory = "${config.home.homeDirectory}/Music";
|
||||
dbFile = "${config.home.homeDirectory}/.config/mpd/database";
|
||||
dataDir = "${config.home.homeDirectory}/.config/mpd";
|
||||
network = {
|
||||
startWhenNeeded = true;
|
||||
listenAddress = "any";
|
||||
port = 6600;
|
||||
};
|
||||
stalonetray = {
|
||||
enable = true;
|
||||
config = {
|
||||
geometry = "1x1-0";
|
||||
max_geometry = "10x0";
|
||||
window_type = "dock";
|
||||
sticky = true;
|
||||
icon_size = 23;
|
||||
background = "#1d2021";
|
||||
icon_gravity = "E";
|
||||
grow_gravity = "E";
|
||||
kludges = "force_icons_size";
|
||||
window_layer = "top";
|
||||
};
|
||||
extraConfig = ''
|
||||
log_file "~/.config/mpd/log"
|
||||
pid_file "~/.config/mpd/pid"
|
||||
bind_to_address "0.0.0.0"
|
||||
bind_to_address "~/.config/mpd/socket"
|
||||
restore_paused "yes"
|
||||
input {
|
||||
plugin "curl"
|
||||
}
|
||||
audio_output {
|
||||
type "pulse"
|
||||
name "pulse audio"
|
||||
}
|
||||
audio_output {
|
||||
encoder "vorbis"
|
||||
type "httpd"
|
||||
quality "9"
|
||||
name "Vorbis Stream"
|
||||
port "8000"
|
||||
max_clients "4"
|
||||
}
|
||||
filesystem_charset "UTF-8"
|
||||
'';
|
||||
};
|
||||
stalonetray = {
|
||||
enable = true;
|
||||
config = {
|
||||
geometry = "1x1-0";
|
||||
max_geometry = "10x0";
|
||||
window_type = "dock";
|
||||
sticky = true;
|
||||
icon_size = 23;
|
||||
background = "#1d2021";
|
||||
icon_gravity = "E";
|
||||
grow_gravity = "E";
|
||||
kludges = "force_icons_size";
|
||||
window_layer = "top";
|
||||
};
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user