From f7d2f2d93c9f7078518a0c846173653721c4f468 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 1 Oct 2020 16:19:56 +0200 Subject: [PATCH 1/3] Add Haskell Language Server support vscode: - use Nix Environment Selector (with shell.nix) - install haskell.haskell extension --- nix/overlay.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nix/overlay.nix b/nix/overlay.nix index 921917e..ebe77a3 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -46,6 +46,7 @@ in buildInputs = [ haskellPkgs.cabal-install haskellPkgs.ghcid + haskellPkgs.haskell-language-server super.docker-compose self.niv # self.releaser From 9dabd9bb92ca26c5f0bba735b9db5d30a66777b8 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 1 Oct 2020 16:52:51 +0200 Subject: [PATCH 2/3] Remove broken live-check script, use ./build --- live-check | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100755 live-check diff --git a/live-check b/live-check deleted file mode 100755 index fb642a5..0000000 --- a/live-check +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env nix-shell -#!nix-shell ./shell.nix -#!nix-shell -i bash -set -eux -o pipefail - -cd "$(dirname "${BASH_SOURCE[0]}")" - -ghcid \ - --command 'ghci -isrc/haskell/exe src/haskell/exe/Main.hs' \ - --reload=src/haskell \ - --restart=arion-compose.cabal \ - ; From 7c20fa9a117844e771fc159225ac32ecb32c049b Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 1 Oct 2020 11:51:06 +0200 Subject: [PATCH 3/3] Support use of prebuilt docker-compose.yaml --- src/haskell/exe/Main.hs | 42 ++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/src/haskell/exe/Main.hs b/src/haskell/exe/Main.hs index eeb6731..1816cd4 100644 --- a/src/haskell/exe/Main.hs +++ b/src/haskell/exe/Main.hs @@ -17,6 +17,8 @@ import Control.Monad.Fail import qualified Data.Text as T import qualified Data.Text.IO as T +import Data.Aeson(Value) + import System.Posix.User (getRealUserID) data CommonOptions = @@ -24,6 +26,7 @@ data CommonOptions = { files :: NonEmpty FilePath , pkgs :: Text , nixArgs :: [Text] + , prebuiltComposeFile :: Maybe FilePath } deriving (Show) @@ -56,6 +59,10 @@ parseOptions = do <> help "Causes Nix to print out a stack trace in case of Nix expression evaluation errors.") -- TODO --option support (https://github.com/pcapriotti/optparse-applicative/issues/284) userNixArgs <- many (T.pack <$> strOption (long "nix-arg" <> metavar "ARG" <> help "Pass an extra argument to nix. Example: --nix-arg --option --nix-arg substitute --nix-arg false")) + prebuiltComposeFile <- optional $ strOption + ( long "prebuilt-file" + <> metavar "JSONFILE" + <> help "Do not evaluate and use the prebuilt JSONFILE instead. Causes other evaluation-related options to be ignored." ) pure $ let nixArgs = userNixArgs <|> "--show-trace" <$ guard showTrace in CommonOptions{..} @@ -135,8 +142,7 @@ runDC cmd (DockerComposeArgs args) _opts = do runBuildAndDC :: Text -> DockerComposeArgs -> CommonOptions -> IO () runBuildAndDC cmd dopts opts = do - ea <- defaultEvaluationArgs opts - Arion.Nix.withBuiltComposition ea $ \path -> do + withBuiltComposeFile opts $ \path -> do loadImages path DockerCompose.run DockerCompose.Args { files = [path] @@ -145,13 +151,36 @@ runBuildAndDC cmd dopts opts = do runEvalAndDC :: Text -> DockerComposeArgs -> CommonOptions -> IO () runEvalAndDC cmd dopts opts = do - ea <- defaultEvaluationArgs opts - Arion.Nix.withEvaluatedComposition ea $ \path -> + withComposeFile opts $ \path -> DockerCompose.run DockerCompose.Args { files = [path] , otherArgs = [cmd] ++ unDockerComposeArgs dopts } +withBuiltComposeFile :: CommonOptions -> (FilePath -> IO r) -> IO r +withBuiltComposeFile opts cont = case prebuiltComposeFile opts of + Just prebuilt -> do + cont prebuilt + Nothing -> do + args <- defaultEvaluationArgs opts + Arion.Nix.withBuiltComposition args cont + +withComposeFile :: CommonOptions -> (FilePath -> IO r) -> IO r +withComposeFile opts cont = case prebuiltComposeFile opts of + Just prebuilt -> do + cont prebuilt + Nothing -> do + args <- defaultEvaluationArgs opts + Arion.Nix.withEvaluatedComposition args cont + +getComposeValue :: CommonOptions -> IO Value +getComposeValue opts = case prebuiltComposeFile opts of + Just prebuilt -> do + decodeFile prebuilt + Nothing -> do + args <- defaultEvaluationArgs opts + Arion.Nix.evaluateComposition args + defaultEvaluationArgs :: CommonOptions -> IO EvaluationArgs defaultEvaluationArgs co = do uid <- getRealUserID @@ -166,7 +195,7 @@ defaultEvaluationArgs co = do runCat :: CommonOptions -> IO () runCat co = do - v <- Arion.Nix.evaluateComposition =<< defaultEvaluationArgs co + v <- getComposeValue co T.hPutStrLn stdout (pretty v) runRepl :: CommonOptions -> IO () @@ -229,8 +258,7 @@ runExec :: Bool -> Bool -> Maybe Text -> Bool -> Int -> [(Text, Text)] -> Maybe runExec detach privileged user noTTY index envs workDir service commandAndArgs opts = do putErrText $ "Service: " <> service - ea <- defaultEvaluationArgs opts - Arion.Nix.withEvaluatedComposition ea $ \path -> do + withComposeFile opts $ \path -> do commandAndArgs'' <- case commandAndArgs of [] -> getDefaultExec path service x -> pure x