Support for multiproject builds with nix

- Closes #28
This commit is contained in:
Mats Rauhala 2018-08-29 22:43:44 +03:00
parent d792cb2a81
commit 6865af361d
Signed by: MasseR
GPG Key ID: 1C18445948FFF87B
30 changed files with 199 additions and 15 deletions

5
backend/ChangeLog.md Normal file
View File

@ -0,0 +1,5 @@
# Revision history for backend
## 0.1.0.0 -- YYYY-mm-dd
* First version. Released on an unsuspecting world.

30
backend/LICENSE Normal file
View File

@ -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.

2
backend/Setup.hs Normal file
View File

@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain

View File

@ -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

View File

@ -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

30
common/LICENSE Normal file
View File

@ -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.

65
common/common.cabal Normal file
View File

@ -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

View File

@ -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;
};
}

37
project.nix Normal file
View File

@ -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

15
release.nix Normal file
View File

@ -0,0 +1,15 @@
{ nixpkgs ? import <nixpkgs> {} }:
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; }