@@ -885,29 +885,21 @@ builtinsBuiltinNix
885885 => m (NValue t f m )
886886builtinsBuiltinNix = throwError $ ErrorCall " HNix does not provide builtins.builtins at the moment. Using builtins directly should be preferred"
887887
888- attrGetOr'
888+ -- a safer version of `attrsetGet`
889+ attrGetOr
889890 :: forall e t f m v a
890891 . (MonadNix e t f m , FromValue v m (NValue t f m ))
891- => AttrSet (NValue t f m )
892- -> VarName
893- -> m a
892+ => a
894893 -> (v -> m a )
894+ -> VarName
895+ -> AttrSet (NValue t f m )
895896 -> m a
896- attrGetOr' attrs n d f =
897+ attrGetOr fallback fun name attrs =
897898 maybe
898- d
899- (f <=< fromValue)
900- (M. lookup n attrs)
899+ ( pure fallback)
900+ (fun <=< fromValue)
901+ (M. lookup name attrs)
901902
902- attrGetOr
903- :: forall e t f m v a
904- . (MonadNix e t f m , FromValue v m (NValue t f m ))
905- => AttrSet (NValue t f m )
906- -> VarName
907- -> a
908- -> (v -> m a )
909- -> m a
910- attrGetOr attrs name fallback = attrGetOr' attrs name (pure fallback)
911903
912904-- NOTE: It is a part of the implementation taken from:
913905-- https://github.com/haskell-nix/hnix/pull/755
@@ -920,8 +912,8 @@ pathNix arg =
920912
921913 -- TODO: Fail on extra args
922914 -- XXX: This is a very common pattern, we could factor it out
923- name <- toText <$> attrGetOr attrs " name " (takeFileName path) (fmap (coerce . toString) . fromStringNoContext)
924- recursive <- attrGetOr attrs " recursive" True pure
915+ name <- toText <$> attrGetOr (takeFileName path) (fmap (coerce . toString) . fromStringNoContext) " name " attrs
916+ recursive <- attrGetOr True pure " recursive" attrs
925917
926918 Right (coerce . toText . coerce @ StorePath @ String -> s) <- addToStore name path recursive False
927919 -- TODO: Ensure that s matches sha256 when not empty
0 commit comments