1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-27 05:29:46 +01:00

emacs: add extraConfig option

This commit is contained in:
midchildan 2021-01-30 01:43:49 +09:00 committed by Robert Helgesson
parent 29ea37374d
commit b0d769691c
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
5 changed files with 59 additions and 3 deletions

View file

@ -20,4 +20,4 @@ jobs:
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}' signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
- run: ./format -c - run: ./format -c
- run: nix-shell . -A install - run: nix-shell . -A install
- run: nix-shell --pure tests -A run.all - run: nix-shell --arg enableBig false --pure tests -A run.all

View file

@ -13,6 +13,12 @@ let
emacsWithPackages = emacsPackages.emacsWithPackages; emacsWithPackages = emacsPackages.emacsWithPackages;
createConfPackage = epkgs:
epkgs.trivialBuild {
pname = "default";
src = pkgs.writeText "default.el" cfg.extraConfig;
};
in { in {
meta.maintainers = [ maintainers.rycee ]; meta.maintainers = [ maintainers.rycee ];
@ -28,6 +34,23 @@ in {
description = "The Emacs package to use."; description = "The Emacs package to use.";
}; };
# NOTE: The config is placed in default.el instead of ~/.emacs.d so that
# it won't conflict with Emacs configuration frameworks. Users of these
# frameworks would still benefit from this option as it would easily allow
# them to have Nix-computed paths in their configuration.
extraConfig = mkOption {
type = types.lines;
default = "";
example = ''
(setq standard-indent 2)
'';
description = ''
Configuration to include in the Emacs default init file. See
<link xlink:href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Init-File.html"/>
for more.
'';
};
extraPackages = mkOption { extraPackages = mkOption {
default = self: [ ]; default = self: [ ];
type = hm.types.selectorFunction; type = hm.types.selectorFunction;
@ -68,6 +91,10 @@ in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
home.packages = [ cfg.finalPackage ]; home.packages = [ cfg.finalPackage ];
programs.emacs.finalPackage = emacsWithPackages cfg.extraPackages; programs.emacs = {
finalPackage = emacsWithPackages cfg.extraPackages;
extraPackages = epkgs:
optional (cfg.extraConfig != "") (createConfPackage epkgs);
};
}; };
} }

View file

@ -1,4 +1,4 @@
{ pkgs ? import <nixpkgs> {} }: { pkgs ? import <nixpkgs> {}, enableBig ? true }:
let let
@ -135,5 +135,7 @@ import nmt {
./modules/services/wlsunset ./modules/services/wlsunset
./modules/systemd ./modules/systemd
./modules/targets-linux ./modules/targets-linux
] ++ lib.optionals enableBig [
./modules/programs/emacs
]); ]);
} }

View file

@ -0,0 +1 @@
{ emacs-extra-config = ./extra-config.nix; }

View file

@ -0,0 +1,26 @@
{ config, lib, pkgs, ... }:
let
testScript = pkgs.writeText "test.el" ''
;; Emacs won't automatically load default.el when --script is specified
(load "default")
(kill-emacs (if (eq hm 'home-manager) 0 1))
'';
emacsBin = "${config.programs.emacs.finalPackage}/bin/emacs";
in {
programs.emacs = {
enable = true;
package = pkgs.emacs-nox;
extraConfig = "(setq hm 'home-manager)";
};
# running emacs with --script would enable headless mode
nmt.script = ''
if ! ${emacsBin} --script ${testScript}; then
fail "Failed to load default.el."
fi
'';
}