Skip to content

Commit 8e64e98

Browse files
soulomoonAnton-Latukha
authored andcommitted
add builtins.hashfile
1 parent 4f94e33 commit 8e64e98

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Nix/Builtins.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,18 @@ hashStringNix nsAlgo ns =
14241424
mkHash s = hash $ encodeUtf8 s
14251425

14261426

1427+
-- | hashFileNix
1428+
-- use hashStringNix to hash file content
1429+
hashFileNix
1430+
:: forall e t f m . MonadNix e t f m => NixString -> Path -> Prim m NixString
1431+
hashFileNix nsAlgo nvfilepath = Prim $ hash =<< fileContent
1432+
where
1433+
hash = outPrim . hashStringNix nsAlgo
1434+
outPrim (Prim x) = x
1435+
fileContent :: m NixString
1436+
fileContent = mkNixStringWithoutContext <$> Nix.Render.readFile nvfilepath
1437+
1438+
14271439
placeHolderNix :: forall t f m e . MonadNix e t f m => NValue t f m -> m (NValue t f m)
14281440
placeHolderNix p =
14291441
do
@@ -1853,6 +1865,7 @@ builtinsList =
18531865
, add2 Normal "hasAttr" hasAttrNix
18541866
, add Normal "hasContext" hasContextNix
18551867
, add' Normal "hashString" (hashStringNix @e @t @f @m)
1868+
, add' Normal "hashFile" hashFileNix
18561869
, add Normal "head" headNix
18571870
, add2 Normal "intersectAttrs" intersectAttrsNix
18581871
, add Normal "isAttrs" isAttrsNix

tests/NixLanguageTests.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ groupBy key = Map.fromListWith (<>) . fmap (key &&& pure)
5656
-- previously passed.
5757
newFailingTests :: Set String
5858
newFailingTests = Set.fromList
59-
[ "eval-okay-hash"
60-
, "eval-okay-hashfile"
59+
[
60+
"eval-okay-hash"
6161
, "eval-okay-path" -- #128
6262
, "eval-okay-fromTOML"
6363
, "eval-okay-ind-string" -- #1000 #610

0 commit comments

Comments
 (0)