From 6865af361dc944116f747a683a900be788e0d8a5 Mon Sep 17 00:00:00 2001 From: Mats Rauhala Date: Wed, 29 Aug 2018 22:43:44 +0300 Subject: [PATCH 1/3] Support for multiproject builds with nix - Closes #28 --- backend/ChangeLog.md | 5 ++ backend/LICENSE | 30 +++++++++ backend/Setup.hs | 2 + ebook-manager.cabal => backend/backend.cabal | 12 ++-- {src => backend/src}/API.hs | 0 {src => backend/src}/API/Books.hs | 0 {src => backend/src}/API/Catalogue.hs | 0 {src => backend/src}/API/Channels.hs | 0 {src => backend/src}/API/Users.hs | 0 {src => backend/src}/Database.hs | 0 {src => backend/src}/Database/Book.hs | 0 {src => backend/src}/Database/Channel.hs | 0 {src => backend/src}/Database/Schema.hs | 0 {src => backend/src}/Database/Tag.hs | 0 {src => backend/src}/Database/User.hs | 0 {src => backend/src}/Datastore.hs | 0 {src => backend/src}/Devel/Main.hs | 2 +- {src => backend/src}/Main.hs | 0 {src => backend/src}/Servant/XML.hs | 0 {src => backend/src}/Server.hs | 0 {src => backend/src}/Server/Auth.hs | 0 {src => backend/src}/Types.hs | 0 {src => backend/src}/View.hs | 0 common/LICENSE | 30 +++++++++ common/common.cabal | 65 ++++++++++++++++++++ {src => common/src}/Configuration.hs | 0 {src => common/src}/Data/Versioned.hs | 0 default.nix | 16 +++-- project.nix | 37 +++++++++++ release.nix | 15 +++++ 30 files changed, 199 insertions(+), 15 deletions(-) create mode 100644 backend/ChangeLog.md create mode 100644 backend/LICENSE create mode 100644 backend/Setup.hs rename ebook-manager.cabal => backend/backend.cabal (92%) rename {src => backend/src}/API.hs (100%) rename {src => backend/src}/API/Books.hs (100%) rename {src => backend/src}/API/Catalogue.hs (100%) rename {src => backend/src}/API/Channels.hs (100%) rename {src => backend/src}/API/Users.hs (100%) rename {src => backend/src}/Database.hs (100%) rename {src => backend/src}/Database/Book.hs (100%) rename {src => backend/src}/Database/Channel.hs (100%) rename {src => backend/src}/Database/Schema.hs (100%) rename {src => backend/src}/Database/Tag.hs (100%) rename {src => backend/src}/Database/User.hs (100%) rename {src => backend/src}/Datastore.hs (100%) rename {src => backend/src}/Devel/Main.hs (97%) rename {src => backend/src}/Main.hs (100%) rename {src => backend/src}/Servant/XML.hs (100%) rename {src => backend/src}/Server.hs (100%) rename {src => backend/src}/Server/Auth.hs (100%) rename {src => backend/src}/Types.hs (100%) rename {src => backend/src}/View.hs (100%) create mode 100644 common/LICENSE create mode 100644 common/common.cabal rename {src => common/src}/Configuration.hs (100%) rename {src => common/src}/Data/Versioned.hs (100%) create mode 100644 project.nix create mode 100644 release.nix diff --git a/backend/ChangeLog.md b/backend/ChangeLog.md new file mode 100644 index 0000000..213dbd4 --- /dev/null +++ b/backend/ChangeLog.md @@ -0,0 +1,5 @@ +# Revision history for backend + +## 0.1.0.0 -- YYYY-mm-dd + +* First version. Released on an unsuspecting world. diff --git a/backend/LICENSE b/backend/LICENSE new file mode 100644 index 0000000..00aedcc --- /dev/null +++ b/backend/LICENSE @@ -0,0 +1,30 @@ +Copyright (c) 2018, Mats Rauhala + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of Mats Rauhala nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/backend/Setup.hs b/backend/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/backend/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/ebook-manager.cabal b/backend/backend.cabal similarity index 92% rename from ebook-manager.cabal rename to backend/backend.cabal index 4d262ee..7b0d575 100644 --- a/ebook-manager.cabal +++ b/backend/backend.cabal @@ -1,4 +1,7 @@ -name: ebook-manager +-- Initial backend.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/ + +name: backend version: 0.1.0.0 -- synopsis: -- description: @@ -12,7 +15,7 @@ build-type: Simple extra-source-files: ChangeLog.md cabal-version: >=1.10 -executable ebook-manager +executable backend main-is: Main.hs other-modules: Devel.Main , API @@ -20,8 +23,6 @@ executable ebook-manager , API.Catalogue , API.Channels , API.Users - , Configuration - , Data.Versioned , Database , Database.Book , Database.Channel @@ -36,6 +37,7 @@ executable ebook-manager , View -- other-extensions: build-depends: base >=4.10 && <4.11 + , common , aeson , asn1-data , asn1-types @@ -77,8 +79,8 @@ executable ebook-manager , xml-conduit , xml-hamlet hs-source-dirs: src + default-language: Haskell2010 default-extensions: DeriveGeneric , NoImplicitPrelude , OverloadedStrings , RecordWildCards - default-language: Haskell2010 diff --git a/src/API.hs b/backend/src/API.hs similarity index 100% rename from src/API.hs rename to backend/src/API.hs diff --git a/src/API/Books.hs b/backend/src/API/Books.hs similarity index 100% rename from src/API/Books.hs rename to backend/src/API/Books.hs diff --git a/src/API/Catalogue.hs b/backend/src/API/Catalogue.hs similarity index 100% rename from src/API/Catalogue.hs rename to backend/src/API/Catalogue.hs diff --git a/src/API/Channels.hs b/backend/src/API/Channels.hs similarity index 100% rename from src/API/Channels.hs rename to backend/src/API/Channels.hs diff --git a/src/API/Users.hs b/backend/src/API/Users.hs similarity index 100% rename from src/API/Users.hs rename to backend/src/API/Users.hs diff --git a/src/Database.hs b/backend/src/Database.hs similarity index 100% rename from src/Database.hs rename to backend/src/Database.hs diff --git a/src/Database/Book.hs b/backend/src/Database/Book.hs similarity index 100% rename from src/Database/Book.hs rename to backend/src/Database/Book.hs diff --git a/src/Database/Channel.hs b/backend/src/Database/Channel.hs similarity index 100% rename from src/Database/Channel.hs rename to backend/src/Database/Channel.hs diff --git a/src/Database/Schema.hs b/backend/src/Database/Schema.hs similarity index 100% rename from src/Database/Schema.hs rename to backend/src/Database/Schema.hs diff --git a/src/Database/Tag.hs b/backend/src/Database/Tag.hs similarity index 100% rename from src/Database/Tag.hs rename to backend/src/Database/Tag.hs diff --git a/src/Database/User.hs b/backend/src/Database/User.hs similarity index 100% rename from src/Database/User.hs rename to backend/src/Database/User.hs diff --git a/src/Datastore.hs b/backend/src/Datastore.hs similarity index 100% rename from src/Datastore.hs rename to backend/src/Datastore.hs diff --git a/src/Devel/Main.hs b/backend/src/Devel/Main.hs similarity index 97% rename from src/Devel/Main.hs rename to backend/src/Devel/Main.hs index fb20ded..db3f764 100644 --- a/src/Devel/Main.hs +++ b/backend/src/Devel/Main.hs @@ -37,7 +37,7 @@ update = do develMain :: IO () develMain = do - conf <- input auto "./config/devel.dhall" + conf <- input auto "../config/devel.dhall" withApp conf $ \app -> do void $ runReaderT (runDB migrate) app defaultMain app diff --git a/src/Main.hs b/backend/src/Main.hs similarity index 100% rename from src/Main.hs rename to backend/src/Main.hs diff --git a/src/Servant/XML.hs b/backend/src/Servant/XML.hs similarity index 100% rename from src/Servant/XML.hs rename to backend/src/Servant/XML.hs diff --git a/src/Server.hs b/backend/src/Server.hs similarity index 100% rename from src/Server.hs rename to backend/src/Server.hs diff --git a/src/Server/Auth.hs b/backend/src/Server/Auth.hs similarity index 100% rename from src/Server/Auth.hs rename to backend/src/Server/Auth.hs diff --git a/src/Types.hs b/backend/src/Types.hs similarity index 100% rename from src/Types.hs rename to backend/src/Types.hs diff --git a/src/View.hs b/backend/src/View.hs similarity index 100% rename from src/View.hs rename to backend/src/View.hs diff --git a/common/LICENSE b/common/LICENSE new file mode 100644 index 0000000..00aedcc --- /dev/null +++ b/common/LICENSE @@ -0,0 +1,30 @@ +Copyright (c) 2018, Mats Rauhala + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of Mats Rauhala nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/common/common.cabal b/common/common.cabal new file mode 100644 index 0000000..9d9331c --- /dev/null +++ b/common/common.cabal @@ -0,0 +1,65 @@ +name: common +version: 0.1.0.0 +-- synopsis: +-- description: +license: BSD3 +license-file: LICENSE +author: Mats Rauhala +maintainer: mats.rauhala@iki.fi +-- copyright: +category: Web +build-type: Simple +extra-source-files: ChangeLog.md +cabal-version: >=1.10 + +library + exposed-modules: Configuration + , Data.Versioned + -- other-extensions: + build-depends: base >=4.10 && <4.11 + , aeson + , asn1-data + , asn1-types + , bytestring + , classy-prelude + , cryptonite + , dhall + , directory + , foreign-store + , generic-lens + , http-api-data + , http-media + , jose + , lens + , lucid + , memory + , monad-logger + , mtl + , pandoc + , pandoc-types + , pem + , process + , resource-pool + , selda + , selda-postgresql + , servant + , servant-auth + , servant-auth-server + , servant-docs + , servant-lucid + , servant-multipart + , servant-server + , text + , transformers + , wai + , warp + , x509 + , x509-store + , xml-conduit + , xml-hamlet + hs-source-dirs: src + default-extensions: DeriveGeneric + , NoImplicitPrelude + , OverloadedStrings + , RecordWildCards + default-language: Haskell2010 diff --git a/src/Configuration.hs b/common/src/Configuration.hs similarity index 100% rename from src/Configuration.hs rename to common/src/Configuration.hs diff --git a/src/Data/Versioned.hs b/common/src/Data/Versioned.hs similarity index 100% rename from src/Data/Versioned.hs rename to common/src/Data/Versioned.hs diff --git a/default.nix b/default.nix index b4e07db..d75df50 100644 --- a/default.nix +++ b/default.nix @@ -1,10 +1,8 @@ -{ mkDerivation, base, stdenv }: -mkDerivation { - pname = "ebook-manager"; - version = "0.1.0.0"; - src = ./.; - isLibrary = false; - isExecutable = true; - executableHaskellDepends = [ base ]; - license = stdenv.lib.licenses.bsd3; +{ nixpkgs, haskellPackages }: + +(import ./project.nix nixpkgs) { + packages = { + common = ./common; + backend = ./backend; + }; } diff --git a/project.nix b/project.nix new file mode 100644 index 0000000..5541338 --- /dev/null +++ b/project.nix @@ -0,0 +1,37 @@ +nixpkgs: + +let + + inherit (nixpkgs.lib) mapAttrs mapAttrsToList escapeShellArg optionalString concatStringsSep concatMapStringsSep; + +in + +{ packages +, overrides ? _ : _ : {} +}: + +let + + overrides' = nixpkgs.lib.foldr nixpkgs.lib.composeExtensions (_: _: {}) [ + (self: super: mapAttrs (name: path: self.callCabal2nix name path {}) packages) + ]; + haskellPackages = nixpkgs.haskellPackages.override { overrides = overrides'; }; + packages' = mapAttrs (name: _: haskellPackages."${name}") packages; + mkShell = name: pkg: + let + n = "${name}-shell"; + deps = haskellPackages.ghcWithPackages (pkgs: pkg.nativeBuildInputs); + in + { + name = "${n}"; + value = nixpkgs.buildEnv { + name = "${n}"; + paths = []; + buildInputs = [deps]; + }; + }; + shells = nixpkgs.lib.listToAttrs (mapAttrsToList mkShell packages'); + +in + +packages' // shells diff --git a/release.nix b/release.nix new file mode 100644 index 0000000..afd47d4 --- /dev/null +++ b/release.nix @@ -0,0 +1,15 @@ +{ nixpkgs ? import {} }: + +let + + pinnedVersion = nixpkgs.lib.importJSON ./nixpkgs-version.json; + pinnedPkgs = import (nixpkgs.fetchFromGitHub { + owner = "NixOS"; + repo = "nixpkgs"; + inherit (pinnedVersion) rev sha256; + }) {}; + inherit (pinnedPkgs) pkgs; + + in + +import ./default.nix { nixpkgs = pinnedPkgs; haskellPackages = pinnedPkgs.haskellPackages; } -- 2.47.0 From fdbd24a4bfb6ae63109ce76954ddcffb3315540a Mon Sep 17 00:00:00 2001 From: Mats Rauhala Date: Wed, 29 Aug 2018 23:03:24 +0300 Subject: [PATCH 2/3] Tools support for nix --- default.nix | 4 ++++ project.nix | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/default.nix b/default.nix index d75df50..efabd3c 100644 --- a/default.nix +++ b/default.nix @@ -5,4 +5,8 @@ common = ./common; backend = ./backend; }; + tools = with haskellPackages; [ + ghcid + hasktags + ]; } diff --git a/project.nix b/project.nix index 5541338..5e9adde 100644 --- a/project.nix +++ b/project.nix @@ -8,6 +8,7 @@ in { packages , overrides ? _ : _ : {} +, tools ? [] }: let @@ -26,8 +27,8 @@ let name = "${n}"; value = nixpkgs.buildEnv { name = "${n}"; - paths = []; - buildInputs = [deps]; + paths = tools; + buildInputs = tools ++ [deps]; }; }; shells = nixpkgs.lib.listToAttrs (mapAttrsToList mkShell packages'); -- 2.47.0 From f5f6c9ced90d6f53ccdaa4143ab56d7135d0c1a3 Mon Sep 17 00:00:00 2001 From: Mats Rauhala Date: Wed, 29 Aug 2018 23:03:32 +0300 Subject: [PATCH 3/3] Clean up common.cabal --- common/common.cabal | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/common/common.cabal b/common/common.cabal index 9d9331c..fe763b6 100644 --- a/common/common.cabal +++ b/common/common.cabal @@ -17,46 +17,14 @@ library , Data.Versioned -- other-extensions: build-depends: base >=4.10 && <4.11 - , aeson - , asn1-data - , asn1-types - , bytestring , classy-prelude - , cryptonite , dhall - , directory , foreign-store , generic-lens - , http-api-data - , http-media - , jose , lens - , lucid - , memory - , monad-logger , mtl - , pandoc - , pandoc-types - , pem - , process - , resource-pool - , selda - , selda-postgresql - , servant - , servant-auth - , servant-auth-server - , servant-docs - , servant-lucid - , servant-multipart - , servant-server , text , transformers - , wai - , warp - , x509 - , x509-store - , xml-conduit - , xml-hamlet hs-source-dirs: src default-extensions: DeriveGeneric , NoImplicitPrelude -- 2.47.0