[nix] make it build

This commit is contained in:
Dhananjay Balan 2023-11-09 22:29:32 +01:00
parent 12099b5e9e
commit 9cdd10eb0e
6 changed files with 128 additions and 34 deletions

2
.envrc
View File

@ -1 +1 @@
use nix use flake

View File

@ -11,8 +11,7 @@ import Servant
import Control.Monad.IO.Class import Control.Monad.IO.Class
import Servant.HTML.Blaze import Servant.HTML.Blaze
import qualified Data.Text as T import qualified Data.Text as T
import Data.Text.Encoding (decodeUtf8) import Data.Text.Encoding (decodeUtf8, encodeUtf8)
import Crypto.Argon2
import Data.Text.Short (fromText, ShortText) import Data.Text.Short (fromText, ShortText)
import Data.ByteString (ByteString) import Data.ByteString (ByteString)
@ -36,7 +35,7 @@ type API = Get '[HTML] Quote
api :: Proxy API api :: Proxy API
api = Proxy api = Proxy
{-
checkBasicAuth :: T.Text -> ShortText -> BasicAuthCheck User checkBasicAuth :: T.Text -> ShortText -> BasicAuthCheck User
checkBasicAuth user passhash = BasicAuthCheck $ \authData -> checkBasicAuth user passhash = BasicAuthCheck $ \authData ->
let u = decodeUtf8 (basicAuthUsername authData) let u = decodeUtf8 (basicAuthUsername authData)
@ -48,6 +47,20 @@ checkBasicAuth user passhash = BasicAuthCheck $ \authData ->
Argon2Ok -> return $ Authorized $ User u p Argon2Ok -> return $ Authorized $ User u p
_ -> return Unauthorized _ -> return Unauthorized
-}
checkBasicAuth :: T.Text -> ShortText -> BasicAuthCheck User
checkBasicAuth _ _ = BasicAuthCheck $ \_ -> return NoSuchUser
initDb :: FilePath -> IO ()
initDb dbFile = withConnection dbFile $ \conn ->
execute_ conn
[sql|CREATE TABLE IF NOT EXISTS quotes ( quote text non null
, author text
, title text
, page text
, chapter text
, created_on integer);|]
-- | TODO: readerT -- | TODO: readerT
server :: FilePath -> Server API server :: FilePath -> Server API
server dbf = randomQuote dbf server dbf = randomQuote dbf

60
flake.lock Normal file
View File

@ -0,0 +1,60 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1699562885,
"narHash": "sha256-fb7RDv0ePGzayhGvkBh9NrilU3pCecgfbbTNPHprRfg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "97b0ae26f7c8a1682b5437a64edcd73ab1798c9b",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

44
flake.nix Normal file
View File

@ -0,0 +1,44 @@
# SPDX-FileCopyrightText: 2021 Serokell <https://serokell.io/>
#
# SPDX-License-Identifier: CC0-1.0
{
description = "quotes-api";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
haskellPackages = pkgs.haskellPackages;
jailbreakUnbreak = pkg:
pkgs.haskell.lib.doJailbreak (pkg.overrideAttrs (_: { meta = { }; }));
# DON'T FORGET TO PUT YOUR PACKAGE NAME HERE, REMOVING `throw`
packageName = "quptes-api";
in {
packages.${packageName} = haskellPackages.callCabal2nix packageName self
rec {
# Dependency overrides go here
};
packages.default = self.packages.${system}.${packageName};
defaultPackage = self.packages.${system}.default;
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
haskellPackages.haskell-language-server # you must build it with your ghc to work
ghcid
cabal-install
];
inputsFrom =
map (__getAttr "env") (__attrValues self.packages.${system});
};
devShell = self.devShells.${system}.default;
});
}

View File

@ -71,7 +71,7 @@ library
-- other-extensions: -- other-extensions:
-- Other library packages from which modules are imported. -- Other library packages from which modules are imported.
build-depends: base ^>=4.16.3.0, build-depends: base,
text, text,
aeson, aeson,
deriving-aeson, deriving-aeson,
@ -104,10 +104,10 @@ executable quotes-api
-- Other library packages from which modules are imported. -- Other library packages from which modules are imported.
build-depends: build-depends:
base ^>=4.16.3.0, base,
sqlite-simple ^>=0.4.18.0, sqlite-simple,
text ^>=1.2.5.0, text,
servant-server ^>=0.19.1, servant-server,
wai, wai,
warp, warp,
aeson, aeson,
@ -115,7 +115,7 @@ executable quotes-api
quotes-api, quotes-api,
servant-blaze, servant-blaze,
optparse-applicative, optparse-applicative,
argon2 >= 1.3.0, -- argon2,
text-short, text-short,
bytestring, bytestring,
QuickCheck, QuickCheck,
@ -186,5 +186,5 @@ test-suite quotes-api-test
-- Test dependencies. -- Test dependencies.
build-depends: build-depends:
base ^>=4.16.3.0, base,
quotes-api quotes-api

View File

@ -1,23 +0,0 @@
{ pkgs ? import <unstable> {}
}:
pkgs.stdenv.mkDerivation rec {
name = "quotes-api";
nativeBuildInputs = [
];
buildInputs = [
pkgs.zlib
pkgs.ghc
pkgs.cabal-install
pkgs.haskellPackages.ghcid
pkgs.haskellPackages.cabal-plan
pkgs.haskellPackages.haskell-language-server
];
shellHook = ''
export LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath buildInputs}:$LD_LIBRARY_PATH
export LANG=en_US.UTF-8
'';
}