cachix 0.3.5 → 0.3.6
raw patch · 13 files changed
+193/−118 lines, 13 filesdep +vectordep −hnix-store-core
Dependencies added: vector
Dependencies removed: hnix-store-core
Files
- CHANGELOG.md +4/−0
- cachix.cabal +3/−2
- src/Cachix/Client/Commands.hs +20/−18
- src/Cachix/Client/Config.hs +5/−4
- src/Cachix/Client/Config/Orphans.hs +11/−0
- src/Cachix/Client/Env.hs +8/−6
- src/Cachix/Client/NetRc.hs +8/−7
- src/Cachix/Client/Push.hs +12/−11
- src/Cachix/Client/Store.hs +6/−5
- src/System/Nix/Base32.hs +39/−0
- test/InstallationModeSpec.hs +48/−40
- test/NetRcSpec.hs +21/−18
- test/NixConfSpec.hs +8/−7
CHANGELOG.md view
@@ -7,6 +7,10 @@ ## Unreleased +## [0.3.6] - 2020-02-22++- #275: support LTS-13.x and GHC 8.2.2+ ## [0.3.5] - 2020-01-10 ### Added
cachix.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: cachix-version: 0.3.5+version: 0.3.6 license: Apache-2.0 license-file: LICENSE copyright: 2018 Domen Kožar@@ -59,6 +59,7 @@ Cachix.Client.Store Cachix.Client.Store.Context Cachix.Client.URI+ System.Nix.Base32 cc-options: -Wall pkgconfig-depends: nix-store ==2.0 || >2.0, nix-main ==2.0 || >2.0@@ -87,7 +88,6 @@ , filepath , fsnotify , here- , hnix-store-core , http-client , http-client-tls , http-conduit@@ -114,6 +114,7 @@ , text , unix , uri-bytestring+ , vector , versions ghc-options: -optc=-std=c++17
src/Cachix/Client/Commands.hs view
@@ -141,11 +141,12 @@ nc <- NixConf.read NixConf.Global isTrusted <- isTrustedUser $ NixConf.readLines (catMaybes [nc]) NixConf.isTrustedUsers isNixOS <- doesFileExist "/etc/NIXOS"- let nixEnv = NixEnv- { isRoot = user == "root",- isTrusted = isTrusted,- isNixOS = isNixOS- }+ let nixEnv =+ NixEnv+ { isRoot = user == "root",+ isTrusted = isTrusted,+ isNixOS = isNixOS+ } addBinaryCache (config env) binaryCache useOptions $ fromMaybe (getInstallationMode nixEnv) (useMode useOptions) @@ -224,19 +225,20 @@ else "(retry #" <> show (rsIterNumber retrystatus) <> ") " pushStrategy :: Env -> PushOptions -> Text -> Text -> PushStrategy IO ()-pushStrategy env opts name storePath = PushStrategy- { onAlreadyPresent = pass,- on401 =- if isJust (config env)- then throwM $ accessDeniedBinaryCache name- else throwM notAuthenticatedBinaryCache,- onError = throwM,- onAttempt = \retrystatus size ->- -- we append newline instead of putStrLn due to https://github.com/haskell/text/issues/242- putStr $ retryText retrystatus <> "compressing and pushing " <> storePath <> " (" <> humanSize (fromIntegral size) <> ")\n",- onDone = pass,- withXzipCompressor = defaultWithXzipCompressorWithLevel (compressionLevel opts)- }+pushStrategy env opts name storePath =+ PushStrategy+ { onAlreadyPresent = pass,+ on401 =+ if isJust (config env)+ then throwM $ accessDeniedBinaryCache name+ else throwM notAuthenticatedBinaryCache,+ onError = throwM,+ onAttempt = \retrystatus size ->+ -- we append newline instead of putStrLn due to https://github.com/haskell/text/issues/242+ putStr $ retryText retrystatus <> "compressing and pushing " <> storePath <> " (" <> humanSize (fromIntegral size) <> ")\n",+ onDone = pass,+ withXzipCompressor = defaultWithXzipCompressorWithLevel (compressionLevel opts)+ } pushStorePath :: Env -> PushOptions -> Text -> Text -> IO () pushStorePath env opts name storePath = do
src/Cachix/Client/Config.hs view
@@ -46,10 +46,11 @@ deriving (Show, Generic, Interpret, Inject) mkConfig :: Text -> Config-mkConfig token = Config- { authToken = Token (toS token),- binaryCaches = []- }+mkConfig token =+ Config+ { authToken = Token (toS token),+ binaryCaches = []+ } type ConfigPath = FilePath
src/Cachix/Client/Config/Orphans.hs view
@@ -1,4 +1,5 @@ {-# OPTIONS_GHC -Wno-orphans #-}+{-# LANGUAGE CPP #-} module Cachix.Client.Config.Orphans (@@ -10,8 +11,13 @@ import Protolude import Servant.Auth.Client +#if MIN_VERSION_dhall(1,28,0)+instance FromDhall Token where+ autoWith _ = Decoder+#else instance Interpret Token where autoWith _ = Type+#endif { extract = ex, expected = Text }@@ -19,8 +25,13 @@ ex (TextLit (Chunks [] t)) = pure (Token (toS t)) ex _ = panic "Unexpected Dhall value. Did it typecheck?" +#if MIN_VERSION_dhall(1,28,0)+instance ToDhall Token where+ injectWith _ = Encoder+#else instance Inject Token where injectWith _ = InputType+#endif { embed = TextLit . Chunks [] . toS . getToken, declared = Text }
src/Cachix/Client/Env.hs view
@@ -2,6 +2,7 @@ ( Env (..), mkEnv, cachixVersion,+ customManagerSettings, ) where @@ -41,12 +42,13 @@ config <- readConfig $ configPath cachixoptions manager <- newTlsManagerWith customManagerSettings let clientenv = mkClientEnv manager $ getBaseUrl (host cachixoptions)- return Env- { config = config,- clientenv = clientenv,- cachixoptions = cachixoptions,- storeAsync = store- }+ return+ Env+ { config = config,+ clientenv = clientenv,+ cachixoptions = cachixoptions,+ storeAsync = store+ } customManagerSettings :: ManagerSettings customManagerSettings =
src/Cachix/Client/NetRc.hs view
@@ -45,13 +45,14 @@ new :: [NetRcHost] new = map mkHost $ filter (not . Api.isPublic) binarycaches mkHost :: Api.BinaryCache -> NetRcHost- mkHost bc = NetRcHost- { nrhName = toS $ stripPrefix "http://" $ stripPrefix "https://" (Api.uri bc),- nrhLogin = "",- nrhPassword = getToken (authToken config),- nrhAccount = "",- nrhMacros = []- }+ mkHost bc =+ NetRcHost+ { nrhName = toS $ stripPrefix "http://" $ stripPrefix "https://" (Api.uri bc),+ nrhLogin = "",+ nrhPassword = getToken (authToken config),+ nrhAccount = "",+ nrhMacros = []+ } where -- stripPrefix that either strips or returns the same string stripPrefix :: Text -> Text -> Text
src/Cachix/Client/Push.hs view
@@ -176,17 +176,18 @@ references <- sort . T.lines . T.strip . toS <$> readProcess "nix-store" ["-q", "--references", toS storePath] mempty let fp = fingerprint storePath narHash narSize references sig = dsign (signingSecretKey $ pushCacheSigningKey cache) fp- nic = Api.NarInfoCreate- { Api.cStoreHash = storeHash,- Api.cStoreSuffix = storeSuffix,- Api.cNarHash = narHash,- Api.cNarSize = narSize,- Api.cFileSize = fileSize,- Api.cFileHash = toS fileHash,- Api.cReferences = fmap (T.drop 11) references,- Api.cDeriver = deriver,- Api.cSig = toS $ B64.encode $ unSignature sig- }+ nic =+ Api.NarInfoCreate+ { Api.cStoreHash = storeHash,+ Api.cStoreSuffix = storeSuffix,+ Api.cNarHash = narHash,+ Api.cNarSize = narSize,+ Api.cFileSize = fileSize,+ Api.cFileHash = toS fileHash,+ Api.cReferences = fmap (T.drop 11) references,+ Api.cDeriver = deriver,+ Api.cSig = toS $ B64.encode $ unSignature sig+ } escalate $ Api.isNarInfoCreateValid nic -- Upload narinfo with signature escalate <=< (`runClientM` clientEnv) $
src/Cachix/Client/Store.hs view
@@ -185,11 +185,12 @@ } defaultClosureParams :: ClosureParams-defaultClosureParams = ClosureParams- { flipDirection = False,- includeOutputs = False,- includeDerivers = False- }+defaultClosureParams =+ ClosureParams+ { flipDirection = False,+ includeOutputs = False,+ includeDerivers = False+ } computeFSClosure :: Store -> ClosureParams -> PathSet -> IO PathSet computeFSClosure (Store store) params startingSet_ = withPathSet startingSet_ $ \startingSet -> do
+ src/System/Nix/Base32.hs view
@@ -0,0 +1,39 @@+module System.Nix.Base32 (encode) where++-- Copied from hnix-store-core until there's a new release++import qualified Data.ByteString as BS+import qualified Data.Text as T+import qualified Data.Vector as V+import Protolude++-- | Encode a 'BS.ByteString' in Nix's base32 encoding+encode :: BS.ByteString -> T.Text+encode c = T.pack $ map char32 [nChar - 1, nChar - 2 .. 0]+ where+ digits32 = V.fromList "0123456789abcdfghijklmnpqrsvwxyz"+ -- Each base32 character gives us 5 bits of information, while+ -- each byte gives is 8. Because 'div' rounds down, we need to add+ -- one extra character to the result, and because of that extra 1+ -- we need to subtract one from the number of bits in the+ -- bytestring to cover for the case where the number of bits is+ -- already a factor of 5. Thus, the + 1 outside of the 'div' and+ -- the - 1 inside of it.+ nChar = fromIntegral $ ((BS.length c * 8 - 1) `div` 5) + 1+ byte = BS.index c . fromIntegral+ -- May need to switch to a more efficient calculation at some+ -- point.+ bAsInteger :: Integer+ bAsInteger =+ sum+ [ fromIntegral (byte j) * (256 ^ j)+ | j <- [0 .. BS.length c - 1]+ ]+ char32 :: Integer -> Char+ char32 i = digits32 V.! digitInd+ where+ digitInd =+ fromIntegral $+ bAsInteger+ `div` (32 ^ i)+ `mod` 32
test/InstallationModeSpec.hs view
@@ -8,58 +8,66 @@ spec :: Spec spec = describe "getInstallationMode" $ do it "NixOS with root prints configuration" $- let nixenv = NixEnv- { isTrusted = True, -- any- isRoot = True,- isNixOS = True- }+ let nixenv =+ NixEnv+ { isTrusted = True, -- any+ isRoot = True,+ isNixOS = True+ } in getInstallationMode nixenv `shouldBe` WriteNixOS it "NixOS without trust prints configuration plus trust" $- let nixenv = NixEnv- { isTrusted = False,- isRoot = False,- isNixOS = True- }+ let nixenv =+ NixEnv+ { isTrusted = False,+ isRoot = False,+ isNixOS = True+ } in getInstallationMode nixenv `shouldBe` UntrustedRequiresSudo it "NixOS without trust prints configuration on older Nix" $- let nixenv = NixEnv- { isTrusted = False,- isRoot = False,- isNixOS = True- }+ let nixenv =+ NixEnv+ { isTrusted = False,+ isRoot = False,+ isNixOS = True+ } in getInstallationMode nixenv `shouldBe` UntrustedRequiresSudo it "NixOS non-root trusted results into local install" $- let nixenv = NixEnv- { isTrusted = True,- isRoot = False,- isNixOS = True- }+ let nixenv =+ NixEnv+ { isTrusted = True,+ isRoot = False,+ isNixOS = True+ } in getInstallationMode nixenv `shouldBe` Install NixConf.Local it "non-NixOS root results into global install" $- let nixenv = NixEnv- { isTrusted = True,- isRoot = True,- isNixOS = False- }+ let nixenv =+ NixEnv+ { isTrusted = True,+ isRoot = True,+ isNixOS = False+ } in getInstallationMode nixenv `shouldBe` Install NixConf.Global it "non-NixOS with Nix 1.X root results into global install" $- let nixenv = NixEnv- { isTrusted = True,- isRoot = True,- isNixOS = False -- any- }+ let nixenv =+ NixEnv+ { isTrusted = True,+ isRoot = True,+ isNixOS = False -- any+ } in getInstallationMode nixenv `shouldBe` Install NixConf.Global it "non-NixOS non-root trusted results into local install" $- let nixenv = NixEnv- { isTrusted = True,- isRoot = False,- isNixOS = False- }+ let nixenv =+ NixEnv+ { isTrusted = True,+ isRoot = False,+ isNixOS = False+ } in getInstallationMode nixenv `shouldBe` Install NixConf.Local it "non-NixOS non-root non-trusted results into required sudo" $- let nixenv = NixEnv- { isTrusted = False,- isRoot = False,- isNixOS = False- }+ let nixenv =+ NixEnv+ { isTrusted = False,+ isRoot = False,+ isNixOS = False+ } in getInstallationMode nixenv `shouldBe` UntrustedRequiresSudo
test/NetRcSpec.hs view
@@ -9,28 +9,31 @@ import Test.Hspec bc1 :: BinaryCache-bc1 = BinaryCache- { name = "name",- uri = "https://name.cachix.org",- publicSigningKeys = ["pub"],- isPublic = False,- githubUsername = "foobar"- }+bc1 =+ BinaryCache+ { name = "name",+ uri = "https://name.cachix.org",+ publicSigningKeys = ["pub"],+ isPublic = False,+ githubUsername = "foobar"+ } bc2 :: BinaryCache-bc2 = BinaryCache- { name = "name2",- uri = "https://name2.cachix.org",- publicSigningKeys = ["pub2"],- isPublic = False,- githubUsername = "foobar2"- }+bc2 =+ BinaryCache+ { name = "name2",+ uri = "https://name2.cachix.org",+ publicSigningKeys = ["pub2"],+ isPublic = False,+ githubUsername = "foobar2"+ } config :: Config-config = Config- { authToken = "token123",- binaryCaches = []- }+config =+ Config+ { authToken = "token123",+ binaryCaches = []+ } -- TODO: poor man's golden tests, use https://github.com/stackbuilders/hspec-golden test :: [BinaryCache] -> Text -> Expectation
test/NixConfSpec.hs view
@@ -12,13 +12,14 @@ property x = NixConf.render <$> parse x `shouldBe` Right x bc :: BinaryCache-bc = BinaryCache- { name = "name",- uri = "https://name.cachix.org",- isPublic = True,- publicSigningKeys = ["pub"],- githubUsername = "foobar"- }+bc =+ BinaryCache+ { name = "name",+ uri = "https://name.cachix.org",+ isPublic = True,+ publicSigningKeys = ["pub"],+ githubUsername = "foobar"+ } spec :: Spec spec = do