-
Notifications
You must be signed in to change notification settings - Fork 1
/
lua.nix
41 lines (38 loc) · 848 Bytes
/
lua.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
{
stdenv,
lib,
UsingDvorak ? false,
minimal,
...
}: let
luaBooleans = {
InNix = true;
inherit UsingDvorak;
Minimal = minimal;
};
boolToStr = bool:
if bool
then "true"
else "false";
booleanSedCommands =
lib.attrsets.mapAttrsToList
(name: value: ''sed -i "s/\(${name}.*\)\(true\|false\)/\1${boolToStr value}/" init.lua'')
luaBooleans;
# lua as a string
rawLua = builtins.readFile ./init.lua;
# lua in the nix store
nixStoreLua = builtins.toFile "init.lua" rawLua;
in
stdenv.mkDerivation {
name = "configure-lua-init-lua";
src = nixStoreLua;
dontUnpack = true;
buildPhase = ''
cp $src init.lua
# change booleans to match lua values
${builtins.concatStringsSep "\n" booleanSedCommands}
'';
installPhase = ''
mv init.lua $out
'';
}