forked from vlaci/nix-straight.el
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlibstraight.nix
90 lines (82 loc) · 3 KB
/
libstraight.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
{ abortOnNotFound ? true,
lib, stdenv, epkgs, emacs, writeScript }:
let
inherit (builtins) filter trace;
inherit (lib) concatMapStringsSep escapeShellArgs importJSON flatten unique optionalString warn;
expandDependencies = packages:
let
withDeps = p:
map (x:
if x == null then [ ] else
[ x ] ++ withDeps x.propagatedBuildInputs
) (flatten p);
in (unique (filter (d: d ? ename) (flatten (withDeps packages))));
install = repo: packages:
let
installPkg = repo: pkg: (''
REPO=${repo}
psrc=(${pkg}/share/emacs/*/*/${pkg.ename}*)
if [[ ! -d $psrc ]]; then
elpa_path=(${pkg}/share/emacs/site-lisp/elpa/*)
if [[ -d $elpa_path ]]; then
ln -snf $elpa_path $REPO/${pkg.ename}
else
ln -snf ${pkg}/share/emacs/site-lisp $REPO/${pkg.ename}
fi
else
ln -snf $psrc $REPO/${pkg.ename}
fi
${optionalString ((pkg.src ? meta) && (pkg.src.meta ? homepage)) ''
if [[ ! -d $REPO/${baseNameOf pkg.src.meta.homepage} ]]; then
ln -snf $psrc $REPO/${baseNameOf pkg.src.meta.homepage}
fi
''}
'');
in writeScript "install-repo" ''
mkdir -p ${repo}
${(concatMapStringsSep "\n" (installPkg repo) (expandDependencies packages))}
'';
parsePackagesJSON = json:
let
list = importJSON json;
in map (x:
if epkgs ? "${x}" then epkgs.${x}
else if abortOnNotFound then abort "Package not available: ${x}"
else (warn "Package not available: ${x}") null) list;
packagesJSON = { emacsInitFile, emacsLoadFiles, emacsArgs }: stdenv.mkDerivation {
name = "emacs-straight-packages.json";
buildInputs = [ emacs ];
buildPhase = ":";
installPhase = ''
runHook preInstall
emacs -q \
--batch \
--directory=${epkgs.straight}/share/emacs/site-lisp \
--load=${./setup.el} \
${concatMapStringsSep "\n" (f: "--load=${f}") emacsLoadFiles} \
--eval="(nix-straight-get-used-packages \"${emacsInitFile}\" \"$out\")" \
${escapeShellArgs emacsArgs}
runHook postInstall
'';
};
emacsEnv = { emacsInitFile, emacsLoadFiles, emacsArgs }: { packages, straightDir }: stdenv.mkDerivation {
name = "straight-emacs-env";
buildPhase = ":";
buildInputs = [ emacs ];
installPhase = ''
runHook preInstall
mkdir -p $out
${(install "${straightDir}/repos" packages)}
emacs -q \
--batch \
--directory=${epkgs.straight}/share/emacs/site-lisp \
--load=${./setup.el} \
${concatMapStringsSep "\n" (f: "--load=${f}") emacsLoadFiles} \
--eval="(nix-straight-build-packages \"${emacsInitFile}\")" ${escapeShellArgs emacsArgs} \
|| (cat $out/logs/cli.doom.*.error 1>&2 && false) # print a proper stacktrace if things fail
runHook postInstall
'';
};
in {
inherit install parsePackagesJSON packagesJSON emacsEnv;
}