Initial commit

This commit is contained in:
Mats Rauhala 2018-08-02 21:39:08 +03:00
parent 8f3ebb139e
commit 0579b6d3e1
10 changed files with 173 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
dist/

5
ChangeLog.md Normal file
View File

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

30
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
Setup.hs Normal file
View File

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

10
default.nix Normal file
View File

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

45
ebook-manager.cabal Normal file
View File

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

7
nixpkgs-version.json Normal file
View File

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

32
shell.nix Normal file
View File

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

34
src/Devel/Main.hs Normal file
View File

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

7
src/Main.hs Normal file
View File

@ -0,0 +1,7 @@
module Main where
defaultMain :: IO ()
defaultMain = putStrLn "Hello haskell"
main :: IO ()
main = defaultMain