Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elisp.nix: add a param to include user config as a default init file #252

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ required in a user's config via =use-package= or =leaf=.
# config = ./emacs.org;
config = ./emacs.el;

# Whether to include your config as a default init file.
# If being bool, the value of config is used.
# Its value can also be a derivation like this if you want to do some
# substitution:
# defaultInitFile = pkgs.substituteAll {
# name = "default.el";
# src = ./emacs.el;
# inherit (config.xdg) configHome dataHome;
# };
defaultInitFile = true;

# Package is optional, defaults to pkgs.emacs
package = pkgs.emacsGit;

Expand Down
26 changes: 25 additions & 1 deletion elisp.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ let

in
{ config
# bool to use the value of config or a derivation whose name is default.el
, defaultInitFile ? false
# emulate `use-package-always-ensure` behavior (defaulting to false)
, alwaysEnsure ? null
# emulate `#+PROPERTY: header-args:emacs-lisp :tangle yes`
Expand Down Expand Up @@ -64,5 +66,27 @@ emacsWithPackages (epkgs:
overridden = override epkgs;
usePkgs = map (name: overridden.${name} or (mkPackageError name)) packages;
extraPkgs = extraEmacsPackages overridden;
defaultInitFilePkg =
if !((builtins.isBool defaultInitFile) || (lib.isDerivation defaultInitFile))
then throw "defaultInitFile must be bool or derivation"
else
if defaultInitFile == false
then null
else
let
# name of the default init file must be default.el according to elisp manual
defaultInitFileName = "default.el";
in
epkgs.trivialBuild {
pname = "default-init-file";
src =
if defaultInitFile == true
then pkgs.writeText defaultInitFileName configText
else
if defaultInitFile.name == defaultInitFileName
then defaultInitFile
else throw "name of defaultInitFile must be ${defaultInitFileName}";
packageRequires = usePkgs;
};
in
usePkgs ++ extraPkgs)
usePkgs ++ extraPkgs ++ [ defaultInitFilePkg ])