Skip to content

Commit 11da925

Browse files
authored
Merge pull request #272 from haskell-nix/srk/daemon
Server side
2 parents 1bc4d05 + e5c1492 commit 11da925

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+4568
-2041
lines changed

cabal.project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ benchmarks: true
44
packages:
55
./hnix-store-core/hnix-store-core.cabal
66
./hnix-store-db/hnix-store-db.cabal
7+
./hnix-store-json/hnix-store-json.cabal
78
./hnix-store-nar/hnix-store-nar.cabal
89
./hnix-store-readonly/hnix-store-readonly.cabal
910
./hnix-store-remote/hnix-store-remote.cabal

cabal.project.local.ci

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ package hnix-store-core
44
package hnix-store-db
55
ghc-options: -Wunused-packages -Wall -Werror
66

7+
package hnix-store-json
8+
ghc-options: -Wunused-packages -Wall -Werror
9+
710
package hnix-store-nar
811
ghc-options: -Wunused-packages -Wall -Werror
912

default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ in {
2222
inherit (haskellPackages)
2323
hnix-store-core
2424
hnix-store-db
25+
hnix-store-json
2526
hnix-store-nar
2627
hnix-store-readonly
2728
hnix-store-remote

docs/01-Contributors.org

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ in order of appearance:
2828
+ Luigy Leon @luigy
2929
+ squalus @squalus
3030
+ Vaibhav Sagar @vaibhavsagar
31+
+ Ryan Trinkle @ryantrinkle
32+
+ Travis Whitaker @TravisWhitaker
33+
+ Andrea Bedini @andreabedini

hie.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ cradle:
1212
- path: "./hnix-store-db/tests"
1313
component: "hnix-store-db:test:db"
1414

15+
- path: "./hnix-store-json/src"
16+
component: "lib:hnix-store-json"
17+
18+
- path: "./hnix-store-json/tests"
19+
component: "hnix-store-json:test:json"
20+
1521
- path: "./hnix-store-nar/src"
1622
component: "lib:hnix-store-nar"
1723

hnix-store-core/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Next
22

33
* Changes:
4+
* `System.Nix.StorePath.makeStorePathName` renamed to `System.Nix.StorePath.mkStorePathName`
45
* `System.Nix.ReadOnlyStore` moved to `hnix-store-readonly` package
56
and renamed to `System.Nix.Store.ReadOnly` [#247](https://github.com/haskell-nix/hnix-store/pull/247)
67
* `System.Nix.Nar*` moved to `hnix-store-nar` package [#247](https://github.com/haskell-nix/hnix-store/pull/247)

hnix-store-core/hnix-store-core.cabal

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ library
6565
, System.Nix.Fingerprint
6666
, System.Nix.Hash
6767
, System.Nix.Hash.Truncation
68+
, System.Nix.OutputName
69+
, System.Nix.Realisation
6870
, System.Nix.Signature
6971
, System.Nix.Store.Types
7072
, System.Nix.StorePath
@@ -80,7 +82,7 @@ library
8082
, crypton
8183
, data-default-class
8284
, dependent-sum > 0.7
83-
, dependent-sum-template > 0.1.1 && < 0.3
85+
, dependent-sum-template >= 0.2.0.1 && < 0.3
8486
, filepath
8587
, hashable
8688
-- Required for crypton low-level type convertion
@@ -102,6 +104,7 @@ test-suite core
102104
Fingerprint
103105
Hash
104106
Signature
107+
StorePath
105108
hs-source-dirs:
106109
tests
107110
build-tool-depends:

hnix-store-core/src/System/Nix/Build.hs

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,40 @@ Maintainer : srk <srk@48.io>
55
module System.Nix.Build
66
( BuildMode(..)
77
, BuildStatus(..)
8-
, BuildResult(..)
98
, buildSuccess
9+
, BuildResult(..)
1010
) where
1111

12+
import Data.Map (Map)
1213
import Data.Time (UTCTime)
1314
import Data.Text (Text)
1415
import GHC.Generics (Generic)
1516

16-
-- keep the order of these Enums to match enums from reference implementations
17+
import System.Nix.OutputName (OutputName)
18+
import System.Nix.Realisation (DerivationOutput, Realisation)
19+
20+
-- | Mode of the build operation
21+
-- Keep the order of these Enums to match enums from reference implementations
1722
-- src/libstore/store-api.hh
1823
data BuildMode
19-
= BuildMode_Normal
20-
| BuildMode_Repair
21-
| BuildMode_Check
24+
= BuildMode_Normal -- ^ Perform normal build
25+
| BuildMode_Repair -- ^ Try to repair corrupted or missing paths by re-building or re-downloading them
26+
| BuildMode_Check -- ^ Check if the build is reproducible (rebuild and compare to previous build)
2227
deriving (Eq, Generic, Ord, Enum, Show)
2328

29+
-- | Build result status
2430
data BuildStatus =
25-
BuildStatus_Built
26-
| BuildStatus_Substituted
27-
| BuildStatus_AlreadyValid
31+
BuildStatus_Built -- ^ Build performed successfully
32+
| BuildStatus_Substituted -- ^ Path substituted from cache
33+
| BuildStatus_AlreadyValid -- ^ Path is already valid (available in local store)
2834
| BuildStatus_PermanentFailure
2935
| BuildStatus_InputRejected
3036
| BuildStatus_OutputRejected
31-
| BuildStatus_TransientFailure -- possibly transient
32-
| BuildStatus_CachedFailure -- no longer used
33-
| BuildStatus_TimedOut
37+
| BuildStatus_TransientFailure -- ^ Possibly transient build failure
38+
| BuildStatus_CachedFailure -- ^ Obsolete
39+
| BuildStatus_TimedOut -- ^ Build timed out
3440
| BuildStatus_MiscFailure
35-
| BuildStatus_DependencyFailed
41+
| BuildStatus_DependencyFailed -- ^ Build dependency failed to build
3642
| BuildStatus_LogLimitExceeded
3743
| BuildStatus_NotDeterministic
3844
| BuildStatus_ResolvesToAlreadyValid
@@ -41,24 +47,27 @@ data BuildStatus =
4147

4248
-- | Result of the build
4349
data BuildResult = BuildResult
44-
{ -- | build status, MiscFailure should be default
45-
status :: !BuildStatus
46-
, -- | possible build error message
47-
errorMessage :: !(Maybe Text)
48-
, -- | How many times this build was performed
49-
timesBuilt :: !Int
50-
, -- | If timesBuilt > 1, whether some builds did not produce the same result
51-
isNonDeterministic :: !Bool
52-
, -- Start time of this build
53-
startTime :: !UTCTime
54-
, -- Stop time of this build
55-
stopTime :: !UTCTime
50+
{ buildResultStatus :: BuildStatus
51+
-- ^ Build status, MiscFailure should be the default
52+
, buildResultErrorMessage :: Maybe Text
53+
-- ^ Possible build error message
54+
, buildResultTimesBuilt :: Maybe Int
55+
-- ^ How many times this build was performed (since 1.29)
56+
, buildResultIsNonDeterministic :: Maybe Bool
57+
-- ^ If timesBuilt > 1, whether some builds did not produce the same result (since 1.29)
58+
, buildResultStartTime :: Maybe UTCTime
59+
-- ^ Start time of this build (since 1.29)
60+
, buildResultStopTime :: Maybe UTCTime
61+
-- ^ Stop time of this build (since 1.29)
62+
, buildResultBuiltOutputs :: Maybe (Map (DerivationOutput OutputName) Realisation)
63+
-- ^ Mapping of the output names to @Realisation@s (since 1.28)
64+
-- (paths with additional info and their dependencies)
5665
}
5766
deriving (Eq, Generic, Ord, Show)
5867

59-
buildSuccess :: BuildResult -> Bool
60-
buildSuccess BuildResult {..} =
61-
status `elem`
68+
buildSuccess :: BuildStatus -> Bool
69+
buildSuccess x =
70+
x `elem`
6271
[ BuildStatus_Built
6372
, BuildStatus_Substituted
6473
, BuildStatus_AlreadyValid

hnix-store-core/src/System/Nix/DerivedPath.hs

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,22 @@ module System.Nix.DerivedPath (
1010
, derivedPathToText
1111
) where
1212

13-
import Data.Bifunctor (first)
1413
import GHC.Generics (Generic)
1514
import Data.Set (Set)
1615
import Data.Text (Text)
17-
import System.Nix.StorePath (StoreDir, StorePath, StorePathName, InvalidPathError)
16+
import System.Nix.OutputName (OutputName, InvalidNameError)
17+
import System.Nix.StorePath (StoreDir(..), StorePath, InvalidPathError)
1818

19+
import qualified Data.Bifunctor
20+
import qualified Data.ByteString.Char8
1921
import qualified Data.Set
2022
import qualified Data.Text
23+
import qualified System.Nix.OutputName
2124
import qualified System.Nix.StorePath
2225

2326
data OutputsSpec =
2427
OutputsSpec_All
25-
| OutputsSpec_Names (Set StorePathName)
28+
| OutputsSpec_Names (Set OutputName)
2629
deriving (Eq, Generic, Ord, Show)
2730

2831
data DerivedPath =
@@ -32,20 +35,20 @@ data DerivedPath =
3235

3336
data ParseOutputsError =
3437
ParseOutputsError_InvalidPath InvalidPathError
38+
| ParseOutputsError_InvalidName InvalidNameError
3539
| ParseOutputsError_NoNames
40+
| ParseOutputsError_NoPrefix StoreDir Text
3641
deriving (Eq, Ord, Show)
3742

38-
convertError
39-
:: Either InvalidPathError a
40-
-> Either ParseOutputsError a
41-
convertError = first ParseOutputsError_InvalidPath
42-
4343
parseOutputsSpec :: Text -> Either ParseOutputsError OutputsSpec
4444
parseOutputsSpec t
4545
| t == "*" = Right OutputsSpec_All
4646
| otherwise = do
4747
names <- mapM
48-
(convertError . System.Nix.StorePath.makeStorePathName)
48+
( Data.Bifunctor.first
49+
ParseOutputsError_InvalidName
50+
. System.Nix.OutputName.mkOutputName
51+
)
4952
(Data.Text.splitOn "," t)
5053
if null names
5154
then Left ParseOutputsError_NoNames
@@ -55,21 +58,47 @@ outputsSpecToText :: OutputsSpec -> Text
5558
outputsSpecToText = \case
5659
OutputsSpec_All -> "*"
5760
OutputsSpec_Names ns ->
58-
Data.Text.intercalate "," (fmap System.Nix.StorePath.unStorePathName (Data.Set.toList ns))
61+
Data.Text.intercalate
62+
","
63+
(fmap System.Nix.OutputName.unOutputName
64+
(Data.Set.toList ns)
65+
)
5966

6067
parseDerivedPath
6168
:: StoreDir
6269
-> Text
6370
-> Either ParseOutputsError DerivedPath
64-
parseDerivedPath root p =
65-
case Data.Text.breakOn "!" p of
66-
(s, r) ->
67-
if Data.Text.null r
68-
then DerivedPath_Opaque
69-
<$> (convertError $ System.Nix.StorePath.parsePathFromText root s)
70-
else DerivedPath_Built
71-
<$> (convertError $ System.Nix.StorePath.parsePathFromText root s)
72-
<*> parseOutputsSpec (Data.Text.drop (Data.Text.length "!") r)
71+
parseDerivedPath root@(StoreDir sd) path =
72+
let -- We need to do a bit more legwork for case
73+
-- when StoreDir contains '!'
74+
-- which is generated by its Arbitrary instance
75+
textRoot = Data.Text.pack
76+
$ Data.ByteString.Char8.unpack sd
77+
78+
in case Data.Text.stripPrefix textRoot path of
79+
Nothing -> Left $ ParseOutputsError_NoPrefix root path
80+
Just woRoot ->
81+
case Data.Text.breakOn "!" woRoot of
82+
(pathNoPrefix, r) ->
83+
if Data.Text.null r
84+
then DerivedPath_Opaque
85+
<$> (convertError
86+
$ System.Nix.StorePath.parsePathFromText
87+
root
88+
path
89+
)
90+
else DerivedPath_Built
91+
<$> (convertError
92+
$ System.Nix.StorePath.parsePathFromText
93+
root
94+
(textRoot <> pathNoPrefix)
95+
)
96+
<*> parseOutputsSpec (Data.Text.drop (Data.Text.length "!") r)
97+
where
98+
convertError
99+
:: Either InvalidPathError a
100+
-> Either ParseOutputsError a
101+
convertError = Data.Bifunctor.first ParseOutputsError_InvalidPath
73102

74103
derivedPathToText :: StoreDir -> DerivedPath -> Text
75104
derivedPathToText root = \case

hnix-store-core/src/System/Nix/Fingerprint.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ import qualified Data.Text as Text
2626
-- | Produce the message signed by a NAR signature
2727
metadataFingerprint :: StoreDir -> StorePath -> Metadata StorePath -> Text
2828
metadataFingerprint storeDir storePath Metadata{..} = let
29-
narSize = fromMaybe 0 narBytes
30-
in fingerprint storeDir storePath narHash narSize (HashSet.toList references)
29+
narSize = fromMaybe 0 metadataNarBytes
30+
in fingerprint
31+
storeDir
32+
storePath
33+
metadataNarHash
34+
narSize
35+
(HashSet.toList metadataReferences)
3136

3237
-- | Produce the message signed by a NAR signature
3338
fingerprint :: StoreDir
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{-# LANGUAGE DeriveAnyClass #-}
2+
{-|
3+
Description : Derived path output names
4+
-}
5+
6+
module System.Nix.OutputName
7+
( OutputName(..)
8+
, mkOutputName
9+
-- * Re-exports
10+
, System.Nix.StorePath.InvalidNameError(..)
11+
, System.Nix.StorePath.parseNameText
12+
) where
13+
14+
import Data.Hashable (Hashable)
15+
import Data.Text (Text)
16+
import GHC.Generics (Generic)
17+
import System.Nix.StorePath (InvalidNameError)
18+
19+
import qualified System.Nix.StorePath
20+
21+
-- | Name of the derived path output
22+
-- Typically used for "dev", "doc" sub-outputs
23+
newtype OutputName = OutputName
24+
{ -- | Extract the contents of the name.
25+
unOutputName :: Text
26+
} deriving (Eq, Generic, Hashable, Ord, Show)
27+
28+
mkOutputName :: Text -> Either InvalidNameError OutputName
29+
mkOutputName = fmap OutputName . System.Nix.StorePath.parseNameText

0 commit comments

Comments
 (0)