diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8936bb1a1..1e0747a04 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/modules/programs/emacs.nix b/modules/programs/emacs.nix index b785f7135..bd68f68ab 100644 --- a/modules/programs/emacs.nix +++ b/modules/programs/emacs.nix @@ -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 + + 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); + }; }; } diff --git a/tests/default.nix b/tests/default.nix index e71e1fd8a..31ef62503 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -1,4 +1,4 @@ -{ pkgs ? import {} }: +{ pkgs ? import {}, enableBig ? true }: let @@ -135,5 +135,7 @@ import nmt { ./modules/services/wlsunset ./modules/systemd ./modules/targets-linux + ] ++ lib.optionals enableBig [ + ./modules/programs/emacs ]); } diff --git a/tests/modules/programs/emacs/default.nix b/tests/modules/programs/emacs/default.nix new file mode 100644 index 000000000..b1b0c566d --- /dev/null +++ b/tests/modules/programs/emacs/default.nix @@ -0,0 +1 @@ +{ emacs-extra-config = ./extra-config.nix; } diff --git a/tests/modules/programs/emacs/extra-config.nix b/tests/modules/programs/emacs/extra-config.nix new file mode 100644 index 000000000..67778c351 --- /dev/null +++ b/tests/modules/programs/emacs/extra-config.nix @@ -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 + ''; +}