Skip to content

Commit

Permalink
add builtins.hashfile
Browse files Browse the repository at this point in the history
  • Loading branch information
soulomoon authored and Anton-Latukha committed Jan 6, 2022
1 parent 4f94e33 commit 8e64e98
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/Nix/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,18 @@ hashStringNix nsAlgo ns =
mkHash s = hash $ encodeUtf8 s


-- | hashFileNix
-- use hashStringNix to hash file content
hashFileNix
:: forall e t f m . MonadNix e t f m => NixString -> Path -> Prim m NixString
hashFileNix nsAlgo nvfilepath = Prim $ hash =<< fileContent
where
hash = outPrim . hashStringNix nsAlgo
outPrim (Prim x) = x
fileContent :: m NixString
fileContent = mkNixStringWithoutContext <$> Nix.Render.readFile nvfilepath


placeHolderNix :: forall t f m e . MonadNix e t f m => NValue t f m -> m (NValue t f m)
placeHolderNix p =
do
Expand Down Expand Up @@ -1853,6 +1865,7 @@ builtinsList =
, add2 Normal "hasAttr" hasAttrNix
, add Normal "hasContext" hasContextNix
, add' Normal "hashString" (hashStringNix @e @t @f @m)
, add' Normal "hashFile" hashFileNix
, add Normal "head" headNix
, add2 Normal "intersectAttrs" intersectAttrsNix
, add Normal "isAttrs" isAttrsNix
Expand Down
4 changes: 2 additions & 2 deletions tests/NixLanguageTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ groupBy key = Map.fromListWith (<>) . fmap (key &&& pure)
-- previously passed.
newFailingTests :: Set String
newFailingTests = Set.fromList
[ "eval-okay-hash"
, "eval-okay-hashfile"
[
"eval-okay-hash"
, "eval-okay-path" -- #128
, "eval-okay-fromTOML"
, "eval-okay-ind-string" -- #1000 #610
Expand Down

0 comments on commit 8e64e98

Please sign in to comment.