Skip to content

Commit e45f763

Browse files
support both epochs of base16-bytestring (#787)
Since it's trivial, allow downstream to stay more casual.
1 parent f4ef25b commit e45f763

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

hnix.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ library
442442
exposed-modules:
443443
Nix.Options.Parser
444444
build-depends:
445-
base16-bytestring >= 0.1.1 && < 0.2
445+
base16-bytestring >= 0.1.1 && < 1.1
446446
, pretty-show >= 1.9.5 && < 1.11
447447
, serialise >= 0.2.1 && < 0.3
448448
-- if !flag(profiling)

src/Nix/Builtins.hs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,7 @@ listToAttrs = fromValue @[NValue t f m] >=> \l ->
11981198
-- prim_hashString from nix/src/libexpr/primops.cc
11991199
-- fail if context in the algo arg
12001200
-- propagate context from the s arg
1201+
-- | The result coming out of hashString is base16 encoded
12011202
hashString
12021203
:: forall e t f m. MonadNix e t f m => NixString -> NixString -> Prim m NixString
12031204
hashString nsAlgo ns = Prim $ do
@@ -1233,10 +1234,16 @@ placeHolder = fromValue >=> fromStringNoContext >=> \t -> do
12331234
$ principledMakeNixStringWithoutContext
12341235
$ Text.cons '/'
12351236
$ Base32.encode
1236-
$ fst -- The result coming out of hashString is base16 encoded
1237-
$ Base16.decode
1238-
$ encodeUtf8
1239-
$ principledStringIgnoreContext h
1237+
$ case Base16.decode (text h) of -- The result coming out of hashString is base16 encoded
1238+
#if MIN_VERSION_base16_bytestring(1,0,0)
1239+
Right d -> d
1240+
Left e -> error $ "Couldn't Base16 decode the text: '" <> show (text h) <> "'.\nThe Left error content: '" <> e <> "'."
1241+
#else
1242+
(d, "") -> d
1243+
(_, e) -> error $ "Couldn't Base16 decode the text: '" <> show (text h) <> "'.\nUndecodable remainder: '" <> show e <> "'."
1244+
#endif
1245+
where
1246+
text h = encodeUtf8 $ principledStringIgnoreContext h
12401247

12411248
absolutePathFromValue :: MonadNix e t f m => NValue t f m -> m FilePath
12421249
absolutePathFromValue = \case

0 commit comments

Comments
 (0)