From 0579b6d3e14c96b722b08e4ced4dd56a6befbb14 Mon Sep 17 00:00:00 2001 From: Mats Rauhala Date: Thu, 2 Aug 2018 21:39:08 +0300 Subject: [PATCH] Initial commit --- .gitignore | 1 + ChangeLog.md | 5 +++++ LICENSE | 30 +++++++++++++++++++++++++++++ Setup.hs | 2 ++ default.nix | 10 ++++++++++ ebook-manager.cabal | 45 ++++++++++++++++++++++++++++++++++++++++++++ nixpkgs-version.json | 7 +++++++ shell.nix | 32 +++++++++++++++++++++++++++++++ src/Devel/Main.hs | 34 +++++++++++++++++++++++++++++++++ src/Main.hs | 7 +++++++ 10 files changed, 173 insertions(+) create mode 100644 .gitignore create mode 100644 ChangeLog.md create mode 100644 LICENSE create mode 100644 Setup.hs create mode 100644 default.nix create mode 100644 ebook-manager.cabal create mode 100644 nixpkgs-version.json create mode 100644 shell.nix create mode 100644 src/Devel/Main.hs create mode 100644 src/Main.hs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..849ddff --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +dist/ diff --git a/ChangeLog.md b/ChangeLog.md new file mode 100644 index 0000000..6e4d195 --- /dev/null +++ b/ChangeLog.md @@ -0,0 +1,5 @@ +# Revision history for ebook-manager + +## 0.1.0.0 -- YYYY-mm-dd + +* First version. Released on an unsuspecting world. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..00aedcc --- /dev/null +++ b/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/Setup.hs b/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..b4e07db --- /dev/null +++ b/default.nix @@ -0,0 +1,10 @@ +{ mkDerivation, base, stdenv }: +mkDerivation { + pname = "ebook-manager"; + version = "0.1.0.0"; + src = ./.; + isLibrary = false; + isExecutable = true; + executableHaskellDepends = [ base ]; + license = stdenv.lib.licenses.bsd3; +} diff --git a/ebook-manager.cabal b/ebook-manager.cabal new file mode 100644 index 0000000..2f1701a --- /dev/null +++ b/ebook-manager.cabal @@ -0,0 +1,45 @@ +-- Initial ebook-manager.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/ + +name: ebook-manager +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 + +executable ebook-manager + main-is: Main.hs + other-modules: Devel.Main + -- other-extensions: + build-depends: base >=4.10 && <4.11 + , servant + , servant-server + , servant-docs + , classy-prelude + , cryptonite + , x509 + , x509-store + , asn1-data + , asn1-types + , pem + , mtl + , transformers + , bytestring + , text + , pandoc + , foreign-store + , warp + , wai + , dhall + , lucid + , servant-lucid + hs-source-dirs: src + default-language: Haskell2010 diff --git a/nixpkgs-version.json b/nixpkgs-version.json new file mode 100644 index 0000000..7772ea3 --- /dev/null +++ b/nixpkgs-version.json @@ -0,0 +1,7 @@ +{ + "url": "https://github.com/nixos/nixpkgs.git", + "rev": "83a5765b1fea2472ec9cf9d179d3efd18b45c77e", + "date": "2018-01-08T11:52:28+01:00", + "sha256": "01rb61dkbzjbwnb3p8lgs03a94f4584199dlr0cwdmqzaxnp506h", + "fetchSubmodules": true +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..6f13871 --- /dev/null +++ b/shell.nix @@ -0,0 +1,32 @@ +{ nixpkgs ? import {}, compiler ? "default", doBenchmark ? false }: + +let + + pinnedVersion = nixpkgs.lib.importJSON ./nixpkgs-version.json; + pinnedPkgs = import (nixpkgs.fetchFromGitHub { + owner = "NixOS"; + repo = "nixpkgs"; + inherit (pinnedVersion) rev sha256; + }) {}; + emailparse = nixpkgs.fetchFromGitHub { + owner = "mkawalec"; + repo = "emailparse"; + rev = "c5533707c7339bcebd616e1f7cdb442ca2d16626"; + sha256 = "036a6yx6lqjz2prj85vi1qxcy9ph4mnr0dq1djj3j7y1rqhmgyiq"; + }; + inherit (pinnedPkgs) pkgs; + + + haskellPackages = if compiler == "default" + then pkgs.haskellPackages + else pkgs.haskell.packages.${compiler}; + + f = haskellPackages.callCabal2nix "ebook-manager" ./.; + + variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id; + + drv = variant (haskellPackages.callPackage f {}); + +in + + if pkgs.lib.inNixShell then drv.env else drv diff --git a/src/Devel/Main.hs b/src/Devel/Main.hs new file mode 100644 index 0000000..8df1b6b --- /dev/null +++ b/src/Devel/Main.hs @@ -0,0 +1,34 @@ +module Devel.Main where + +import Main (defaultMain) +import Control.Concurrent +import Control.Monad (void) +import Data.IORef (IORef, newIORef, readIORef, writeIORef) +import Foreign.Store (Store(..), lookupStore, readStore, storeAction, withStore) +import GHC.Word (Word32) + +update :: IO () +update = do + lookupStore tidStoreNum >>= maybe setupNew restart + where + doneStore :: Store (MVar ()) + doneStore = Store 0 + setupNew :: IO () + setupNew = do + done <- storeAction doneStore newEmptyMVar + tid <- start done + void $ storeAction (Store tidStoreNum) (newIORef tid) + restart tidStore = modifyStoredIORef tidStore $ \tid -> do + killThread tid + withStore doneStore takeMVar + readStore doneStore >>= start + start :: MVar () -> IO ThreadId + start done = forkFinally defaultMain (\_ -> putMVar done ()) + +modifyStoredIORef :: Store (IORef a) -> (a -> IO a) -> IO () +modifyStoredIORef store f = withStore store $ \ref -> do + v <- readIORef ref + f v >>= writeIORef ref + +tidStoreNum :: Word32 +tidStoreNum = 1 diff --git a/src/Main.hs b/src/Main.hs new file mode 100644 index 0000000..1b2903d --- /dev/null +++ b/src/Main.hs @@ -0,0 +1,7 @@ +module Main where + +defaultMain :: IO () +defaultMain = putStrLn "Hello haskell" + +main :: IO () +main = defaultMain