on master help sign in
Add staticWhich around most subprocess paths
commitf4fddfdf801e593f7059b72ec526295403a9ace8 authorLeon P Smith <leon.smith@obsidian.systems> dateFri 10 Jul 2020, 15:13 (6 years ago) parent989641f
5 files changed+59−24
haskell-overlays/obelisk.nix+4 lib/command/src/Obelisk/Command/Deploy.hs+13−11 lib/command/src/Obelisk/Command/Project.hs+4−4 lib/command/src/Obelisk/Command/Utils.hs+30−1 lib/command/src/Obelisk/Command/VmBuilder.hs+8−8
haskell-overlays/obelisk.nix+4
@@ -19,8 +19,12 @@ in
1919 obelisk-command = haskellLib.overrideCabal (self.callCabal2nix "obelisk-command" (obeliskCleanSource ../lib/command) {}) {
2020 librarySystemDepends = [
2121 pkgs.jre
22+ pkgs.git
2223 pkgs.nix
2324 pkgs.nix-prefetch-git
25+ pkgs.openssh
26+ pkgs.rsync
27+ pkgs.which
2428 (haskellLib.justStaticExecutables self.ghcid)
2529 ];
2630 };
lib/command/src/Obelisk/Command/Deploy.hs+13−11
@@ -87,11 +87,12 @@ deployInit' thunkPtr (DeployInitOpts deployDir sshKeyPath hostnames route adminE
8787 --production data backed up to a dev environment.
8888 withSpinner "Creating project configuration directories" $ do
8989 callProcessAndLogOutput (Notice, Error) $
90− proc "mkdir" [ "-p"
91− , deployDir </> "config" </> "backend"
92− , deployDir </> "config" </> "common"
93− , deployDir </> "config" </> "frontend"
94− ]
90+ proc mkdirPath
91+ [ "-p"
92+ , deployDir </> "config" </> "backend"
93+ , deployDir </> "config" </> "common"
94+ , deployDir </> "config" </> "frontend"
95+ ]
9596
9697 let srcDir = deployDir </> "src"
9798 withSpinner ("Creating source thunk (" <> T.pack (makeRelative deployDir srcDir) <> ")") $ do
@@ -162,8 +163,8 @@ deployPush deployPath getNixBuilders = do
162163 "nix-copy-closure" ["-v", "--to", "--use-substitutes", "root@" <> host, "--gzip", outputPath]
163164 withSpinner "Uploading config" $ ifor_ buildOutputByHost $ \host _ -> do
164165 callProcessAndLogOutput (Notice, Warning) $
165− proc "rsync"
166− [ "-e ssh " <> unwords sshOpts
166+ proc rsyncPath
167+ [ "-e " <> sshPath <> " " <> unwords sshOpts
167168 , "-qarvz"
168169 , deployPath </> "config"
169170 , "root@" <> host <> ":/var/lib/backend"
@@ -171,9 +172,10 @@ deployPush deployPath getNixBuilders = do
171172 --TODO: Create GC root so we're sure our closure won't go away during this time period
172173 withSpinner "Switching to new configuration" $ ifor_ buildOutputByHost $ \host outputPath -> do
173174 callProcessAndLogOutput (Notice, Warning) $
174− proc "ssh" $ sshOpts <>
175+ proc sshPath $ sshOpts <>
175176 [ "root@" <> host
176177 , unwords
178+ -- Note that we don't want to $(staticWhich "nix-env") here, because this is executing on a remote machine
177179 [ "nix-env -p /nix/var/nix/profiles/system --set " <> outputPath
178180 , "&&"
179181 , "/nix/var/nix/profiles/system/bin/switch-to-configuration switch"
@@ -182,9 +184,9 @@ deployPush deployPath getNixBuilders = do
182184 isClean <- checkGitCleanStatus deployPath True
183185 when (not isClean) $ do
184186 withSpinner "Committing changes to Git" $ do
185− callProcessAndLogOutput (Debug, Error) $ proc "git"
187+ callProcessAndLogOutput (Debug, Error) $ proc gitPath
186188 ["-C", deployPath, "add", "."]
187− callProcessAndLogOutput (Debug, Error) $ proc "git"
189+ callProcessAndLogOutput (Debug, Error) $ proc gitPath
188190 ["-C", deployPath, "commit", "-m", "New deployment"]
189191 putLog Notice $ "Deployed => " <> T.pack route
190192 where
@@ -315,7 +317,7 @@ readDeployConfig deployDir fname = liftIO $ do
315317
316318verifyHostKey :: MonadObelisk m => FilePath -> FilePath -> String -> m ()
317319verifyHostKey knownHostsPath keyPath hostName =
318− callProcessAndLogOutput (Notice, Warning) $ proc "ssh" $
320+ callProcessAndLogOutput (Notice, Warning) $ proc sshPath $
319321 sshArgs knownHostsPath keyPath True <>
320322 [ "root@" <> hostName
321323 , "-o", "NumberOfPasswordPrompts=0"
lib/command/src/Obelisk/Command/Project.hs+4−4
@@ -51,7 +51,7 @@ import Obelisk.App (MonadObelisk)
5151import Obelisk.CliApp
5252import Obelisk.Command.Nix
5353import Obelisk.Command.Thunk
54−import Obelisk.Command.Utils (nixBuildExePath, nixExePath, toNixPath)
54+import Obelisk.Command.Utils (nixBuildExePath, nixExePath, toNixPath, cp, nixShellPath)
5555
5656--TODO: Make this module resilient to random exceptions
5757
@@ -116,7 +116,7 @@ initProject source force = withSystemTempDirectory "ob-init" $ \tmpDir -> do
116116 skel <- nixBuildAttrWithCache implDir "skeleton" --TODO: I don't think there's actually any reason to cache this
117117
118118 callProcessAndLogOutput (Notice, Error) $
119− proc "cp"
119+ proc cp
120120 [ "-r"
121121 , "--preserve=links"
122122 , obDir
@@ -126,7 +126,7 @@ initProject source force = withSystemTempDirectory "ob-init" $ \tmpDir -> do
126126
127127 withSpinner "Copying project skeleton" $ do
128128 callProcessAndLogOutput (Notice, Error) $
129− proc "cp"
129+ proc cp
130130 [ "-r"
131131 , "--no-preserve=mode"
132132 , "-T"
@@ -292,7 +292,7 @@ bashEscape :: String -> String
292292bashEscape = BSU.toString . bytes . bash . BSU.fromString
293293
294294nixShellRunProc :: NixShellConfig -> ProcessSpec
295−nixShellRunProc cfg = setDelegateCtlc True $ proc "nix-shell" $ runNixShellConfig cfg
295+nixShellRunProc cfg = setDelegateCtlc True $ proc nixShellPath $ runNixShellConfig cfg
296296
297297nixShellWithoutPkgs
298298 :: MonadObelisk m
lib/command/src/Obelisk/Command/Utils.hs+30−1
@@ -39,6 +39,9 @@ mvPath = $(staticWhich "mv")
3939rmPath :: FilePath
4040rmPath = $(staticWhich "rm")
4141
42+mkdirPath :: FilePath
43+mkdirPath = $(staticWhich "mkdir")
44+
4245ghcidExePath :: FilePath
4346ghcidExePath = $(staticWhich "ghcid")
4447
@@ -60,6 +63,32 @@ nixPrefetchGitPath = $(staticWhich "nix-prefetch-git")
6063nixPrefetchUrlPath :: FilePath
6164nixPrefetchUrlPath = $(staticWhich "nix-prefetch-url")
6265
66+nixShellPath :: FilePath
67+nixShellPath = $(staticWhich "nix-shell")
68+
69+rsyncPath :: FilePath
70+rsyncPath = $(staticWhich "rsync")
71+
72+sshPath :: FilePath
73+sshPath = $(staticWhich "ssh")
74+
75+gitPath :: FilePath
76+gitPath = $(staticWhich "git")
77+
78+whichPath :: FilePath
79+whichPath = $(staticWhich "which")
80+
81+sshKeygenPath :: FilePath
82+sshKeygenPath = $(staticWhich "ssh-keygen")
83+
84+-- $(staticWhich "docker") was intentionally omitted, at least for now
85+-- One concern is that I don't know how particular docker is about having the
86+-- CLI exe match the version of the docker daemon, which is largely outside of
87+-- the control of obelisk-command.
88+-- TODO: Investigate the tradeoffs associated with this choice
89+dockerPath :: FilePath
90+dockerPath = "docker"
91+
6392-- | Nix syntax requires relative paths to be prefixed by @./@ or
6493-- @../@. This will make a 'FilePath' that can be embedded in a Nix
6594-- expression.
@@ -97,7 +126,7 @@ initGit repo = do
97126 git ["commit", "-m", "Initial commit."]
98127
99128gitProcNoRepo :: [String] -> ProcessSpec
100−gitProcNoRepo args = setEnvOverride (M.singleton "GIT_TERMINAL_PROMPT" "0" <>) $ proc "git" args
129+gitProcNoRepo args = setEnvOverride (M.singleton "GIT_TERMINAL_PROMPT" "0" <>) $ proc gitPath args
101130
102131gitProc :: FilePath -> [String] -> ProcessSpec
103132gitProc repo = gitProcNoRepo . runGitInDir
lib/command/src/Obelisk/Command/VmBuilder.hs+8−8
@@ -21,7 +21,7 @@ import qualified System.Info
2121
2222import Obelisk.App (MonadObelisk, getObeliskUserStateDir)
2323import Obelisk.CliApp
24−import Obelisk.Command.Utils (rmPath)
24+import Obelisk.Command.Utils (rmPath, whichPath, sshKeygenPath, nixBuildExePath, dockerPath)
2525
2626-- | Generate the `--builders` argument string to enable the VM builder after ensuring it is available.
2727getNixBuildersArg :: MonadObelisk m => m String
@@ -35,7 +35,7 @@ getNixBuildersArg = do
3535
3636checkForNixDarwin :: MonadObelisk m => String -> m ()
3737checkForNixDarwin sshIdFile = do
38− (exitCode, _, _) <- readCreateProcessWithExitCode $ proc "which" ["darwin-rebuild"]
38+ (exitCode, _, _) <- readCreateProcessWithExitCode $ proc whichPath ["darwin-rebuild"]
3939 unless (exitCode == ExitSuccess) $ failWith $ T.intercalate "\n"
4040 [ "Deployments from macOS require nix-darwin to be installed."
4141 , "Follow the installation instructions here: https://github.com/LnL7/nix-darwin"
@@ -67,7 +67,7 @@ containerExists :: MonadObelisk m => FilePath -> m Bool
6767containerExists stateDir = handle (\(_ :: IOError) -> failWith needDockerMsg) $ do
6868 containerNames <- fmap (map T.strip . T.lines) $
6969 readProcessAndLogStderr Error $
70− proc "docker" ["container", "list", "--all", "--format", "{{.Names}}"]
70+ proc dockerPath ["container", "list", "--all", "--format", "{{.Names}}"]
7171 let exists = containerName `elem` containerNames
7272 when exists $ testLinuxBuild stateDir
7373 pure exists
@@ -85,7 +85,7 @@ containerSshPort = 2222
8585startContainer :: MonadObelisk m => m ()
8686startContainer = withSpinner "Starting VM builder" $
8787 callProcessAndLogOutput (Debug, Debug) $
88− proc "docker" ["start", containerName]
88+ proc dockerPath ["start", containerName]
8989
9090-- | Creates the Docker container; assumes it does not exist.
9191setupNixDocker :: MonadObelisk m => FilePath -> m ()
@@ -98,12 +98,12 @@ setupNixDocker stateDir = withSpinner ("Creating Docker container named " <> con
9898 callProcessAndLogOutput (Debug, Error) $
9999 proc rmPath ["-f", stateDir </> sshKeyFileName, stateDir </> sshKeyFileName <.> "pub"]
100100 callProcessAndLogOutput (Debug, Error) $
101− proc "ssh-keygen" ["-t", "ed25519", "-f", stateDir </> sshKeyFileName, "-P", ""]
101+ proc sshKeygenPath ["-t", "ed25519", "-f", stateDir </> sshKeyFileName, "-P", ""]
102102
103103 -- Build the docker container (which uses the SSH keys in the 'ssh' folder)
104104 containerId <- fmap T.strip $ readProcessAndLogStderr Error $
105− proc "docker" ["build", stateDir, "--quiet"]
106− callProcessAndLogOutput (Debug, Error) $ proc "docker"
105+ proc dockerPath ["build", stateDir, "--quiet"]
106+ callProcessAndLogOutput (Debug, Error) $ proc dockerPath
107107 [ "run"
108108 , "--restart", "always"
109109 , "--detach"
@@ -155,7 +155,7 @@ testLinuxBuild :: MonadObelisk m => FilePath -> m ()
155155testLinuxBuild stateDir
156156 | System.Info.os == "linux" = failWith "Using the docker builder is not necessary on linux."
157157 | otherwise = do
158− (exitCode, _stdout, stderr) <- readCreateProcessWithExitCode $ proc "nix-build"
158+ (exitCode, _stdout, stderr) <- readCreateProcessWithExitCode $ proc nixBuildExePath
159159 [ "--no-out-link"
160160 , "-E", "(import <nixpkgs> { system = \"x86_64-linux\"; }).writeText \"test\" builtins.currentTime"
161161 , "--builders", nixBuildersArgString stateDir