@@ -1043,7 +1043,7 @@ replaceStringsNix tfrom tto ts =
10431043
10441044 -- 2021-02-18: NOTE: rly?: toStrict . toLazyText
10451045 -- Maybe `text-builder`, `text-show`?
1046- finish ctx output = mkNixString (toStrict $ Builder. toLazyText output) ctx
1046+ finish ctx output = mkNixString ctx (toStrict $ Builder. toLazyText output)
10471047
10481048 replace (key, replacementNS, unprocessedInput) = replaceWithNixBug unprocessedInput updatedOutput
10491049
@@ -1141,7 +1141,7 @@ toFileNix name s =
11411141 storepath = coerce (fromString @ Text ) mres
11421142 sc = StringContext DirectPath storepath
11431143
1144- toValue $ mkNixStringWithSingletonContext storepath sc
1144+ toValue $ mkNixStringWithSingletonContext sc storepath
11451145
11461146toPathNix :: MonadNix e t f m => NValue t f m -> m (NValue t f m )
11471147toPathNix = inHask @ Path id
@@ -1699,15 +1699,12 @@ getRecursiveSizeNix = fmap (mkNVConstant . NInt . fromIntegral) . recursiveSize
16991699
17001700getContextNix
17011701 :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m )
1702- getContextNix v =
1703- do
1704- v' <- demand v
1705- case v' of
1706- (NVStr ns) -> do
1707- let context = getNixLikeContext $ toNixLikeContext $ getContext ns
1708- valued :: AttrSet (NValue t f m ) <- traverseToValue context
1709- pure $ mkNVSet mempty valued
1710- x -> throwError $ ErrorCall $ " Invalid type for builtins.getContext: " <> show x
1702+ getContextNix =
1703+ \ case
1704+ (NVStr ns) ->
1705+ mkNVSet mempty <$> traverseToValue (getNixLikeContext $ toNixLikeContext $ getContext ns)
1706+ x -> throwError $ ErrorCall $ " Invalid type for builtins.getContext: " <> show x
1707+ <=< demand
17111708
17121709appendContextNix
17131710 :: forall e t f m
@@ -1723,62 +1720,63 @@ appendContextNix tx ty =
17231720 case (x, y) of
17241721 (NVStr ns, NVSet _ attrs) ->
17251722 do
1726- newContextValues <- traverse getPathNOuts attrs
1723+ let
1724+ getPathNOuts :: NValue t f m -> m NixLikeContextValue
1725+ getPathNOuts tx =
1726+ do
1727+ x <- demand tx
17271728
1728- toValue $ addContext ns newContextValues
1729+ case x of
1730+ NVSet _ atts ->
1731+ do
1732+ -- TODO: Fail for unexpected keys.
1733+
1734+ let
1735+ getK :: VarName -> m Bool
1736+ getK k =
1737+ maybe
1738+ (pure False )
1739+ (fromValue <=< demand)
1740+ $ M. lookup k atts
1741+
1742+ getOutputs :: m [Text ]
1743+ getOutputs =
1744+ maybe
1745+ stub
1746+ (\ touts ->
1747+ do
1748+ outs <- demand touts
1749+
1750+ case outs of
1751+ NVList vs -> traverse (fmap ignoreContext . fromValue) vs
1752+ _x -> throwError $ ErrorCall $ " Invalid types for context value outputs in builtins.appendContext: " <> show _x
1753+ )
1754+ (M. lookup " outputs" atts)
1755+
1756+ path <- getK " path"
1757+ allOutputs <- getK " allOutputs"
1758+
1759+ NixLikeContextValue path allOutputs <$> getOutputs
1760+
1761+ _x -> throwError $ ErrorCall $ " Invalid types for context value in builtins.appendContext: " <> show _x
1762+ addContext :: HashMap VarName NixLikeContextValue -> NixString
1763+ addContext newContextValues =
1764+ mkNixString
1765+ (fromNixLikeContext $
1766+ NixLikeContext $
1767+ M. unionWith
1768+ (<>)
1769+ newContextValues
1770+ $ getNixLikeContext $
1771+ toNixLikeContext $
1772+ getContext ns
1773+ )
1774+ $ ignoreContext ns
17291775
1730- _xy -> throwError $ ErrorCall $ " Invalid types for builtins.appendContext: " <> show _xy
1776+ toValue . addContext =<< traverse getPathNOuts attrs
17311777
1732- where
1733- getPathNOuts tx =
1734- do
1735- x <- demand tx
1778+ _xy -> throwError $ ErrorCall $ " Invalid types for builtins.appendContext: " <> show _xy
17361779
1737- case x of
1738- NVSet _ attrs->
1739- do
1740- -- TODO: Fail for unexpected keys.
1741-
1742- let
1743- getK k =
1744- maybe
1745- (pure False )
1746- (fromValue <=< demand)
1747- (M. lookup k attrs)
1748-
1749- getOutputs =
1750- maybe
1751- stub
1752- (\ touts ->
1753- do
1754- outs <- demand touts
1755-
1756- case outs of
1757- NVList vs -> traverse (fmap ignoreContext . fromValue) vs
1758- _x -> throwError $ ErrorCall $ " Invalid types for context value outputs in builtins.appendContext: " <> show _x
1759- )
1760- (M. lookup " outputs" attrs)
1761-
1762- path <- getK " path"
1763- allOutputs <- getK " allOutputs"
1764-
1765- NixLikeContextValue path allOutputs <$> getOutputs
1766-
1767- _x -> throwError $ ErrorCall $ " Invalid types for context value in builtins.appendContext: " <> show _x
1768-
1769- addContext ns newContextValues =
1770- mkNixString
1771- (ignoreContext ns)
1772- (fromNixLikeContext $
1773- NixLikeContext $
1774- M. unionWith
1775- (<>)
1776- newContextValues
1777- (getNixLikeContext $
1778- toNixLikeContext $
1779- getContext ns
1780- )
1781- )
17821780
17831781nixVersionNix :: MonadNix e t f m => m (NValue t f m )
17841782nixVersionNix = toValue $ mkNixStringWithoutContext " 2.3"
0 commit comments