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

Use a read-only store #903

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
36 changes: 13 additions & 23 deletions src/Nix/Effects.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ import qualified System.Info
import System.Process

import qualified System.Nix.Hash as Store
import qualified System.Nix.Store.Remote as Store.Remote
import qualified System.Nix.StorePath as Store
import qualified System.Nix.ReadonlyStore as Store

-- | A path into the nix store
newtype StorePath = StorePath { unStorePath :: FilePath }
Expand Down Expand Up @@ -400,34 +400,24 @@ class

-- *** Instances

instance MonadStore IO where
toStorePath :: Store.StorePath -> StorePath
toStorePath = StorePath . T.unpack . T.decodeUtf8 . Store.storePathToRawFilePath

addToStore name path recursive repair =
case Store.makeStorePathName name of
Left err -> pure $ Left $ ErrorCall $ "String '" <> show name <> "' is not a valid path name: " <> err
Right pathName ->
do
-- TODO: redesign the filter parameter
res <- Store.Remote.runStore $ Store.Remote.addToStore @'Store.SHA256 pathName path recursive (const False) repair
parseStoreResult "addToStore" res >>= \case
Left err -> pure $ Left err
Right storePath -> pure $ Right $ StorePath $ toString $ T.decodeUtf8 $ Store.storePathToRawFilePath storePath
instance MonadStore IO where

addTextToStore' name text references repair = do
res <- Store.Remote.runStore $ Store.Remote.addTextToStore name text references repair
parseStoreResult "addTextToStore" res >>= \case
Left err -> pure $ Left err
Right path -> pure $ Right $ StorePath $ toString $ T.decodeUtf8 $ Store.storePathToRawFilePath path
addToStore name path recursive repair = case Store.makeStorePathName name of
Left err -> return $ Left $ ErrorCall $ "String '" ++ show name ++ "' is not a valid path name: " ++ err
Right pathName -> do
-- TODO: redesign the filter parameter
Right . toStorePath <$> Store.computeStorePathForPath @'Store.SHA256 pathName path recursive (const False) repair

addTextToStore' name text references _repair = case Store.makeStorePathName name of
Left err -> return $ Left $ ErrorCall $ "String '" ++ show name ++ "' is not a valid path name: " ++ err
Right pathName -> do
return $ Right $ toStorePath $ Store.computeStorePathForText "/nix/store" pathName (T.encodeUtf8 text) references

-- ** Functions

parseStoreResult :: Monad m => String -> (Either String a, [Store.Remote.Logger]) -> m (Either ErrorCall a)
parseStoreResult name res =
case res of
(Left msg, logs) -> pure $ Left $ ErrorCall $ "Failed to execute '" <> name <> "': " <> msg <> "\n" <> show logs
(Right result, _) -> pure $ Right result

addTextToStore :: (Framed e m, MonadStore m) => StorePathName -> Text -> Store.StorePathSet -> RepairFlag -> m StorePath
addTextToStore a b c d = either throwError pure =<< addTextToStore' a b c d

Expand Down