forked from nix-community/emacs-overlay
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathelisp.nix
90 lines (86 loc) · 2.67 KB
/
elisp.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
Parse an emacs lisp configuration file to derive packages from
use-package declarations.
*/
{ pkgs }:
let
parse = pkgs.callPackage ./parse.nix { };
inherit (pkgs) lib;
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 ? false,
# emulate `#+PROPERTY: header-args:emacs-lisp :tangle yes`
alwaysTangle ? false,
extraEmacsPackages ? epkgs: [ ],
package ? pkgs.emacs-unstable,
override ? (self: super: { }),
}:
let
configType = config: if (lib.strings.isStorePath config) then "path" else (builtins.typeOf config);
isOrgModeFile =
let
ext = lib.last (builtins.split "\\." (builtins.toString config));
type = configType config;
in
type == "path" && ext == "org";
configText =
let
type = configType config;
in
if type == "string" then
config
else if type == "path" then
builtins.readFile config
else
throw "Unsupported type for config: \"${type}\"";
packages = parse.parsePackagesFromUsePackage {
inherit
configText
isOrgModeFile
alwaysTangle
alwaysEnsure
;
};
emacsPackages = (pkgs.emacsPackagesFor package).overrideScope (
self: super:
# for backward compatibility: override was a function with one parameter
if builtins.isFunction (override super) then override self super else override super
);
emacsWithPackages = emacsPackages.emacsWithPackages;
mkPackageError =
name: throw "Emacs package ${name}, declared wanted with use-package, not found." null;
in
emacsWithPackages (
epkgs:
let
usePkgs = map (name: epkgs.${name} or (mkPackageError name)) packages;
extraPkgs = extraEmacsPackages epkgs;
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";
src =
if defaultInitFile == true then
pkgs.writeText defaultInitFileName configText
else if defaultInitFile.name == defaultInitFileName then
defaultInitFile
else
throw "name of defaultInitFile must be ${defaultInitFileName}";
version = "0.1.0";
packageRequires = usePkgs ++ extraPkgs;
};
in
usePkgs ++ extraPkgs ++ [ defaultInitFilePkg ]
)