Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote store #59

Merged
merged 8 commits into from
Jul 24, 2020
Merged
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
17 changes: 16 additions & 1 deletion hnix-store-core/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
# Revision history for hnix-store-core

## (unreleased) 0.3.0.0 -- 2020-XY-ZV

* `StorePath` type changed to simple variant without type level
symbolic store path root.
* Added `makeFixedOutputPath` to `System.Nix.ReadonlyStore`
* Added `decodeBase16` and `decodeBase32` to `System.Nix.Hash`
* `System.Nix.StorePath` module now provides
* `storePathToFilePath` and `storePathToText` helpers
* `storePathToNarInfo` for converting paths to `narinfo` URLs
* `parsePath` function
* `pathParser` Attoparsec parser
* Added `System.Nix.Build` module
* Added `System.Nix.Derivation` module
* Removed `System.Nix.Util` module, moved to `hnix-store-remote`

## 0.2.0.0 -- 2020-03-12

Removed `System.Nix.Store`. We may reintroduce it later when multiple backends
exist and we can tell what common effects they should share.

## 0.1.0.0 -- YYYY-mm-dd
## 0.1.0.0 -- 2019-03-18

* First version.
14 changes: 10 additions & 4 deletions hnix-store-core/hnix-store-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ license-file: LICENSE
author: Shea Levy
maintainer: shea@shealevy.com
copyright: 2018 Shea Levy
category: System
category: Nix
build-type: Simple
extra-source-files: ChangeLog.md, README.md
cabal-version: >=1.10

library
exposed-modules: System.Nix.Base32
, System.Nix.Build
, System.Nix.Derivation
, System.Nix.Hash
, System.Nix.Internal.Base32
, System.Nix.Internal.Hash
Expand All @@ -28,8 +30,8 @@ library
, System.Nix.Signature
, System.Nix.StorePath
, System.Nix.StorePathMetadata
, System.Nix.Util
build-depends: base >=4.10 && <5
, attoparsec
, base16-bytestring
, bytestring
, binary
Expand All @@ -42,8 +44,7 @@ library
, filepath
, hashable
, mtl
, regex-base
, regex-tdfa >= 1.3.1.0
, nix-derivation >= 1.1.1 && <2
, saltine
, time
, text
Expand All @@ -65,22 +66,27 @@ test-suite format-tests
main-is: Driver.hs
other-modules:
Arbitrary
Derivation
NarFormat
Hash
StorePath
hs-source-dirs:
tests
build-depends:
hnix-store-core
, attoparsec
, base
, base16-bytestring
, base64-bytestring
, binary
, bytestring
, containers
, filepath
, directory
, process
, tasty
, tasty-discover
, tasty-golden
, tasty-hspec
, tasty-hunit
, tasty-quickcheck
Expand Down
55 changes: 55 additions & 0 deletions hnix-store-core/src/System/Nix/Build.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{-# LANGUAGE RecordWildCards #-}
{-|
Description : Build related types
Maintainer : srk <srk@48.io>
|-}
module System.Nix.Build (
BuildMode(..)
, BuildStatus(..)
, BuildResult(..)
, buildSuccess
) where

import Data.Time (UTCTime)
import Data.Text (Text)
import Data.HashSet (HashSet)

-- keep the order of these Enums to match enums from reference implementations
-- src/libstore/store-api.hh
data BuildMode = Normal | Repair | Check
deriving (Eq, Ord, Enum, Show)

data BuildStatus =
Built
| Substituted
| AlreadyValid
| PermanentFailure
| InputRejected
| OutputRejected
| TransientFailure -- possibly transient
| CachedFailure -- no longer used
| TimedOut
| MiscFailure
| DependencyFailed
| LogLimitExceeded
| NotDeterministic
deriving (Eq, Ord, Enum, Show)


-- | Result of the build
data BuildResult = BuildResult
{ -- | build status, MiscFailure should be default
status :: !BuildStatus
, -- | possible build error message
errorMessage :: !(Maybe Text)
, -- | How many times this build was performed
timesBuilt :: !Integer
, -- | If timesBuilt > 1, whether some builds did not produce the same result
isNonDeterministic :: !Bool
, -- Start time of this build
startTime :: !UTCTime
, -- Stop time of this build
stopTime :: !UTCTime
} deriving (Eq, Ord, Show)

buildSuccess BuildResult{..} = status == Built || status == Substituted || status == AlreadyValid
36 changes: 36 additions & 0 deletions hnix-store-core/src/System/Nix/Derivation.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{-# LANGUAGE OverloadedStrings #-}

module System.Nix.Derivation (
parseDerivation
, buildDerivation
) where

import Data.Attoparsec.Text.Lazy (Parser)
import Data.ByteString (ByteString)
import Data.Text (Text)
import Data.Text.Lazy.Builder (Builder)
import Nix.Derivation (Derivation)
import System.Nix.StorePath (StorePath, pathParser)

import qualified Data.ByteString.Char8
import qualified Data.Text
import qualified Data.Text.Lazy.Builder
import qualified Data.Attoparsec.Text.Lazy

import qualified Nix.Derivation
import qualified System.Nix.StorePath

parseDerivation :: FilePath -> Parser (Derivation StorePath Text)
parseDerivation expectedRoot =
Nix.Derivation.parseDerivationWith
("\"" *> System.Nix.StorePath.pathParser expectedRoot <* "\"")
Nix.Derivation.textParser

buildDerivation :: Derivation StorePath Text -> Builder
buildDerivation derivation =
Nix.Derivation.buildDerivationWith
(string . Data.Text.pack . show)
string
derivation
where
string = Data.Text.Lazy.Builder.fromText . Data.Text.pack . show
Loading