Skip to content

Commit 6dc0bda

Browse files
committed
lib/to-lua: handle derivations as path strings
Fixes #1888
1 parent 34aa3e0 commit 6dc0bda

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

lib/to-lua.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ rec {
141141
value
142142
else if allowRawValues && value ? __raw then
143143
value
144+
else if isDerivation value then
145+
value
144146
else if isList value then
145147
let
146148
needsFiltering = removeNullListEntries || removeEmptyListEntries;
@@ -205,8 +207,8 @@ rec {
205207
builtins.toJSON v
206208
else if isBool v then
207209
boolToString v
208-
else if isPath v then
209-
go indent (toString v)
210+
else if isPath v || isDerivation v then
211+
go indent "${v}"
210212
else if isString v then
211213
# TODO: support lua's escape sequences, literal string, and content-appropriate quote style
212214
# See https://www.lua.org/pil/2.4.html
@@ -217,8 +219,6 @@ rec {
217219
"{ }"
218220
else if isFunction v then
219221
abort "nixvim(toLua): Unexpected function: " + generators.toPretty { } v
220-
else if isDerivation v then
221-
abort "nixvim(toLua): Unexpected derivation: " + generators.toPretty { } v
222222
else if isList v then
223223
"{" + introSpace + concatMapStringsSep ("," + introSpace) (go (indent + " ")) v + outroSpace + "}"
224224
else if isAttrs v then

tests/lib-tests.nix

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ let
4545
];
4646
};
4747

48+
drv = pkgs.writeText "example-derivation" "hello, world!";
49+
4850
results = pkgs.lib.runTests {
4951
testToLuaObject = {
5052
expr = helpers.toLuaObject {
@@ -124,6 +126,23 @@ let
124126
expected = ''"foo\\bar\nbaz"'';
125127
};
126128

129+
testToLuaObjectDerivation = {
130+
expr = helpers.toLuaObject drv;
131+
expected = ''"${drv}"'';
132+
};
133+
134+
testToLuaObjectDerivationNested = {
135+
expr = helpers.toLuaObject {
136+
a = drv;
137+
b = {
138+
c = drv;
139+
};
140+
d = [ drv ];
141+
e = [ { f = drv; } ];
142+
};
143+
expected = ''{ a = "${drv}", b = { c = "${drv}" }, d = { "${drv}" }, e = { { f = "${drv}" } } }'';
144+
};
145+
127146
testToLuaObjectFilters = {
128147
expr = helpers.toLuaObject {
129148
a = null;

0 commit comments

Comments
 (0)