mirror of
https://github.com/nix-community/home-manager
synced 2024-12-23 10:19:48 +01:00
emacs: add extraConfig option
This commit is contained in:
parent
29ea37374d
commit
b0d769691c
5 changed files with 59 additions and 3 deletions
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
|
@ -20,4 +20,4 @@ jobs:
|
|||
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
|
||||
- run: ./format -c
|
||||
- run: nix-shell . -A install
|
||||
- run: nix-shell --pure tests -A run.all
|
||||
- run: nix-shell --arg enableBig false --pure tests -A run.all
|
||||
|
|
|
@ -13,6 +13,12 @@ let
|
|||
|
||||
emacsWithPackages = emacsPackages.emacsWithPackages;
|
||||
|
||||
createConfPackage = epkgs:
|
||||
epkgs.trivialBuild {
|
||||
pname = "default";
|
||||
src = pkgs.writeText "default.el" cfg.extraConfig;
|
||||
};
|
||||
|
||||
in {
|
||||
meta.maintainers = [ maintainers.rycee ];
|
||||
|
||||
|
@ -28,6 +34,23 @@ in {
|
|||
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 {
|
||||
default = self: [ ];
|
||||
type = hm.types.selectorFunction;
|
||||
|
@ -68,6 +91,10 @@ in {
|
|||
|
||||
config = mkIf cfg.enable {
|
||||
home.packages = [ cfg.finalPackage ];
|
||||
programs.emacs.finalPackage = emacsWithPackages cfg.extraPackages;
|
||||
programs.emacs = {
|
||||
finalPackage = emacsWithPackages cfg.extraPackages;
|
||||
extraPackages = epkgs:
|
||||
optional (cfg.extraConfig != "") (createConfPackage epkgs);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{ pkgs ? import <nixpkgs> {} }:
|
||||
{ pkgs ? import <nixpkgs> {}, enableBig ? true }:
|
||||
|
||||
let
|
||||
|
||||
|
@ -135,5 +135,7 @@ import nmt {
|
|||
./modules/services/wlsunset
|
||||
./modules/systemd
|
||||
./modules/targets-linux
|
||||
] ++ lib.optionals enableBig [
|
||||
./modules/programs/emacs
|
||||
]);
|
||||
}
|
||||
|
|
1
tests/modules/programs/emacs/default.nix
Normal file
1
tests/modules/programs/emacs/default.nix
Normal file
|
@ -0,0 +1 @@
|
|||
{ emacs-extra-config = ./extra-config.nix; }
|
26
tests/modules/programs/emacs/extra-config.nix
Normal file
26
tests/modules/programs/emacs/extra-config.nix
Normal 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
|
||||
'';
|
||||
}
|
Loading…
Reference in a new issue