Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions hnix.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -454,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
Expand Down
20 changes: 8 additions & 12 deletions src/Nix/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 #-}

Expand All @@ -27,11 +26,7 @@
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
Expand All @@ -51,6 +46,7 @@
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 )
Expand Down Expand Up @@ -1458,17 +1454,17 @@

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

Check warning on line 1467 in src/Nix/Builtins.hs

View workflow job for this annotation

GitHub Actions / HLint

Suggestion in hashStringNix in module Nix.Builtins: Use alternative ▫︎ Found: "Text.encodeUtf8" ▫︎ Perhaps: "encodeUtf8"


-- | hashFileNix
Expand Down
2 changes: 0 additions & 2 deletions src/Nix/Effects.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 #-}
Expand All @@ -23,7 +22,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 )
Expand Down
13 changes: 4 additions & 9 deletions src/Nix/Effects/Derivation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 #-}

Expand All @@ -27,8 +26,7 @@
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 Crypto.Hash as Hash
import qualified System.Nix.Base32 as Base32

import Nix.Atoms
Expand All @@ -48,15 +46,12 @@

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
Expand Down Expand Up @@ -107,9 +102,9 @@
hashDerivationModulo
Derivation
{ mFixed = Just digest
, outputs

Check warning on line 105 in src/Nix/Effects/Derivation.hs

View workflow job for this annotation

GitHub Actions / GHC (9.10)

Defined but not used: ‘outputs’
, hashMode
, name

Check warning on line 107 in src/Nix/Effects/Derivation.hs

View workflow job for this annotation

GitHub Actions / GHC (9.10)

Defined but not used: ‘name’
} =
do
-- For fixed-output derivations, hash a special string encoding the content address
Expand Down Expand Up @@ -348,7 +343,7 @@
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

Expand All @@ -364,7 +359,7 @@
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
Expand Down
Loading