Skip to content

Commit 51a3ff9

Browse files
committed
Add a hacky but working liftTyped instance
1 parent 1b517a4 commit 51a3ff9

File tree

2 files changed

+41
-33
lines changed

2 files changed

+41
-33
lines changed

src/Nix/Builtins.hs

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -168,39 +168,7 @@ builtinsList = sequence
168168
, add0 Normal "currentSystem" currentSystem
169169
, add0 Normal "currentTime" currentTime_
170170
, add2 Normal "deepSeq" deepSeq
171-
172-
-- This is compiled in so that we only parse and evaluate it once, at
173-
-- compile-time.
174-
, add0 TopLevel "derivation" $(do
175-
let Success expr = parseNixText [text|
176-
drvAttrs @ { outputs ? [ "out" ], ... }:
177-
178-
let
179-
180-
strict = derivationStrict drvAttrs;
181-
182-
commonAttrs = drvAttrs
183-
// (builtins.listToAttrs outputsList)
184-
// { all = map (x: x.value) outputsList;
185-
inherit drvAttrs;
186-
};
187-
188-
outputToAttrListElement = outputName:
189-
{ name = outputName;
190-
value = commonAttrs // {
191-
outPath = builtins.getAttr outputName strict;
192-
drvPath = strict.drvPath;
193-
type = "derivation";
194-
inherit outputName;
195-
};
196-
};
197-
198-
outputsList = map outputToAttrListElement outputs;
199-
200-
in (builtins.head outputsList).value|]
201-
[| foldFix Eval.eval expr |]
202-
)
203-
171+
, add0 TopLevel "derivation" derivation
204172
, add TopLevel "derivationStrict" derivationStrict_
205173
, add TopLevel "dirOf" dirOf
206174
, add2 Normal "div" div_
@@ -306,6 +274,40 @@ builtinsList = sequence
306274

307275
-- Primops
308276

277+
derivation
278+
:: forall e t f m. (MonadNix e t f m, Scoped (NValue t f m) m)
279+
=> m (NValue t f m)
280+
derivation = foldFix Eval.eval $$(do
281+
-- This is compiled in so that we only parse it once at compile-time.
282+
let Success expr = parseNixText [text|
283+
drvAttrs @ { outputs ? [ "out" ], ... }:
284+
285+
let
286+
287+
strict = derivationStrict drvAttrs;
288+
289+
commonAttrs = drvAttrs
290+
// (builtins.listToAttrs outputsList)
291+
// { all = map (x: x.value) outputsList;
292+
inherit drvAttrs;
293+
};
294+
295+
outputToAttrListElement = outputName:
296+
{ name = outputName;
297+
value = commonAttrs // {
298+
outPath = builtins.getAttr outputName strict;
299+
drvPath = strict.drvPath;
300+
type = "derivation";
301+
inherit outputName;
302+
};
303+
};
304+
305+
outputsList = map outputToAttrListElement outputs;
306+
307+
in (builtins.head outputsList).value|]
308+
[|| expr ||]
309+
)
310+
309311
foldNixPath
310312
:: forall e t f m r
311313
. MonadNix e t f m

src/Nix/Expr/Types.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ instance Lift (Fix NExprF) where
182182
Just HRefl -> Just [| pack $(liftString $ unpack b) |]
183183
Nothing -> Nothing
184184

185+
#if MIN_VERSION_template_haskell(2,17,0)
186+
liftTyped = unsafeCodeCoerce . lift
187+
#elif MIN_VERSION_template_haskell(2,16,0)
188+
liftTyped = unsafeTExpCoerce . lift
189+
#endif
190+
185191
-- | The monomorphic expression type is a fixed point of the polymorphic one.
186192
type NExpr = Fix NExprF
187193

0 commit comments

Comments
 (0)