Skip to content

Instantly share code, notes, and snippets.

@DamienCassou
Created May 29, 2016 15:52
Show Gist options
  • Save DamienCassou/0ca0a0b116acbdd77b6256c0b303bdc5 to your computer and use it in GitHub Desktop.
Save DamienCassou/0ca0a0b116acbdd77b6256c0b303bdc5 to your computer and use it in GitHub Desktop.
systemd user service for Emacs daemon defined in NixOS
{
systemd.user.services.emacs = {
description = "Emacs: the extensible, self-documenting text editor";
serviceConfig = {
Type = "forking";
# ExecStart = "${bigEmacs}/bin/emacs --daemon";
# Running Emacs this way ensures environment variable are accessible:
ExecStart = "${pkgs.bash}/bin/bash -c 'source ${config.system.build.setEnvironment}; exec ${bigEmacs}/bin/emacs --daemon'";
ExecStop = "${bigEmacs}/bin/emacsclient --eval (kill-emacs)";
Restart = "always";
};
environment = {
# Give Emacs a chance to use ssh-agent and gpg-agent
SSH_AUTH_SOCK = "%h/.gnupg/S.gpg-agent.ssh";
# Some variables for GTK applications I will launch from Emacs
# (typically evince and the gnome-terminal)
GTK_DATA_PREFIX = config.system.path;
GTK_PATH = "${config.system.path}/lib/gtk-3.0:${config.system.path}/lib/gtk-2.0";
GDK_CORE_DEVICE_EVENTS = "1"; # https://github.com/stumpwm/stumpwm/wiki/FAQ#my-mouse-wheel-doesnt-work-with-gtk3-applications
# Aspell will find its dictionaries
ASPELL_CONF = "dict-dir /home/cassou/.nix-profile/lib/aspell";
# Locate will find its database
LOCATE_PATH = "/var/cache/locatedb";
# the last ':' is important for Emacs. See Emacs variable
# `Info-directory-list'.
INFOPATH = "%h/.nix-profile/info:%h/.nix-profile/share/info:/nix/var/nix/profiles/default/info:/nix/var/nix/profiles/default/share/info:/run/current-system/sw/info:/run/current-system/sw/share/info:";
# Scripts won't try to download and use the pharo vm
PHARO_VM = "%h/.nix-profile/bin/pharo-vm-nox";
TERMINFO_DIRS = "/run/current-system/sw/share/terminfo";
# NIX environment
NIX_CONF_DIR = "/etc/nix";
NIX_OTHER_STORES = "/run/nix/remote-stores/*/nix";
NIX_PATH = "nixpkgs=%h/nixpkgs:nixos=%h/nixpkgs/nixos:nixos-config=/etc/nixos/configuration.nix";
NIX_PROFILES = "${pkgs.lib.concatStringsSep " " config.environment.profiles}";
NIX_REMOTE = "daemon";
NIX_USER_PROFILE_DIR = "/nix/var/nix/profiles/per-user/%u";
};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment