From 6fb0b1ec66e70f997ba129fb0080400538a05a52 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 4 Oct 2019 16:37:39 +0200 Subject: [PATCH 1/7] Update nixpkgs via added niv --- nix/default.nix | 5 +-- nix/nixpkgs.nix | 5 --- nix/overlay.nix | 5 +++ nix/sources.json | 26 ++++++++++++++ nix/sources.nix | 93 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 127 insertions(+), 7 deletions(-) delete mode 100644 nix/nixpkgs.nix create mode 100644 nix/sources.json create mode 100644 nix/sources.nix diff --git a/nix/default.nix b/nix/default.nix index c3fd071..12e5b95 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,12 +1,13 @@ /** * This is the entry-point for all nix execution in this project. */ -{ nixpkgsSrc ? ./nixpkgs.nix +{ sources ? import ./sources.nix +, nixpkgsSrc ? sources.nixpkgs , system ? null , ... }: -import (import ./nixpkgs.nix) ({ +import nixpkgsSrc ({ # Makes the config pure as well. See /top-level/impure.nix: config = { }; diff --git a/nix/nixpkgs.nix b/nix/nixpkgs.nix deleted file mode 100644 index 662487c..0000000 --- a/nix/nixpkgs.nix +++ /dev/null @@ -1,5 +0,0 @@ -# to update: $ nix-prefetch-url --unpack url -builtins.fetchTarball { - url = "https://github.com/NixOS/nixpkgs/archive/bd5e8f35c2e9d1ddc9cd2fea7a23563336d54acb.tar.gz"; - sha256 = "1wnzqqijrwf797nb234q10zb1h7086njradkkrx3a15b303grsw4"; -} diff --git a/nix/overlay.nix b/nix/overlay.nix index 8b5490c..5c3fa01 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -3,6 +3,8 @@ let inherit (self.arion-project) haskellPkgs; inherit (super) lib; + sources = import ./sources.nix; + in { @@ -19,7 +21,10 @@ in haskellPkgs.ghcid super.docker-compose (import ~/h/ghcide-nix {}).ghcide-ghc864 + self.niv ]; }; }; + + inherit (import (sources.niv) {}) niv; } diff --git a/nix/sources.json b/nix/sources.json new file mode 100644 index 0000000..efa1ae1 --- /dev/null +++ b/nix/sources.json @@ -0,0 +1,26 @@ +{ + "niv": { + "branch": "master", + "description": "Easy dependency management for Nix projects", + "homepage": "https://github.com/nmattia/niv", + "owner": "nmattia", + "repo": "niv", + "rev": "1dd094156b249586b66c16200ecfd365c7428dc0", + "sha256": "1b2vjnn8iac5iiqszjc2v1s1ygh0yri998c0k3s4x4kn0dsqik21", + "type": "tarball", + "url": "https://github.com/nmattia/niv/archive/1dd094156b249586b66c16200ecfd365c7428dc0.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "nixpkgs": { + "branch": "nixos-19.03", + "description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to", + "homepage": "https://github.com/NixOS/nixpkgs", + "owner": "NixOS", + "repo": "nixpkgs-channels", + "rev": "6420e2649fa9e267481fb78e602022dab9d1dcd1", + "sha256": "1z3hx7gp8nxk3fspi8vik3j9zxpajj3s7nxvjvx3b5igndxwbp74", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs-channels/archive/6420e2649fa9e267481fb78e602022dab9d1dcd1.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + } +} diff --git a/nix/sources.nix b/nix/sources.nix new file mode 100644 index 0000000..d4ac577 --- /dev/null +++ b/nix/sources.nix @@ -0,0 +1,93 @@ +# This file has been generated by Niv. + +# A record, from name to path, of the third-party packages +with rec +{ + pkgs = + if hasNixpkgsPath + then + if hasThisAsNixpkgsPath + then import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {} + else import {} + else + import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {}; + + sources_nixpkgs = + if builtins.hasAttr "nixpkgs" sources + then sources.nixpkgs + else abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; + + # fetchTarball version that is compatible between all the versions of Nix + builtins_fetchTarball = + { url, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if lessThan nixVersion "1.12" then + fetchTarball { inherit url; } + else + fetchTarball attrs; + + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = + { url, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchurl; + in + if lessThan nixVersion "1.12" then + fetchurl { inherit url; } + else + fetchurl attrs; + + # A wrapper around pkgs.fetchzip that has inspectable arguments, + # annoyingly this means we have to specify them + fetchzip = { url, sha256 }@attrs: pkgs.fetchzip attrs; + + # A wrapper around pkgs.fetchurl that has inspectable arguments, + # annoyingly this means we have to specify them + fetchurl = { url, sha256 }@attrs: pkgs.fetchurl attrs; + + hasNixpkgsPath = (builtins.tryEval ).success; + hasThisAsNixpkgsPath = + (builtins.tryEval ).success && == ./.; + + sources = builtins.fromJSON (builtins.readFile ./sources.json); + + mapAttrs = builtins.mapAttrs or + (f: set: with builtins; + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))); + + # borrowed from nixpkgs + functionArgs = f: f.__functionArgs or (builtins.functionArgs f); + callFunctionWith = autoArgs: f: args: + let auto = builtins.intersectAttrs (functionArgs f) autoArgs; + in f (auto // args); + + getFetcher = spec: + let fetcherName = + if builtins.hasAttr "type" spec + then builtins.getAttr "type" spec + else "builtin-tarball"; + in builtins.getAttr fetcherName { + "tarball" = fetchzip; + "builtin-tarball" = builtins_fetchTarball; + "file" = fetchurl; + "builtin-url" = builtins_fetchurl; + }; +}; +# NOTE: spec must _not_ have an "outPath" attribute +mapAttrs (_: spec: + if builtins.hasAttr "outPath" spec + then abort + "The values in sources.json should not have an 'outPath' attribute" + else + if builtins.hasAttr "url" spec && builtins.hasAttr "sha256" spec + then + spec // + { outPath = callFunctionWith spec (getFetcher spec) { }; } + else spec + ) sources From 80a4dbe8b92762c6881d2ec360762a88e4054b01 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 4 Oct 2019 17:16:41 +0200 Subject: [PATCH 2/7] Build matrix --- nix/ci.nix | 41 ++++++++++++++++++++++++++++++++++++----- nix/default.nix | 8 ++------ nix/overlay.nix | 2 +- nix/sources.json | 25 +++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 12 deletions(-) diff --git a/nix/ci.nix b/nix/ci.nix index 91f1a0f..4cf9309 100644 --- a/nix/ci.nix +++ b/nix/ci.nix @@ -1,6 +1,37 @@ -args@{ pkgs ? import ./default.nix args, system ? null, ... }: +let + sources = import ./sources.nix; + lib = import (sources."nixpkgs" + "/lib"); + inherit (import sources."project.nix" { inherit lib; }) dimension; +in -{ - inherit (pkgs) arion tests; - doc = pkgs.recurseIntoAttrs (import ../doc { inherit pkgs; }); -} +dimension "Nixpkgs version" { + "nixos-19_03" = { + nixpkgsSource = "nixpkgs"; + }; + "nixos-unstable" = { + nixpkgsSource = "nixos-unstable"; + + # Broken on unstable, wontfix because doc tooling will be changed. + # TODO: reenable + enableDoc = false; + }; + } ( + _name: { nixpkgsSource, enableDoc ? true }: + + + dimension "System" { + "x86_64-linux" = {}; + # TODO: darwin + # "x86_64-darwin" = { enableNixOSTests = false; }; + } ( + system: {}: + let + pkgs = import ./. { inherit system; nixpkgsSrc = sources.${nixpkgsSource}; }; + in + { + inherit (pkgs) arion tests; + } // lib.optionalAttrs enableDoc { + doc = pkgs.recurseIntoAttrs (import ../doc { inherit pkgs; }); + } + ) + ) diff --git a/nix/default.nix b/nix/default.nix index 12e5b95..7393d12 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,9 +1,6 @@ -/** - * This is the entry-point for all nix execution in this project. - */ { sources ? import ./sources.nix , nixpkgsSrc ? sources.nixpkgs -, system ? null +, system ? builtins.currentSystem , ... }: @@ -15,6 +12,5 @@ import nixpkgsSrc ({ # all the packages are defined there: (import ./overlay.nix) ]; -} // (if system == null then {} else { inherit system; -})) +}) diff --git a/nix/overlay.nix b/nix/overlay.nix index 5c3fa01..be6a8e1 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -8,7 +8,7 @@ let in { - arion = import ./arion.nix { pkgs = self; }; + inherit (import ./.. { pkgs = self; }) arion; tests = super.callPackage ../tests {}; doc = super.callPackage ../doc {}; diff --git a/nix/sources.json b/nix/sources.json index efa1ae1..fc22e3a 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -11,6 +11,19 @@ "url": "https://github.com/nmattia/niv/archive/1dd094156b249586b66c16200ecfd365c7428dc0.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, + "nixos-unstable": { + "branch": "nixos-unstable", + "description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to", + "homepage": "https://github.com/NixOS/nixpkgs", + "owner": "NixOS", + "repo": "nixpkgs-channels", + "rev": "cb4332e3eb6dfdb653f1fc7397a0292df228a533", + "sha256": "1722wphznqhpfny08rcy19l85r2l893ckjc3h1vfivj6aj64fwjr", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs-channels/archive/cb4332e3eb6dfdb653f1fc7397a0292df228a533.tar.gz", + "url_template": "https://github.com///archive/.tar.gz", + "version": "" + }, "nixpkgs": { "branch": "nixos-19.03", "description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to", @@ -22,5 +35,17 @@ "type": "tarball", "url": "https://github.com/NixOS/nixpkgs-channels/archive/6420e2649fa9e267481fb78e602022dab9d1dcd1.tar.gz", "url_template": "https://github.com///archive/.tar.gz" + }, + "project.nix": { + "branch": "master", + "description": "A configuration manager for your projects", + "homepage": null, + "owner": "hercules-ci", + "repo": "project.nix", + "rev": "33e5f3cb25feff4ccd00f8c60a05976e2ee01802", + "sha256": "0c3q3il5h6q3ms8m6da51knvjsfvpz12sh3a3av4d2a5ikm5ncl1", + "type": "tarball", + "url": "https://github.com/hercules-ci/project.nix/archive/33e5f3cb25feff4ccd00f8c60a05976e2ee01802.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" } } From 41d4fefd642387864d6e78d5ae997b212c916b57 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 4 Oct 2019 17:24:01 +0200 Subject: [PATCH 3/7] Add releaser --- nix/overlay.nix | 2 ++ nix/sources.json | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/nix/overlay.nix b/nix/overlay.nix index be6a8e1..163a653 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -22,9 +22,11 @@ in super.docker-compose (import ~/h/ghcide-nix {}).ghcide-ghc864 self.niv + self.releaser ]; }; }; inherit (import (sources.niv) {}) niv; + releaser = self.haskellPackages.callCabal2nix "releaser" sources.releaser {}; } diff --git a/nix/sources.json b/nix/sources.json index fc22e3a..9306c4b 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -47,5 +47,17 @@ "type": "tarball", "url": "https://github.com/hercules-ci/project.nix/archive/33e5f3cb25feff4ccd00f8c60a05976e2ee01802.tar.gz", "url_template": "https://github.com///archive/.tar.gz" + }, + "releaser": { + "branch": "master", + "description": "Automation of Haskell package release process.", + "homepage": null, + "owner": "domenkozar", + "repo": "releaser", + "rev": "43a4e27654f388e8eacab631e24e26792ff88fe2", + "sha256": "072jlbw0hdc4nvs9frd7wdyzdv4mz2dc5ib35iaqi9rzdafq6822", + "type": "tarball", + "url": "https://github.com/domenkozar/releaser/archive/43a4e27654f388e8eacab631e24e26792ff88fe2.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" } } From 7749eb2ef92fa9935fa77795a2ad61be34e436c0 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 4 Oct 2019 19:09:29 +0200 Subject: [PATCH 4/7] Add cabal check to ci, build strictly (once) --- arion-compose.cabal | 22 ++++++++++++---------- nix/ci.nix | 9 ++++++--- nix/haskell-overlay.nix | 12 ++++++++++++ src/haskell/exe/Main.hs | 18 ++++++------------ src/haskell/lib/Arion/Aeson.hs | 2 -- src/haskell/lib/Arion/DockerCompose.hs | 20 +------------------- src/haskell/lib/Arion/Images.hs | 1 - src/haskell/lib/Arion/Nix.hs | 24 +++++++++--------------- src/haskell/lib/Arion/Services.hs | 4 ---- src/haskell/test/Arion/NixSpec.hs | 9 ++------- src/haskell/test/TestMain.hs | 1 + 11 files changed, 49 insertions(+), 73 deletions(-) diff --git a/arion-compose.cabal b/arion-compose.cabal index 2ff2f0b..853bb3a 100644 --- a/arion-compose.cabal +++ b/arion-compose.cabal @@ -1,9 +1,9 @@ cabal-version: 2.4 name: arion-compose -version: 0.1.0.0 +version: 0.1.0.0 synopsis: Run docker-compose with help from Nix/NixOS --- description: +description: Arion is a tool for building and running applications that consist of multiple docker containers using NixOS modules. It has special support for docker images that are built with Nix, for a smooth development experience and improved performance. homepage: https://github.com/hercules-ci/arion#readme -- bug-reports: license: Apache-2.0 @@ -11,10 +11,10 @@ license-file: LICENSE author: Robert Hensing maintainer: robert@hercules-ci.com -- copyright: --- category: -extra-source-files: CHANGELOG.md, README.asciidoc -write-ghc-enviroment-files: - never +category: Distribution, Network, Cloud, Distributed Computing +extra-source-files: CHANGELOG.md, README.asciidoc, + src/haskell/testdata/**/*.nix + src/haskell/testdata/**/*.json data-files: nix/*.nix , nix/modules/composition/*.nix , nix/modules/nixos/*.nix @@ -24,7 +24,7 @@ data-files: nix/*.nix -- all data is verbatim from some sources data-dir: src -common deps +common common build-depends: base ^>=4.12.0.0 , aeson , aeson-pretty @@ -38,25 +38,27 @@ common deps , text , protolude , unix + ghc-options: -Wall flag ghci default: False manual: True library - import: deps + import: common exposed-modules: Arion.Nix Arion.Aeson Arion.DockerCompose Arion.Images Arion.Services other-modules: Paths_arion_compose + autogen-modules: Paths_arion_compose -- other-extensions: hs-source-dirs: src/haskell/lib default-language: Haskell2010 executable arion - import: deps + import: common main-is: Main.hs -- other-modules: -- other-extensions: @@ -66,7 +68,7 @@ executable arion default-language: Haskell2010 test-suite arion-unit-tests - import: deps + import: common if flag(ghci) hs-source-dirs: src/haskell/lib ghc-options: -Wno-missing-home-modules diff --git a/nix/ci.nix b/nix/ci.nix index 4cf9309..a478fff 100644 --- a/nix/ci.nix +++ b/nix/ci.nix @@ -7,6 +7,7 @@ in dimension "Nixpkgs version" { "nixos-19_03" = { nixpkgsSource = "nixpkgs"; + isReferenceNixpkgs = true; }; "nixos-unstable" = { nixpkgsSource = "nixos-unstable"; @@ -16,15 +17,15 @@ dimension "Nixpkgs version" { enableDoc = false; }; } ( - _name: { nixpkgsSource, enableDoc ? true }: + _name: { nixpkgsSource, isReferenceNixpkgs ? false, enableDoc ? true }: dimension "System" { - "x86_64-linux" = {}; + "x86_64-linux" = { isReferenceTarget = isReferenceNixpkgs; }; # TODO: darwin # "x86_64-darwin" = { enableNixOSTests = false; }; } ( - system: {}: + system: { isReferenceTarget ? false }: let pkgs = import ./. { inherit system; nixpkgsSrc = sources.${nixpkgsSource}; }; in @@ -32,6 +33,8 @@ dimension "Nixpkgs version" { inherit (pkgs) arion tests; } // lib.optionalAttrs enableDoc { doc = pkgs.recurseIntoAttrs (import ../doc { inherit pkgs; }); + } // lib.optionalAttrs isReferenceTarget { + inherit (pkgs.arion-project.haskellPkgs) arion-compose-checked; } ) ) diff --git a/nix/haskell-overlay.nix b/nix/haskell-overlay.nix index c2d82cb..7d5ba27 100644 --- a/nix/haskell-overlay.nix +++ b/nix/haskell-overlay.nix @@ -1,4 +1,16 @@ self: super: hself: hsuper: { arion-compose = import ./haskell-arion-compose.nix { pkgs = self; haskellPackages = hself; }; + arion-compose-checked = + let pkg = super.haskell.lib.buildStrictly hself.arion-compose; + checked = super.haskell.lib.overrideCabal pkg (o: { + postConfigure = ''${o.postConfigure or ""} + if ! ${hsuper.cabal-install}/bin/cabal check; + then + echo 1>&2 ERROR: cabal file is invalid. Above warnings were errors. + exit 1 + fi + ''; + }); + in checked; } \ No newline at end of file diff --git a/src/haskell/exe/Main.hs b/src/haskell/exe/Main.hs index 57fcada..6f806c6 100644 --- a/src/haskell/exe/Main.hs +++ b/src/haskell/exe/Main.hs @@ -12,20 +12,13 @@ import qualified Arion.DockerCompose as DockerCompose import Arion.Services (getDefaultExec) import Options.Applicative -import Control.Applicative import Control.Monad.Fail -import qualified Data.Aeson.Encode.Pretty import qualified Data.Text as T import qualified Data.Text.IO as T -import qualified Data.Text.Lazy as TL -import qualified Data.Text.Lazy.Builder as TB -import qualified Data.List.NonEmpty as NE import Data.List.NonEmpty (NonEmpty(..)) -import Control.Arrow ((>>>)) - import System.Posix.User (getRealUserID) data CommonOptions = @@ -69,6 +62,7 @@ parseOptions = do let nixArgs = userNixArgs <|> "--show-trace" <$ guard showTrace in CommonOptions{..} +textArgument :: Mod ArgumentFields [Char] -> Parser Text textArgument = fmap T.pack . strArgument parseCommand :: Parser (CommonOptions -> IO ()) @@ -124,18 +118,18 @@ commandDC -> Text -> Text -> Mod CommandFields (CommonOptions -> IO ()) -commandDC run cmdStr help = +commandDC run cmdStr helpText = command (T.unpack cmdStr) (info (run cmdStr <$> parseDockerComposeArgs) - (progDesc (T.unpack help) <> fullDesc <> forwardOptions)) + (progDesc (T.unpack helpText) <> fullDesc <> forwardOptions)) -------------------------------------------------------------------------------- runDC :: Text -> DockerComposeArgs -> CommonOptions -> IO () -runDC cmd (DockerComposeArgs args) opts = do +runDC cmd (DockerComposeArgs args) _opts = do DockerCompose.run DockerCompose.Args { files = [] , otherArgs = [cmd] ++ args @@ -265,7 +259,7 @@ runExec detach privileged user noTTY index envs workDir service commandAndArgs o main :: IO () main = - (join . execParser) (info (parseAll <**> helper) fullDesc) + (join . arionExecParser) (info (parseAll <**> helper) fullDesc) where - execParser = customExecParser (prefs showHelpOnEmpty) + arionExecParser = customExecParser (prefs showHelpOnEmpty) diff --git a/src/haskell/lib/Arion/Aeson.hs b/src/haskell/lib/Arion/Aeson.hs index dd3ae12..02c9b89 100644 --- a/src/haskell/lib/Arion/Aeson.hs +++ b/src/haskell/lib/Arion/Aeson.hs @@ -4,11 +4,9 @@ import Prelude () import Data.Aeson import qualified Data.ByteString.Lazy as BL import qualified Data.Text.Lazy as TL -import qualified Data.Text.Lazy.IO as TL import qualified Data.Text.Lazy.Builder as TB import qualified Data.Aeson.Encode.Pretty import Data.Aeson.Encode.Pretty ( defConfig - , keyOrder , confCompare , confTrailingNewline ) diff --git a/src/haskell/lib/Arion/DockerCompose.hs b/src/haskell/lib/Arion/DockerCompose.hs index b7cce7f..f44d86f 100644 --- a/src/haskell/lib/Arion/DockerCompose.hs +++ b/src/haskell/lib/Arion/DockerCompose.hs @@ -3,24 +3,7 @@ module Arion.DockerCompose where import Prelude ( ) import Protolude -import Arion.Aeson ( pretty ) -import Data.Aeson -import qualified Data.String import System.Process -import qualified Data.ByteString as BS -import qualified Data.ByteString.Lazy as BL -import Paths_arion_compose -import Control.Applicative - -import qualified Data.Text as T -import qualified Data.Text.IO as T - -import qualified Data.List.NonEmpty as NE -import Data.List.NonEmpty ( NonEmpty(..) ) - -import Control.Arrow ( (>>>) ) -import System.IO.Temp ( withTempFile ) -import System.IO ( hClose ) data Args = Args { files :: [FilePath] @@ -43,6 +26,5 @@ run args = do case exitCode of ExitSuccess -> pass ExitFailure 1 -> exitFailure - e@ExitFailure {} -> do + ExitFailure {} -> do throwIO $ FatalError $ "docker-compose failed with " <> show exitCode - exitWith e diff --git a/src/haskell/lib/Arion/Images.hs b/src/haskell/lib/Arion/Images.hs index 369d09f..a533cec 100644 --- a/src/haskell/lib/Arion/Images.hs +++ b/src/haskell/lib/Arion/Images.hs @@ -10,7 +10,6 @@ import Protolude hiding (to) import qualified Data.Aeson as Aeson import Arion.Aeson (decodeFile) -import qualified Data.ByteString as BS import qualified System.Process as Process import Control.Lens diff --git a/src/haskell/lib/Arion/Nix.hs b/src/haskell/lib/Arion/Nix.hs index a90343a..dbc9103 100644 --- a/src/haskell/lib/Arion/Nix.hs +++ b/src/haskell/lib/Arion/Nix.hs @@ -16,12 +16,9 @@ import Data.Aeson import qualified Data.String import qualified System.Directory as Directory import System.Process -import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy as BL import Paths_arion_compose -import Control.Applicative -import qualified Data.Text as T import qualified Data.Text.IO as T import qualified Data.List.NonEmpty as NE @@ -76,21 +73,20 @@ evaluateComposition ea = do case exitCode of ExitSuccess -> pass ExitFailure 1 -> exitFailure - e@ExitFailure {} -> do + ExitFailure {} -> do throwIO $ FatalError $ "evaluation failed with " <> show exitCode - exitWith e case v of Right r -> pure r - Left e -> throwIO $ FatalError "Couldn't parse nix-instantiate output" + Left e -> throwIO $ FatalError ("Couldn't parse nix-instantiate output" <> show e) -- | Run with docker-compose.yaml tmpfile withEvaluatedComposition :: EvaluationArgs -> (FilePath -> IO r) -> IO r withEvaluatedComposition ea f = do v <- evaluateComposition ea - withTempFile "." ".tmp-arion-docker-compose.yaml" $ \path handle -> do - T.hPutStrLn handle (pretty v) - hClose handle + withTempFile "." ".tmp-arion-docker-compose.yaml" $ \path yamlHandle -> do + T.hPutStrLn yamlHandle (pretty v) + hClose yamlHandle f path @@ -117,15 +113,14 @@ buildComposition outLink ea = do case exitCode of ExitSuccess -> pass ExitFailure 1 -> exitFailure - e@ExitFailure {} -> do + ExitFailure {} -> do throwIO $ FatalError $ "nix-build failed with " <> show exitCode - exitWith e -- | Do something with a docker-compose.yaml. withBuiltComposition :: EvaluationArgs -> (FilePath -> IO r) -> IO r withBuiltComposition ea f = do - withTempFile "." ".tmp-arion-docker-compose.yaml" $ \path handle -> do - hClose handle + withTempFile "." ".tmp-arion-docker-compose.yaml" $ \path emptyYamlHandle -> do + hClose emptyYamlHandle -- Known problem: kills atomicity of withTempFile; won't fix because we should manage gc roots, -- impl of which will probably avoid this "problem". It seems unlikely to cause issues. Directory.removeFile path @@ -149,9 +144,8 @@ replForComposition ea = do case exitCode of ExitSuccess -> pass ExitFailure 1 -> exitFailure - e@ExitFailure {} -> do + ExitFailure {} -> do throwIO $ FatalError $ "nix repl failed with " <> show exitCode - exitWith e argArgs :: EvaluationArgs -> [[Char]] argArgs ea = diff --git a/src/haskell/lib/Arion/Services.hs b/src/haskell/lib/Arion/Services.hs index f63e6e2..d8ecb30 100644 --- a/src/haskell/lib/Arion/Services.hs +++ b/src/haskell/lib/Arion/Services.hs @@ -10,13 +10,9 @@ import Protolude hiding (to) import qualified Data.Aeson as Aeson import Arion.Aeson (decodeFile) -import qualified Data.ByteString as BS -import qualified System.Process as Process import Control.Lens import Data.Aeson.Lens -import Data.String -import System.IO (withFile, IOMode(ReadMode)) -- | Subject to change getDefaultExec :: FilePath -> Text -> IO [Text] diff --git a/src/haskell/test/Arion/NixSpec.hs b/src/haskell/test/Arion/NixSpec.hs index 884a68a..f5c3887 100644 --- a/src/haskell/test/Arion/NixSpec.hs +++ b/src/haskell/test/Arion/NixSpec.hs @@ -6,16 +6,11 @@ where import Protolude import Test.Hspec -import Test.QuickCheck import qualified Data.List.NonEmpty as NEL import Arion.Aeson import Arion.Nix import qualified Data.Text as T import qualified Data.Text.IO as T -import qualified Data.Text.Lazy.IO as TL -import qualified Data.Text.Lazy.Builder as TB -import qualified Data.Aeson.Encode.Pretty -import Data.Char (isSpace) spec :: Spec spec = describe "evaluateComposition" $ it "matches an example" $ do @@ -32,8 +27,8 @@ spec = describe "evaluateComposition" $ it "matches an example" $ do expected <- T.readFile "src/haskell/testdata/Arion/NixSpec/arion-compose.json" censorPaths actual `shouldBe` censorPaths expected +censorPaths :: Text -> Text censorPaths = censorImages . censorStorePaths ---censorPaths = censorStorePaths censorStorePaths :: Text -> Text censorStorePaths x = case T.breakOn "/nix/store/" x of @@ -61,4 +56,4 @@ isNixNameChar c | c >= 'A' && c <= 'Z' = True isNixNameChar c | c == '-' = True isNixNameChar c | c == '.' = True isNixNameChar c | c == '_' = True -- WRONG? -isNixNameChar c = False -- WRONG? +isNixNameChar _ = False -- WRONG? diff --git a/src/haskell/test/TestMain.hs b/src/haskell/test/TestMain.hs index 746b8d7..e0303fa 100644 --- a/src/haskell/test/TestMain.hs +++ b/src/haskell/test/TestMain.hs @@ -1,5 +1,6 @@ module Main where +import Prelude() import Protolude import Test.Hspec.Runner import qualified Spec From 0ab8ad6bddaffbb6e1d8fed61dcecf2962f7797a Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 4 Oct 2019 19:09:52 +0200 Subject: [PATCH 5/7] Update changelog --- CHANGELOG.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c8d48d..73df568 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Revision history for arion-compose -## 0.1.0.0 -- YYYY-mm-dd +## Unreleased -* First version. Released on an unsuspecting world. -* *BREAKING:* useHostStore now uses a proper empty base image, like `scratch`. + + +## 0.1.0.0 -- 2019-10-04 + +* First released version. Released on an unsuspecting world. From e21b1b4e75394309acaa8598582915f45307f88a Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 4 Oct 2019 19:29:09 +0200 Subject: [PATCH 6/7] Add nixos-19.09 --- nix/ci.nix | 9 ++++++++- nix/sources.json | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/nix/ci.nix b/nix/ci.nix index a478fff..a8bca06 100644 --- a/nix/ci.nix +++ b/nix/ci.nix @@ -9,10 +9,17 @@ dimension "Nixpkgs version" { nixpkgsSource = "nixpkgs"; isReferenceNixpkgs = true; }; + "nixos-19_09" = { + nixpkgsSource = "nixos-19.09"; + + # Broken since 19.09, wontfix because doc tooling will be changed. + # TODO: reenable + enableDoc = false; + }; "nixos-unstable" = { nixpkgsSource = "nixos-unstable"; - # Broken on unstable, wontfix because doc tooling will be changed. + # Broken since 19.09, wontfix because doc tooling will be changed. # TODO: reenable enableDoc = false; }; diff --git a/nix/sources.json b/nix/sources.json index 9306c4b..7e4b088 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -11,6 +11,18 @@ "url": "https://github.com/nmattia/niv/archive/1dd094156b249586b66c16200ecfd365c7428dc0.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, + "nixos-19.09": { + "branch": "nixos-19.09", + "description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to", + "homepage": "https://github.com/NixOS/nixpkgs", + "owner": "NixOS", + "repo": "nixpkgs-channels", + "rev": "3ba0d9f75ccffd41e32cfea4046805f8bbab12f5", + "sha256": "0w20drs4mwlq12k1sss1x8adyf5ph5jd52n8wdcgmn4sm60qjmki", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs-channels/archive/3ba0d9f75ccffd41e32cfea4046805f8bbab12f5.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, "nixos-unstable": { "branch": "nixos-unstable", "description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to", From cc07068beb803a1b918b1745af430c94156352a3 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 4 Oct 2019 20:18:25 +0200 Subject: [PATCH 7/7] Bump to v0.1.0.0 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73df568..89b07db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# Revision history for arion-compose +# Revision history for Arion ## Unreleased