From 4941ce541a9c1c5ceff6572da722c55d9e7cf73f Mon Sep 17 00:00:00 2001 From: Tomas Drtina Date: Fri, 19 Dec 2025 02:56:19 -0800 Subject: [PATCH 1/2] remove dependency on cryptonite --- hnix.cabal | 1 - src/Nix/Effects.hs | 1 - src/Nix/Effects/Derivation.hs | 12 ++++-------- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/hnix.cabal b/hnix.cabal index 9f4cf5796..f8bff11ce 100644 --- a/hnix.cabal +++ b/hnix.cabal @@ -442,7 +442,6 @@ library , binary >= 0.8.5 && < 0.9 , bytestring >= 0.10.8 && < 0.13 , crypton - , cryptonite , memory , comonad >= 5.0.4 && < 5.2 , containers >= 0.5.11.0 && < 0.8 diff --git a/src/Nix/Effects.hs b/src/Nix/Effects.hs index 45898f443..ac14a30ba 100644 --- a/src/Nix/Effects.hs +++ b/src/Nix/Effects.hs @@ -23,7 +23,6 @@ import qualified Data.Text as Text import Network.HTTP.Client hiding ( path, Proxy ) import Network.HTTP.Client.TLS import Network.HTTP.Types -import qualified "cryptonite" Crypto.Hash as Hash import Nix.Utils.Fix1 import Nix.Expr.Types.Annotated import Nix.Frames hiding ( Proxy ) diff --git a/src/Nix/Effects/Derivation.hs b/src/Nix/Effects/Derivation.hs index 9692d0ef7..f3a7e14d5 100644 --- a/src/Nix/Effects/Derivation.hs +++ b/src/Nix/Effects/Derivation.hs @@ -27,8 +27,7 @@ import qualified Data.Text as Text import Text.Megaparsec import Text.Megaparsec.Char -import qualified "cryptonite" Crypto.Hash as Hash -- 2021-07-05: Attrocity of Haskell hashing situation, in HNix we ended-up with 2 hash package dependencies @{hashing, cryptonite}@ -import qualified Data.ByteString +import qualified "crypton" Crypto.Hash as Hash -- 2021-07-05: Attrocity of Haskell hashing situation, in HNix we ended-up with 2 hash package dependencies @{hashing, cryptonite}@ import qualified System.Nix.Base32 as Base32 import Nix.Atoms @@ -48,15 +47,12 @@ import Nix.Value.Monad import qualified System.Nix.Hash as Store import qualified System.Nix.StorePath as Store -import qualified System.Nix.ContentAddress as Store -import qualified "crypton" Crypto.Hash as CryptonHash -import Data.Some.Newtype ( Some(..) ) import Data.Dependent.Sum ( DSum(..) ) import qualified Data.Dependent.Sum as DSum -- Type for fixed-output derivation hash digest -- Digest comes from crypton (Crypto.Hash.Digest) -type HashDigest = DSum Store.HashAlgo CryptonHash.Digest +type HashDigest = DSum Store.HashAlgo Hash.Digest -- Helper functions to work with HashDigest hashDigestAlgoText :: HashDigest -> Text @@ -348,7 +344,7 @@ defaultDerivationStrict val = do Flat -> mempty let toHash = "fixed:out:" <> modePrefix <> algoText <> ":" <> hashText <> ":/nix/store:" <> Store.unStorePathName name -- Use SHA256 to compute the store path hash - let hashPart = Store.mkStorePathHashPart @CryptonHash.SHA256 (encodeUtf8 toHash) + let hashPart = Store.mkStorePathHashPart @Hash.SHA256 (encodeUtf8 toHash) let hashBase32 = Base32.encode $ Store.unStorePathHashPart hashPart pure $ "/nix/store/" <> hashBase32 <> "-" <> Store.unStorePathName name @@ -364,7 +360,7 @@ defaultDerivationStrict val = do let toHash = "output:" <> o <> ":sha256:" <> drvHashHex <> ":/nix/store:" <> Store.unStorePathName name -- Use hnix-store-core's mkStorePathHashPart which handles truncation and returns raw bytes -- Use crypton's SHA256 (compatible with hnix-store-core) - let hashPart = Store.mkStorePathHashPart @CryptonHash.SHA256 (encodeUtf8 toHash) + let hashPart = Store.mkStorePathHashPart @Hash.SHA256 (encodeUtf8 toHash) -- Extract raw bytes and base32-encode using Nix base32 let hashText = Base32.encode $ Store.unStorePathHashPart hashPart -- Build the store path From 506e613524803d993ac3d1819be7f65610647ae9 Mon Sep 17 00:00:00 2001 From: Tomas Drtina Date: Fri, 19 Dec 2025 03:24:56 -0800 Subject: [PATCH 2/2] remove dependency on hashing --- hnix.cabal | 1 - src/Nix/Builtins.hs | 20 ++++++++------------ src/Nix/Effects.hs | 1 - src/Nix/Effects/Derivation.hs | 3 +-- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/hnix.cabal b/hnix.cabal index f8bff11ce..c437d5408 100644 --- a/hnix.cabal +++ b/hnix.cabal @@ -453,7 +453,6 @@ library , free >= 5.1 && < 5.3 , gitrev >= 1.1.0 && < 1.4 , hashable >= 1.2.5 && < 1.5 - , hashing >= 0.1.0 && < 0.2 , hnix-store-core >= 0.6.0 && < 0.9 , hnix-store-nar >= 0.1.0 && < 0.2 , hnix-store-remote >= 0.6.0 && < 0.9 diff --git a/src/Nix/Builtins.hs b/src/Nix/Builtins.hs index 4ff48ed1f..45c8070ad 100644 --- a/src/Nix/Builtins.hs +++ b/src/Nix/Builtins.hs @@ -10,7 +10,6 @@ {-# language PatternSynonyms #-} {-# language TemplateHaskell #-} {-# language UndecidableInstances #-} -{-# language PackageImports #-} -- 2021-07-05: Due to hashing Haskell IT system situation, in HNix we currently ended-up with 2 hash package dependencies @{hashing, cryptonite}@ {-# options_ghc -fno-warn-name-shadowing #-} @@ -27,11 +26,7 @@ import GHC.Exception ( ErrorCall(ErrorCall) ) import Control.Monad ( foldM ) import Control.Monad.Catch ( MonadCatch(catch) ) import Control.Monad.ListM ( sortByM ) -import "hashing" Crypto.Hash -import qualified "hashing" Crypto.Hash.MD5 as MD5 -import qualified "hashing" Crypto.Hash.SHA1 as SHA1 -import qualified "hashing" Crypto.Hash.SHA256 as SHA256 -import qualified "hashing" Crypto.Hash.SHA512 as SHA512 +import qualified Crypto.Hash as Hash import qualified Data.Aeson as A #if MIN_VERSION_aeson(2,0,0) import qualified Data.Aeson.Key as AKM @@ -51,6 +46,7 @@ import qualified Data.HashMap.Lazy as M import Data.Scientific import qualified Data.Set as S import qualified Data.Text as Text +import qualified Data.Text.Encoding as Text import Data.Text.Read ( decimal ) import qualified Data.Text.Lazy.Builder as Builder import Data.These ( fromThese, These ) @@ -1458,17 +1454,17 @@ hashStringNix nsAlgo ns = case algo of -- 2021-03-04: Pattern can not be taken-out because hashes represented as different types - "md5" -> f (show . mkHash @MD5.MD5) - "sha1" -> f (show . mkHash @SHA1.SHA1) - "sha256" -> f (show . mkHash @SHA256.SHA256) - "sha512" -> f (show . mkHash @SHA512.SHA512) + "md5" -> f (show . mkHash @Hash.MD5) + "sha1" -> f (show . mkHash @Hash.SHA1) + "sha256" -> f (show . mkHash @Hash.SHA256) + "sha512" -> f (show . mkHash @Hash.SHA512) _ -> throwError $ ErrorCall $ "builtins.hashString: expected \"md5\", \"sha1\", \"sha256\", or \"sha512\", got " <> show algo where -- This intermidiary `a` is only needed because of the type application - mkHash :: (Show a, HashAlgorithm a) => Text -> a - mkHash s = hash $ encodeUtf8 s + mkHash :: (Show a, Hash.HashAlgorithm a) => Text -> Hash.Digest a + mkHash s = Hash.hash $ Text.encodeUtf8 s -- | hashFileNix diff --git a/src/Nix/Effects.hs b/src/Nix/Effects.hs index ac14a30ba..40315e902 100644 --- a/src/Nix/Effects.hs +++ b/src/Nix/Effects.hs @@ -5,7 +5,6 @@ {-# language DataKinds #-} {-# language GeneralizedNewtypeDeriving #-} {-# language UndecidableInstances #-} -{-# language PackageImports #-} -- 2021-07-05: Due to hashing Haskell IT system situation, in HNix we currently ended-up with 2 hash package dependencies @{hashing, cryptonite}@ {-# language TypeOperators #-} {-# options_ghc -Wno-orphans #-} diff --git a/src/Nix/Effects/Derivation.hs b/src/Nix/Effects/Derivation.hs index f3a7e14d5..eadd93b0a 100644 --- a/src/Nix/Effects/Derivation.hs +++ b/src/Nix/Effects/Derivation.hs @@ -2,7 +2,6 @@ {-# language DataKinds #-} {-# language NamedFieldPuns #-} {-# language RecordWildCards #-} -{-# language PackageImports #-} -- 2021-07-05: Due to hashing Haskell IT system situation, in HNix we currently ended-up with 2 hash package dependencies @{hashing, cryptonite}@ {-# language TypeApplications #-} {-# language ExistentialQuantification #-} @@ -27,7 +26,7 @@ import qualified Data.Text as Text import Text.Megaparsec import Text.Megaparsec.Char -import qualified "crypton" Crypto.Hash as Hash -- 2021-07-05: Attrocity of Haskell hashing situation, in HNix we ended-up with 2 hash package dependencies @{hashing, cryptonite}@ +import qualified Crypto.Hash as Hash import qualified System.Nix.Base32 as Base32 import Nix.Atoms