git.iko.soy/purestack-dev/project-m36-rest
on 69f708b help sign in
flake.lock+1−17
since splitsnapshots
unifiedsplit
@@ -35,23 +35,7 @@
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"
55 }
39 }
56 },
40 },
57 "systems": {
41 "systems": {
flake.nix+2−44
@@ -2,53 +2,16 @@
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";
6 };
5 };
7
6
8− outputs = { self, flake-utils, nixpkgs, stacklock2nix }:
7+ outputs = { self, flake-utils, nixpkgs }:
9 let
8 let
10 supportedSystems =
9 supportedSystems =
11 [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" "aarch64-linux" ];
10 [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" "aarch64-linux" ];
12 compilerVersion = "966";
11 compilerVersion = "966";
13 in flake-utils.lib.eachSystem supportedSystems (system:
12 in flake-utils.lib.eachSystem supportedSystems (system:
14− let
15− pkgs = import nixpkgs {
13+ let pkgs = import nixpkgs { inherit system; };
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; }));
28 in {
14 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− };
52 devShells.default = pkgs.mkShell {
15 devShells.default = pkgs.mkShell {
53 buildInputs = with pkgs; [
16 buildInputs = with pkgs; [
54 haskell.compiler."ghc${compilerVersion}"
17 haskell.compiler."ghc${compilerVersion}"
@@ -58,9 +21,4 @@
58 ];
21 ];
59 };
22 };
60 });
23 });
61− nixConfig = {
62− extra-substituters = [ "https://cache.garnix.io" ];
63− extra-trusted-public-keys =
64− [ "cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g=" ];
65− };
66}
24}
package.yaml−1
@@ -15,7 +15,6 @@ library:
15 - base64
15 - base64
16 - text
16 - text
17 - containers
17 - containers
18− - wai-logger
19
18
20executable:
19executable:
21 main: Main.hs
20 main: Main.hs
resultdeleted−1
@@ -1 +0,0 @@
1−/nix/store/r7qq705mq8sp0l20wmj1b66vxm78zvl8-project-m36-rest-0.0.0
src/ProjectM36/Rest.hs+21−24
@@ -19,7 +19,6 @@ 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)
23import Options.Applicative
22import Options.Applicative
24import ProjectM36.Base
23import ProjectM36.Base
25import ProjectM36.Client
24import ProjectM36.Client
@@ -98,23 +97,25 @@ encodeRelation (Relation (Attributes attrs) (RelationTupleSet tuples)) =
98 "vals" A..= (tuples <&> (\(RelationTuple _ atoms) -> encodeAtom <$> atoms))
97 "vals" A..= (tuples <&> (\(RelationTuple _ atoms) -> encodeAtom <$> atoms))
99 ]
98 ]
100
99
101−decodeRelationType :: V.Vector (Text, A.Value) -> A.Parser (V.Vector Attribute)
100+decodeRelationType :: A.Array -> A.Parser (V.Vector Attribute)
102−decodeRelationType =
101+decodeRelationType o =
103− traverse
102+ traverse parseJSON o
103+ >>= traverse
104− ( \(key, v) ->
104+ ( \(key, v) ->
105− Attribute key <$> case v of
105+ Attribute (Key.toText 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− x -> parseJSON x >>= fmap (RelationAtomType . Attributes) . decodeRelationType
116+ A.Array x -> RelationAtomType . Attributes <$> decodeRelationType x
117+ _ -> fail $ "unknown type: " <> show v
117− )
118+ )
118
119
119decodeExpr :: A.Value -> A.Parser RelationalExpr
120decodeExpr :: A.Value -> A.Parser RelationalExpr
120decodeExpr = withObject "Expr" $ \o -> case KeyMap.toList o of
121decodeExpr = withObject "Expr" $ \o -> case KeyMap.toList o of
@@ -224,12 +225,8 @@ run = do
224 Right x -> pure x
225 Right x -> pure x
225 )
226 )
226 close
227 close
227− ( \conn -> withStdoutLogger $ \logger ->
228+ ( \conn ->
228 Warp.runSettings
229 Warp.runSettings
229− ( Warp.defaultSettings
230− & Warp.setServerName "project-m36-rest"
230+ (Warp.defaultSettings & Warp.setServerName "project-m36-rest" & Warp.setPort opts.port)
231− & Warp.setPort opts.port
232− & Warp.setLogger logger
233− )
234 (genericServe (server conn))
231 (genericServe (server conn))
235 )
232 )