Skip to content

Commit 4fd0bbb

Browse files
committed
elisp.nix: add a param to include user config as a default init file
This is good for AOT native compilation of user config. Besides being bool, the value of this new option can also be a derivation produced by pkgs.substituteAll, which avoids IFD comparing to directly setting that derivation to the config param.
1 parent 4d79c6e commit 4fd0bbb

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

elisp.nix

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ let
1212

1313
in
1414
{ config
15+
# bool to use the value of config or a derivation whose name is default.el
16+
, defaultInitFile ? false
1517
# emulate `use-package-always-ensure` behavior (defaulting to false)
1618
, alwaysEnsure ? null
1719
# emulate `#+PROPERTY: header-args:emacs-lisp :tangle yes`
@@ -64,5 +66,27 @@ emacsWithPackages (epkgs:
6466
overridden = override epkgs;
6567
usePkgs = map (name: overridden.${name} or (mkPackageError name)) packages;
6668
extraPkgs = extraEmacsPackages overridden;
69+
defaultInitFilePkg =
70+
if !((builtins.isBool defaultInitFile) || (lib.isDerivation defaultInitFile))
71+
then throw "defaultInitFile must be bool or derivation"
72+
else
73+
if defaultInitFile == false
74+
then null
75+
else
76+
let
77+
# name of the default init file must be default.el according to elisp manual
78+
defaultInitFileName = "default.el";
79+
in
80+
epkgs.trivialBuild {
81+
pname = "default-init-file";
82+
src =
83+
if defaultInitFile == true
84+
then pkgs.writeText defaultInitFileName configText
85+
else
86+
if defaultInitFile.name == defaultInitFileName
87+
then defaultInitFile
88+
else throw "name of defaultInitFile must be ${defaultInitFileName}";
89+
packageRequires = usePkgs;
90+
};
6791
in
68-
usePkgs ++ extraPkgs)
92+
usePkgs ++ extraPkgs ++ [ defaultInitFilePkg ])

0 commit comments

Comments
 (0)