git.iko.soy/purestack-dev/project-m36-rest
on master help sign in
flake.lock+17−1
since splitsnapshots
unifiedsplit
@@ -35,7 +35,23 @@
35 "root": {
35 "root": {
36 "inputs": {
36 "inputs": {
37 "flake-utils": "flake-utils",
37 "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"
39 }
55 }
40 },
56 },
41 "systems": {
57 "systems": {
flake.nix+44−2
@@ -2,16 +2,53 @@
2 inputs = {
2 inputs = {
3 nixpkgs.url = "nixpkgs/nixos-unstable";
3 nixpkgs.url = "nixpkgs/nixos-unstable";
4 flake-utils.url = "flake-utils";
4 flake-utils.url = "flake-utils";
5+ stacklock2nix.url = "github:cdepillabout/stacklock2nix";
5 };
6 };
6
7
7− outputs = { self, flake-utils, nixpkgs }:
8+ outputs = { self, flake-utils, nixpkgs, stacklock2nix }:
8 let
9 let
9 supportedSystems =
10 supportedSystems =
10 [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" "aarch64-linux" ];
11 [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" "aarch64-linux" ];
11 compilerVersion = "966";
12 compilerVersion = "966";
12 in flake-utils.lib.eachSystem supportedSystems (system:
13 in flake-utils.lib.eachSystem supportedSystems (system:
14+ let
13− let pkgs = import nixpkgs { inherit system; };
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; }));
14 in {
28 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+ };
15 devShells.default = pkgs.mkShell {
52 devShells.default = pkgs.mkShell {
16 buildInputs = with pkgs; [
53 buildInputs = with pkgs; [
17 haskell.compiler."ghc${compilerVersion}"
54 haskell.compiler."ghc${compilerVersion}"
@@ -21,4 +58,9 @@
21 ];
58 ];
22 };
59 };
23 });
60 });
61+ nixConfig = {
62+ extra-substituters = [ "https://cache.garnix.io" ];
63+ extra-trusted-public-keys =
64+ [ "cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g=" ];
65+ };
24}
66}
package.yaml+1
@@ -15,6 +15,7 @@ library:
15 - base64
15 - base64
16 - text
16 - text
17 - containers
17 - containers
18+ - wai-logger
18
19
19executable:
20executable:
20 main: Main.hs
21 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
19import Data.Vector qualified as V
19import Data.Vector qualified as V
20import GHC.Generics (Generic)
20import GHC.Generics (Generic)
21import Network.Wai.Handler.Warp qualified as Warp
21import Network.Wai.Handler.Warp qualified as Warp
22+import Network.Wai.Logger (withStdoutLogger)
22import Options.Applicative
23import Options.Applicative
23import ProjectM36.Base
24import ProjectM36.Base
24import ProjectM36.Client
25import ProjectM36.Client
@@ -97,25 +98,23 @@ encodeRelation (Relation (Attributes attrs) (RelationTupleSet tuples)) =
97 "vals" A..= (tuples <&> (\(RelationTuple _ atoms) -> encodeAtom <$> atoms))
98 "vals" A..= (tuples <&> (\(RelationTuple _ atoms) -> encodeAtom <$> atoms))
98 ]
99 ]
99
100
100−decodeRelationType :: A.Array -> A.Parser (V.Vector Attribute)
101+decodeRelationType :: V.Vector (Text, A.Value) -> A.Parser (V.Vector Attribute)
101−decodeRelationType o =
102+decodeRelationType =
102− traverse parseJSON o
103+ traverse
103− >>= traverse
104− ( \(key, v) ->
104+ ( \(key, v) ->
105− Attribute (Key.toText key) <$> case v of
105+ Attribute key <$> case v of
106− A.String "int" -> pure IntAtomType
106+ A.String "int" -> pure IntAtomType
107− A.String "integer" -> pure IntegerAtomType
107+ A.String "integer" -> pure IntegerAtomType
108− A.String "scientific" -> pure ScientificAtomType
108+ A.String "scientific" -> pure ScientificAtomType
109− A.String "double" -> pure DoubleAtomType
109+ A.String "double" -> pure DoubleAtomType
110− A.String "text" -> pure TextAtomType
110+ A.String "text" -> pure TextAtomType
111− A.String "day" -> pure DayAtomType
111+ A.String "day" -> pure DayAtomType
112− A.String "datetime" -> pure DateTimeAtomType
112+ A.String "datetime" -> pure DateTimeAtomType
113− A.String "bytestring" -> pure ByteStringAtomType
113+ A.String "bytestring" -> pure ByteStringAtomType
114− A.String "bool" -> pure BoolAtomType
114+ A.String "bool" -> pure BoolAtomType
115− A.String "uuid" -> pure UUIDAtomType
115+ A.String "uuid" -> pure UUIDAtomType
116− A.Array x -> RelationAtomType . Attributes <$> decodeRelationType x
116+ x -> parseJSON x >>= fmap (RelationAtomType . Attributes) . decodeRelationType
117− _ -> fail $ "unknown type: " <> show v
118− )
117+ )
119
118
120decodeExpr :: A.Value -> A.Parser RelationalExpr
119decodeExpr :: A.Value -> A.Parser RelationalExpr
121decodeExpr = withObject "Expr" $ \o -> case KeyMap.toList o of
120decodeExpr = withObject "Expr" $ \o -> case KeyMap.toList o of
@@ -225,8 +224,12 @@ run = do
225 Right x -> pure x
224 Right x -> pure x
226 )
225 )
227 close
226 close
228− ( \conn ->
227+ ( \conn -> withStdoutLogger $ \logger ->
229 Warp.runSettings
228 Warp.runSettings
229+ ( Warp.defaultSettings
230− (Warp.defaultSettings & Warp.setServerName "project-m36-rest" & Warp.setPort opts.port)
230+ & Warp.setServerName "project-m36-rest"
231+ & Warp.setPort opts.port
232+ & Warp.setLogger logger
233+ )
231 (genericServe (server conn))
234 (genericServe (server conn))
232 )
235 )