git.iko.soy/purestack-dev/project-m36-rest
on master help sign in
5 files changed+87−24
since splitsnapshots
unifiedsplit
flake.lock+17−1 flake.nix+44−2 package.yaml+1 result+1 src/ProjectM36/Rest.hs+24−21
flake.lock+17−1
@@ -35,7 +35,23 @@
3535 "root": {
3636 "inputs": {
3737 "flake-utils": "flake-utils",
38− "nixpkgs": "nixpkgs"
38+ "nixpkgs": "nixpkgs",
39+ "stacklock2nix": "stacklock2nix"
40+ }
41+ },
42+ "stacklock2nix": {
43+ "locked": {
44+ "lastModified": 1743151034,
45+ "narHash": "sha256-2QgpxnOyQg475wd0f/qzgG4fNqce1UearDjzZyrmMG8=",
46+ "owner": "cdepillabout",
47+ "repo": "stacklock2nix",
48+ "rev": "108f6ab6d0208e3842443bea26dfd72b37d82f28",
49+ "type": "github"
50+ },
51+ "original": {
52+ "owner": "cdepillabout",
53+ "repo": "stacklock2nix",
54+ "type": "github"
3955 }
4056 },
4157 "systems": {
flake.nix+44−2
@@ -2,16 +2,53 @@
22 inputs = {
33 nixpkgs.url = "nixpkgs/nixos-unstable";
44 flake-utils.url = "flake-utils";
5+ stacklock2nix.url = "github:cdepillabout/stacklock2nix";
56 };
67
7− outputs = { self, flake-utils, nixpkgs }:
8+ outputs = { self, flake-utils, nixpkgs, stacklock2nix }:
89 let
910 supportedSystems =
1011 [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" "aarch64-linux" ];
1112 compilerVersion = "966";
1213 in flake-utils.lib.eachSystem supportedSystems (system:
13− let pkgs = import nixpkgs { inherit system; };
14+ let
15+ pkgs = import nixpkgs {
16+ inherit system;
17+ overlays = [ stacklock2nix.overlay ];
18+ };
19+ appendGhcFlags = opts: drv:
20+ pkgs.haskell.lib.appendBuildFlag drv
21+ ''--ghc-options="${builtins.concatStringsSep " " opts}"'';
22+ insaneOptimizationFlags =
23+ [ "-O2" "-fexpose-all-unfoldings" "-fspecialise-aggressively" ];
24+ justStatic = package:
25+ (pkgs.haskell.lib.overrideCabal
26+ (pkgs.haskell.lib.justStaticExecutables package)
27+ (drv: { disallowGhcReference = false; }));
1428 in {
29+ packages = {
30+ default = justStatic (pkgs.stacklock2nix {
31+ stackYaml = ./stack.yaml;
32+ baseHaskellPkgSet = pkgs.haskell.packages."ghc${compilerVersion}";
33+ additionalHaskellPkgSetOverrides = (hfinal: hprev:
34+ builtins.mapAttrs (name: value:
35+ if (builtins.tryEval (!(builtins.isAttrs value)
36+ || !(value ? pname))).value or true then
37+ value
38+ else if value ? doCheck && value.pname != "ghc" then
39+ pkgs.lib.pipe value (with pkgs.haskell.lib; [
40+ dontCheck
41+ dontHaddock
42+ doJailbreak
43+ doStrip
44+ disableLibraryProfiling
45+ disableExecutableProfiling
46+ (appendGhcFlags insaneOptimizationFlags)
47+ ])
48+ else
49+ value) hprev);
50+ }).pkgSet.project-m36-rest;
51+ };
1552 devShells.default = pkgs.mkShell {
1653 buildInputs = with pkgs; [
1754 haskell.compiler."ghc${compilerVersion}"
@@ -21,4 +58,9 @@
2158 ];
2259 };
2360 });
61+ nixConfig = {
62+ extra-substituters = [ "https://cache.garnix.io" ];
63+ extra-trusted-public-keys =
64+ [ "cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g=" ];
65+ };
2466}
package.yaml+1
@@ -15,6 +15,7 @@ library:
1515 - base64
1616 - text
1717 - containers
18+ - wai-logger
1819
1920executable:
2021 main: Main.hs
resultnew file+1
@@ -0,0 +1 @@
1+/nix/store/r7qq705mq8sp0l20wmj1b66vxm78zvl8-project-m36-rest-0.0.0
src/ProjectM36/Rest.hs+24−21
@@ -19,6 +19,7 @@ import Data.Traversable
1919import Data.Vector qualified as V
2020import GHC.Generics (Generic)
2121import Network.Wai.Handler.Warp qualified as Warp
22+import Network.Wai.Logger (withStdoutLogger)
2223import Options.Applicative
2324import ProjectM36.Base
2425import ProjectM36.Client
@@ -97,25 +98,23 @@ encodeRelation (Relation (Attributes attrs) (RelationTupleSet tuples)) =
9798 "vals" A..= (tuples <&> (\(RelationTuple _ atoms) -> encodeAtom <$> atoms))
9899 ]
99100
100−decodeRelationType :: A.Array -> A.Parser (V.Vector Attribute)
101−decodeRelationType o =
102− traverse parseJSON o
103− >>= traverse
104− ( \(key, v) ->
105− Attribute (Key.toText key) <$> case v of
106− A.String "int" -> pure IntAtomType
107− A.String "integer" -> pure IntegerAtomType
108− A.String "scientific" -> pure ScientificAtomType
109− A.String "double" -> pure DoubleAtomType
110− A.String "text" -> pure TextAtomType
111− A.String "day" -> pure DayAtomType
112− A.String "datetime" -> pure DateTimeAtomType
113− A.String "bytestring" -> pure ByteStringAtomType
114− A.String "bool" -> pure BoolAtomType
115− A.String "uuid" -> pure UUIDAtomType
116− A.Array x -> RelationAtomType . Attributes <$> decodeRelationType x
117− _ -> fail $ "unknown type: " <> show v
118− )
101+decodeRelationType :: V.Vector (Text, A.Value) -> A.Parser (V.Vector Attribute)
102+decodeRelationType =
103+ traverse
104+ ( \(key, v) ->
105+ Attribute key <$> case v of
106+ A.String "int" -> pure IntAtomType
107+ A.String "integer" -> pure IntegerAtomType
108+ A.String "scientific" -> pure ScientificAtomType
109+ A.String "double" -> pure DoubleAtomType
110+ A.String "text" -> pure TextAtomType
111+ A.String "day" -> pure DayAtomType
112+ A.String "datetime" -> pure DateTimeAtomType
113+ A.String "bytestring" -> pure ByteStringAtomType
114+ A.String "bool" -> pure BoolAtomType
115+ A.String "uuid" -> pure UUIDAtomType
116+ x -> parseJSON x >>= fmap (RelationAtomType . Attributes) . decodeRelationType
117+ )
119118
120119decodeExpr :: A.Value -> A.Parser RelationalExpr
121120decodeExpr = withObject "Expr" $ \o -> case KeyMap.toList o of
@@ -225,8 +224,12 @@ run = do
225224 Right x -> pure x
226225 )
227226 close
228− ( \conn ->
227+ ( \conn -> withStdoutLogger $ \logger ->
229228 Warp.runSettings
230− (Warp.defaultSettings & Warp.setServerName "project-m36-rest" & Warp.setPort opts.port)
229+ ( Warp.defaultSettings
230+ & Warp.setServerName "project-m36-rest"
231+ & Warp.setPort opts.port
232+ & Warp.setLogger logger
233+ )
231234 (genericServe (server conn))
232235 )