diff --git a/cabal.project b/cabal.project index d4ee776..80a713b 100644 --- a/cabal.project +++ b/cabal.project @@ -1,2 +1,3 @@ -allow-newer: servant, servant-server, *:servant-server, *:base, lucid-htmx:* -packages: rcv-site.cabal +packages: + ./ +allow-newer: servant, servant-server, *:servant-server, *:base, lucid-htmx:*, beam:* diff --git a/flake.lock b/flake.lock index 1bb3800..f64ec30 100644 --- a/flake.lock +++ b/flake.lock @@ -1,58 +1,78 @@ { "nodes": { - "flake-utils": { + "flake-parts": { "inputs": { - "systems": "systems" + "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1689068808, - "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "lastModified": 1690933134, + "narHash": "sha256-ab989mN63fQZBFrkk4Q8bYxQCktuHmBIBqUG1jl6/FQ=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "59cf3f1447cfc75087e7273b04b31e689a8599fb", "type": "github" }, "original": { - "owner": "numtide", - "repo": "flake-utils", + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "haskell-flake": { + "locked": { + "lastModified": 1690398210, + "narHash": "sha256-1wnx2K3U2xmUI5rUulOZ66tcIva+OGWS47dyHdZJjsA=", + "owner": "srid", + "repo": "haskell-flake", + "rev": "d3c8d8be31d3a5dcf9d49e9dacfc570b5c736658", + "type": "github" + }, + "original": { + "owner": "srid", + "repo": "haskell-flake", "type": "github" } }, "nixpkgs": { "locked": { - "lastModified": 1690924695, - "narHash": "sha256-1yshNzds/qJztMoJk0Sa2xhKwSLaOAuepR6ABWbrgRU=", - "owner": "NixOS", + "lastModified": 1691403902, + "narHash": "sha256-J74y4xWtKPDPyVtF4arzrwuSOGznlFlJ+uB9RwNNnbo=", + "owner": "nixos", "repo": "nixpkgs", - "rev": "7282565b1ca9ba7b293b899411e70167f4a7c1ff", + "rev": "c91024273f020df2dcb209cc133461ca17848026", "type": "github" }, "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1690881714, + "narHash": "sha256-h/nXluEqdiQHs1oSgkOOWF+j8gcJMWhwnZ9PFabN6q0=", "owner": "NixOS", "repo": "nixpkgs", + "rev": "9e1960bc196baf6881340d53dccb203a951745a2", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", "type": "github" } }, "root": { "inputs": { - "flake-utils": "flake-utils", + "flake-parts": "flake-parts", + "haskell-flake": "haskell-flake", "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", diff --git a/flake.nix b/flake.nix index 398885b..2258bb8 100644 --- a/flake.nix +++ b/flake.nix @@ -1,43 +1,53 @@ -# SPDX-FileCopyrightText: 2021 Serokell -# -# SPDX-License-Identifier: CC0-1.0 - { - description = "My haskell application"; - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs"; - flake-utils.url = "github:numtide/flake-utils"; + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; + haskell-flake.url = "github:srid/haskell-flake"; }; + outputs = inputs@{ self, nixpkgs, flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = nixpkgs.lib.systems.flakeExposed; + imports = [ inputs.haskell-flake.flakeModule ]; - outputs = { self, nixpkgs, flake-utils }: - flake-utils.lib.eachDefaultSystem (system: - let - pkgs = nixpkgs.legacyPackages.${system}; + perSystem = { self', pkgs, ... }: { - haskellPackages = pkgs.haskellPackages; + # Typically, you just want a single project named "default". But + # multiple projects are also possible, each using different GHC version. + haskellProjects.default = { + # The base package set representing a specific GHC version. + # By default, this is pkgs.haskellPackages. + # You may also create your own. See https://zero-to-flakes.com/haskell-flake/package-set + # basePackages = pkgs.haskellPackages; - jailbreakUnbreak = pkg: - pkgs.haskell.lib.doJailbreak (pkg.overrideAttrs (_: { meta = { }; })); + # Extra package information. See https://zero-to-flakes.com/haskell-flake/dependency + # + # Note that local packages are automatically included in `packages` + # (defined by `defaults.packages` option). + # + # packages = { + # base.source = "4.17.0.0"; # Hackage version override + # }; + # settings = { + # beam = { + # broken = false; + # jailbreak = true; + # }; + # }; - # DON'T FORGET TO PUT YOUR PACKAGE NAME HERE, REMOVING `throw` - packageName = "rcv-site"; - in { - packages.${packageName} = - haskellPackages.callCabal2nix packageName self rec { - # Dependency overrides go here + devShell = { + # Enabled by default + enable = true; + + # Programs you want to make available in the shell. + # Default programs can be disabled by setting to 'null' + tools = hp: { sqlite = pkgs.sqlite; haskell-language-server = pkgs.haskell-language-server ; ghcid = null; }; + + hlsCheck.enable = true; }; - - 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 - cabal-install - ]; - inputsFrom = map (__getAttr "env") (__attrValues self.packages.${system}); }; - devShell = self.devShells.${system}.default; - }); + + # haskell-flake doesn't set the default package, but you can do it here. + packages.default = self'.packages.rcv-site; + }; + }; } diff --git a/rcv-site.cabal b/rcv-site.cabal index c55ab04..75b32ca 100644 --- a/rcv-site.cabal +++ b/rcv-site.cabal @@ -39,6 +39,9 @@ executable rcv-site build-depends: acid-state, aeson, + -- beam-sqlite, + -- beam-core, + -- sqlite-simple, async, base, bytestring, @@ -70,6 +73,7 @@ executable rcv-site other-modules: API Database + -- BeamDatabase InstantRunoff Error Poll diff --git a/src/Main.hs b/src/Main.hs index 0cb46d4..cbbd59d 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -233,17 +233,10 @@ emptyApp _ respondf = respondf $ NW.responseLBS TS.status200 [] "redirecting to main :: IO () main = do env <- getEnv - opts <- S.getArgs M.void . liftIO $ Ac.update (db env) (DB.CreatePoll examplePoll (P.PollId 7)) M.void . liftIO $ Ac.update (db env) (DB.PostBallot (P.PollId 7) (B.Ballot ["blue", "green", "yellow", "orange", "pink"])) M.void . liftIO $ Ac.update (db env) (DB.PostBallot (P.PollId 7) (B.Ballot ["blue", "red", "pink", "purple", "green"])) M.void . liftIO $ Ac.update (db env) (DB.PostBallot (P.PollId 7) (B.Ballot ["purple", "black", "yellow", "orange", "blue"])) - print =<< Ac.query (db env) (DB.GetPoll (P.PollId 14836861905326358375)) mapM_ print =<< (liftIO . Ac.query (db env) $ DB.GetPollIds) let application = serve api . hoistServer api (runWithEnv env) $ server - case opts of -- TODO: allow more command-line options like tls & domain - ["--with-tls"] -> do - httpsSite <- A.async $ WTLS.runTLS tlsSettings warpSettings application - httpSite <- A.async $ W.run 80 $ TLS.forceSSL emptyApp - M.void $ A.waitAny [httpsSite, httpSite] - _ -> W.run 8080 application + W.run 8080 application