on master help sign in
Merge pull request #271 from obsidiansystems/drop-nix-remote-check

Drop nix remote check

commitaed938c786391d9988869d84480855cdab840514 authorLuigy Leon <luichi.19@gmail.com> dateMon 22 Oct 2018, 22:41 (8 years ago) parent7ce865d4119078
7 files changed+9−64
lib/command/src/Obelisk/Command.hs+1−9 lib/command/src/Obelisk/Command/Nix.hs+1−30 lib/command/src/Obelisk/Command/Project.hs+1−2 lib/command/src/Obelisk/Command/Thunk.hs+3−4 lib/command/src/Obelisk/Command/Upgrade/Hash.hs+1−2 lib/command/src/Obelisk/Command/VmBuilder.hs+1−2 lib/selftest/src/Obelisk/SelfTest.hs+1−15
lib/command/src/Obelisk/Command.hs+1−9
@@ -238,18 +238,10 @@ mkObeliskConfig = do
238238 -- This function should not use argument parser (full argument parsing happens post handoff)
239239 let logLevel = toLogLevel $ "-v" `elem` cliArgs
240240 notInteractive <- not <$> isInteractiveTerm
241−-- instance MonadIO m => MonadError (Either Text ProcessFailed) (DieT m) where
242−-- throwError = \case
243−-- Left s -> do
244−-- putLog Alert s
245−-- liftIO $ exitWith $ ExitFailure 2
246−-- Right (ProcessFailed p code) -> do
247−-- putLog Alert $ "Process exited with code " <> T.pack (show code) <> "; " <> T.pack (show p)
248−-- liftIO $ exitWith $ ExitFailure 2
249241 cliConf <- newCliConfig logLevel notInteractive notInteractive $ \case
250242 ObeliskError_ProcessError (ProcessFailure p code) ann ->
251243 ( "Process exited with code " <> T.pack (show code) <> "; " <> reconstructCommand p
252− <> maybe "" ("\n\n" <>) ann
244+ <> maybe "" ("\n" <>) ann
253245 , 2
254246 )
255247 ObeliskError_Unstructured msg -> (msg, 2)
lib/command/src/Obelisk/Command/Nix.hs+1−30
@@ -9,7 +9,6 @@
99{-# LANGUAGE TypeApplications #-}
1010module Obelisk.Command.Nix
1111 ( nixBuild
12− , withNixRemoteCheck
1312 , NixBuildConfig (..)
1413 , Target (..)
1514 , OutLink (..)
@@ -87,7 +86,7 @@ instance Default NixBuildConfig where
8786
8887nixBuild :: MonadObelisk m => NixBuildConfig -> m FilePath
8988nixBuild cfg = withSpinner' ("Running nix-build on " <> desc) (Just $ const $ "Built " <> desc) $ do
90− output <- withNixRemoteCheck $ readProcessAndLogStderr Debug $ proc "nix-build" $ mconcat
89+ output <- readProcessAndLogStderr Debug $ proc "nix-build" $ mconcat
9190 [[path], attrArg, args, outLink, buildersArg]
9291 -- Remove final newline that Nix appends
9392 Just (outPath, '\n') <- pure $ T.unsnoc output
@@ -108,31 +107,3 @@ nixBuild cfg = withSpinner' ("Running nix-build on " <> desc) (Just $ const $ "B
108107 [] -> []
109108 builders -> ["--builders", intercalate ";" builders]
110109
111−-- | If a nix command fails, and this may be related to the NIX_REMOTE issue,
112−-- tell the user what to do.
113−--
114−-- Added: June, 2018. Consider removing this eventually.
115−withNixRemoteCheck
116− :: MonadObelisk m
117− => (forall m'. MonadInfallibleObelisk m' => ExceptT ObeliskError m' a)
118− -> m a
119−withNixRemoteCheck f = do
120− status <- runExceptT f
121− case status of
122− Right a -> pure a
123− Left e -> throwError =<< case matching asProcessFailure e of
124− Left _ -> pure e
125− Right pf -> liftIO (lookupEnv "NIX_REMOTE") >>= \case
126− Just _ -> pure e
127− Nothing -> liftIO (writable <$> getPermissions "/nix/var/nix/db") >>= \case
128− True -> pure e
129− False -> pure $ ObeliskError_ProcessError pf $ Just $ T.unlines
130− [ "!!! "
131− , "!!! A nix command failed to run. You might need to set the NIX_REMOTE environment variable"
132− , "!!! to `daemon`. To do this, run the following before running obelisk:"
133− , "!!! "
134− , "!!! export NIX_REMOTE=daemon"
135− , "!!! "
136− , "!!! For details, see https://github.com/NixOS/nixpkgs/issues/5713"
137− , "!!! "
138− ]
lib/command/src/Obelisk/Command/Project.hs+1−2
@@ -34,7 +34,6 @@ import GitHub.Data.Name (Name)
3434import Obelisk.App (MonadObelisk)
3535import Obelisk.CliApp
3636import Obelisk.Command.Thunk
37−import Obelisk.Command.Nix (withNixRemoteCheck)
3837--TODO: Make this module resilient to random exceptions
3938
4039--TODO: Don't hardcode this
@@ -204,7 +203,7 @@ inImpureProjectShell shellName command = withProjectRoot "." $ \root ->
204203 projectShell root False shellName command
205204
206205projectShell :: MonadObelisk m => FilePath -> Bool -> String -> String -> m ()
207−projectShell root isPure shellName command = withNixRemoteCheck $ do
206+projectShell root isPure shellName command = do
208207 (_, _, _, ph) <- createProcess_ "runNixShellAttr" $ setCwd (Just root) $ proc "nix-shell" $
209208 [ "--pure" | isPure ] <>
210209 [ "-A"
lib/command/src/Obelisk/Command/Thunk.hs+3−4
@@ -73,7 +73,6 @@ import Text.URI
7373
7474import Obelisk.App (MonadObelisk)
7575import Obelisk.CliApp
76−import Obelisk.Command.Nix (withNixRemoteCheck)
7776import Obelisk.Command.Utils
7877
7978--TODO: Support symlinked thunk data
@@ -160,14 +159,14 @@ getNixSha256ForUriUnpacked
160159 -> m NixSha256
161160getNixSha256ForUriUnpacked uri =
162161 withExitFailMessage ("nix-prefetch-url: Failed to determine sha256 hash of URL " <> render uri) $ do
163− [hash] <- fmap T.lines $ withNixRemoteCheck $ readProcessAndLogOutput (Debug, Debug) $
162+ [hash] <- fmap T.lines $ readProcessAndLogOutput (Debug, Debug) $
164163 proc "nix-prefetch-url" ["--unpack" , "--type" , "sha256" , T.unpack $ render uri]
165164 pure hash
166165
167166nixPrefetchGit :: MonadObelisk m => URI -> Text -> Bool -> m NixSha256
168167nixPrefetchGit uri rev fetchSubmodules =
169168 withExitFailMessage ("nix-prefetch-git: Failed to determine sha256 hash of Git repo " <> render uri <> " at " <> rev) $ do
170− out <- withNixRemoteCheck $ readProcessAndLogStderr Debug $
169+ out <- readProcessAndLogStderr Debug $
171170 proc "nix-prefetch-git" $ filter (/="")
172171 [ "--url", T.unpack $ render uri
173172 , "--rev", T.unpack rev
@@ -751,7 +750,7 @@ uriThunkPtr uri mbranch = do
751750 Left e -> do
752751 putLog Warning $ "\
753752\Failed to fetch archive from GitHub. This is probably a private repo. \
754−\Falling back on normal fetchgit. Original failure:\n\n"
753+\Falling back on normal fetchgit. Original failure:"
755754 errorToWarning e
756755 let s' = forgetGithub True s
757756 (,) (ThunkSource_Git s') <$> gitThunkRev s' commit
lib/command/src/Obelisk/Command/Upgrade/Hash.hs+1−2
@@ -23,7 +23,6 @@ import System.Process (cwd, proc)
2323
2424import Obelisk.App (MonadObelisk)
2525import Obelisk.CliApp
26−import Obelisk.Command.Nix (withNixRemoteCheck)
2726import Obelisk.Command.Utils
2827
2928import Obelisk.Migration
@@ -88,7 +87,7 @@ getHashAtGitRevision revs excludes dir = withSystemTempDirectory "obelisk-hashre
8887 return result
8988
9089nixHash :: MonadObelisk m => FilePath -> m Hash
91−nixHash dir = withSpinnerNoTrail "Running `nix-hash`" $ withNixRemoteCheck $
90+nixHash dir = withSpinnerNoTrail "Running `nix-hash`" $
9291 readProc $ proc "nix-hash" [dir]
9392
9493-- | Clean up the following files in the git working copy
lib/command/src/Obelisk/Command/VmBuilder.hs+1−2
@@ -22,7 +22,6 @@ import System.Process (proc)
2222
2323import Obelisk.App (MonadObelisk, getObeliskUserStateDir)
2424import Obelisk.CliApp
25−import Obelisk.Command.Nix (withNixRemoteCheck)
2625
2726-- | Generate the `--builders` argument string to enable the VM builder after ensuring it is available.
2827getNixBuildersArg :: MonadObelisk m => m String
@@ -155,7 +154,7 @@ getDockerBuilderStateDir = liftA2 (</>) getObeliskUserStateDir (pure "nix-docker
155154testLinuxBuild :: MonadObelisk m => FilePath -> m ()
156155testLinuxBuild stateDir
157156 | System.Info.os == "linux" = failWith "Using the docker builder is not necessary on linux."
158− | otherwise = withNixRemoteCheck $ do
157+ | otherwise = do
159158 (exitCode, _stdout, stderr) <- readCreateProcessWithExitCode $ proc "nix-build"
160159 [ "-E", "(import <nixpkgs> { system = \"x86_64-linux\"; }).writeText \"test\" builtins.currentTime"
161160 , "--builders", nixBuildersArgString stateDir
lib/selftest/src/Obelisk/SelfTest.hs+1−15
@@ -64,22 +64,8 @@ tshow :: Show a => a -> Text
6464tshow = T.pack . show
6565
6666-- | Like `shelly` but used when running `ob` commands
67−--
68−-- This tests the NIX_REMOTE workaround, whether that gets printed
69−-- on failure, and whether retrying with the suggested workaround
70−-- leads to the test succeeding.
7167shellyOb :: MonadIO m => (Sh a -> Sh a) -> Sh a -> m a
72−shellyOb f obTest = shelly $ f $ do
73− obTest `catch_sh` \(e :: RunFailed) -> do
74− obStderr <- lastStderr
75− if T.isInfixOf "export NIX_REMOTE" obStderr
76− then do
77− runCli $ do
78− putLog Notice "Detected NIX_REMOTE suggestion in stderr of failed ob"
79− putLog Warning "Retrying this test with NIX_REMOTE=daemon"
80− setenv "NIX_REMOTE" "daemon"
81− f obTest
82− else throw e
68+shellyOb f obTest = shelly $ f obTest
8369
8470main :: IO ()
8571main = do