initial commit
This commit is contained in:
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
.parcel-cache
|
||||
dist
|
||||
elm-stuff
|
||||
flake.lock
|
||||
node_modules
|
||||
result
|
||||
61
client/default.nix
Normal file
61
client/default.nix
Normal file
@@ -0,0 +1,61 @@
|
||||
{ pkgs }:
|
||||
|
||||
with pkgs;
|
||||
|
||||
let
|
||||
|
||||
|
||||
yarnFilter = p: t: builtins.any (x: baseNameOf p == x) [
|
||||
"package.json"
|
||||
"yarn.lock"
|
||||
];
|
||||
|
||||
yarnSrc = lib.cleanSourceWith {
|
||||
filter = yarnFilter;
|
||||
src = ./.;
|
||||
};
|
||||
|
||||
in
|
||||
rec {
|
||||
shell = buildEnv { name = "homepage-devshell"; paths = homepage.buildInputs; };
|
||||
|
||||
nodeHeaders = fetchzip {
|
||||
name = "node-v${pkgs.nodejs.version}-headers";
|
||||
url = "https://nodejs.org/download/release/v${pkgs.nodejs.version}/node-v${pkgs.nodejs.version}-headers.tar.gz";
|
||||
sha256 = "sha256-wnw/eK+hqawpLbqC+sA65EF7FBz/Q8zvSJfb70dVo4o=";
|
||||
};
|
||||
|
||||
yarnPkgs = yarn2nix-moretea.mkYarnPackage {
|
||||
src = yarnSrc;
|
||||
publishBinsFor = [ "parcel" ];
|
||||
pkgConfig.lmdb-store = {
|
||||
buildInputs = [ nodePackages.node-gyp python3 pkgconfig ];
|
||||
postInstall = ''
|
||||
node-gyp --nodedir=${nodeHeaders} rebuild
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
homepage = stdenv.mkDerivation {
|
||||
name = "Homepage";
|
||||
src = ./.;
|
||||
buildInputs = with elmPackages; [
|
||||
elm
|
||||
elm-format
|
||||
elm2nix
|
||||
yarnPkgs
|
||||
];
|
||||
patchPhase = ''
|
||||
ln -sf ${yarnPkgs}/libexec/*/node_modules .
|
||||
'';
|
||||
configurePhase = elmPackages.fetchElmDeps {
|
||||
elmPackages = import ./elm-srcs.nix;
|
||||
registryDat = ./registry.dat;
|
||||
elmVersion = "0.19.1";
|
||||
};
|
||||
installPhase = ''
|
||||
mkdir $out
|
||||
parcel build --dist-dir $out index.html --no-source-maps --no-cache
|
||||
'';
|
||||
};
|
||||
}
|
||||
37
client/elm-srcs.nix
Normal file
37
client/elm-srcs.nix
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
|
||||
"elm/html" = {
|
||||
sha256 = "1n3gpzmpqqdsldys4ipgyl1zacn0kbpc3g4v3hdpiyfjlgh8bf3k";
|
||||
version = "1.0.0";
|
||||
};
|
||||
|
||||
"elm/browser" = {
|
||||
sha256 = "0nagb9ajacxbbg985r4k9h0jadqpp0gp84nm94kcgbr5sf8i9x13";
|
||||
version = "1.0.2";
|
||||
};
|
||||
|
||||
"elm/core" = {
|
||||
sha256 = "19w0iisdd66ywjayyga4kv2p1v9rxzqjaxhckp8ni6n8i0fb2dvf";
|
||||
version = "1.0.5";
|
||||
};
|
||||
|
||||
"elm/json" = {
|
||||
sha256 = "0kjwrz195z84kwywaxhhlnpl3p251qlbm5iz6byd6jky2crmyqyh";
|
||||
version = "1.1.3";
|
||||
};
|
||||
|
||||
"elm/url" = {
|
||||
sha256 = "0av8x5syid40sgpl5vd7pry2rq0q4pga28b4yykn9gd9v12rs3l4";
|
||||
version = "1.0.0";
|
||||
};
|
||||
|
||||
"elm/time" = {
|
||||
sha256 = "0vch7i86vn0x8b850w1p69vplll1bnbkp8s383z7pinyg94cm2z1";
|
||||
version = "1.0.0";
|
||||
};
|
||||
|
||||
"elm/virtual-dom" = {
|
||||
sha256 = "0q1v5gi4g336bzz1lgwpn5b1639lrn63d8y6k6pimcyismp2i1yg";
|
||||
version = "1.0.2";
|
||||
};
|
||||
}
|
||||
24
client/elm.json
Normal file
24
client/elm.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"type": "application",
|
||||
"source-directories": [
|
||||
"elm"
|
||||
],
|
||||
"elm-version": "0.19.1",
|
||||
"dependencies": {
|
||||
"direct": {
|
||||
"elm/browser": "1.0.2",
|
||||
"elm/core": "1.0.5",
|
||||
"elm/html": "1.0.0"
|
||||
},
|
||||
"indirect": {
|
||||
"elm/json": "1.1.3",
|
||||
"elm/time": "1.0.0",
|
||||
"elm/url": "1.0.0",
|
||||
"elm/virtual-dom": "1.0.2"
|
||||
}
|
||||
},
|
||||
"test-dependencies": {
|
||||
"direct": {},
|
||||
"indirect": {}
|
||||
}
|
||||
}
|
||||
36
client/elm/Loading.elm
Normal file
36
client/elm/Loading.elm
Normal file
@@ -0,0 +1,36 @@
|
||||
module Loading exposing (..)
|
||||
|
||||
import Html as H exposing (Html)
|
||||
import Html.Attributes as HA
|
||||
import Html.Events as HE
|
||||
|
||||
|
||||
type alias Model =
|
||||
Int
|
||||
|
||||
|
||||
type Msg
|
||||
= Dec
|
||||
| Inc
|
||||
|
||||
|
||||
init =
|
||||
0
|
||||
|
||||
|
||||
view mdl =
|
||||
H.div []
|
||||
[ H.button [ HE.onClick Dec ] [ H.text "-" ]
|
||||
, H.button [ HE.onClick Inc ] [ H.text "+" ]
|
||||
, H.text <| String.fromInt mdl
|
||||
]
|
||||
|
||||
|
||||
update : Msg -> Model -> Model
|
||||
update msg mdl =
|
||||
case msg of
|
||||
Dec ->
|
||||
mdl - 1
|
||||
|
||||
Inc ->
|
||||
mdl + 1
|
||||
39
client/elm/Main.elm
Normal file
39
client/elm/Main.elm
Normal file
@@ -0,0 +1,39 @@
|
||||
module Main exposing (main)
|
||||
|
||||
import Browser as B
|
||||
import Html as H exposing (Html)
|
||||
import Html.Attributes as HA
|
||||
import Html.Events as HE
|
||||
import Loading
|
||||
|
||||
|
||||
main =
|
||||
B.sandbox { init = init, update = update, view = view }
|
||||
|
||||
|
||||
type Model
|
||||
= LoadingMdl Loading.Model
|
||||
|
||||
|
||||
type Msg
|
||||
= LoadingMsg Loading.Msg
|
||||
|
||||
|
||||
init : Model
|
||||
init =
|
||||
LoadingMdl Loading.init
|
||||
|
||||
|
||||
view : Model -> Html Msg
|
||||
view mdl =
|
||||
case mdl of
|
||||
LoadingMdl m ->
|
||||
H.map LoadingMsg <| Loading.view m
|
||||
|
||||
|
||||
update : Msg -> Model -> Model
|
||||
update msg_ mdl_ =
|
||||
case ( msg_, mdl_ ) of
|
||||
( LoadingMsg msg, LoadingMdl mdl ) ->
|
||||
LoadingMdl <| Loading.update msg mdl
|
||||
|
||||
8
client/index.html
Normal file
8
client/index.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
</head>
|
||||
<body>
|
||||
<div id="root">Broken</div>
|
||||
<script type="module" src="./index.js"> </script>
|
||||
</body>
|
||||
5
client/index.js
Normal file
5
client/index.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import { Elm } from "./elm/Main.elm";
|
||||
|
||||
Elm.Main.init(
|
||||
{ node: document.getElementById("root") }
|
||||
);
|
||||
13
client/package.json
Normal file
13
client/package.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "FlakeTest",
|
||||
"version": "1.0.0",
|
||||
"browserslist": "since 2015 or > 0.05%",
|
||||
"repository": ".",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@parcel/transformer-elm": "2.0.0-rc.0",
|
||||
"parcel": "^2.0.0-rc.0"
|
||||
},
|
||||
"dependencies": {
|
||||
}
|
||||
}
|
||||
BIN
client/registry.dat
Normal file
BIN
client/registry.dat
Normal file
Binary file not shown.
5055
client/yarn.lock
Normal file
5055
client/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
42
flake.lock
generated
Normal file
42
flake.lock
generated
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"nodes": {
|
||||
"flakeUtils": {
|
||||
"locked": {
|
||||
"lastModified": 1623875721,
|
||||
"narHash": "sha256-A8BU7bjS5GirpAUv4QA+QnJ4CceLHkcXdRp4xITDB0s=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "f7e004a55b120c02ecb6219596820fcd32ca8772",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1628152337,
|
||||
"narHash": "sha256-GhvgTd/DKiloi6cDH3i/Ibab7jQixnJUfCTqObChvtE=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "aeda3e09c601800556f4da7e633827e417a5f62f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flakeUtils": "flakeUtils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
50
flake.nix
Normal file
50
flake.nix
Normal file
@@ -0,0 +1,50 @@
|
||||
{
|
||||
description = "A simple homepage";
|
||||
|
||||
inputs.flakeUtils.url = "github:numtide/flake-utils";
|
||||
inputs.nixpkgs.url = "github:NixOS/nixpkgs";
|
||||
|
||||
outputs = { self, nixpkgs, flakeUtils }:
|
||||
with flakeUtils.lib;
|
||||
eachDefaultSystem (
|
||||
system:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
|
||||
clientFilter = p: t: builtins.all (x: baseNameOf p != x) [
|
||||
".parcel-cache"
|
||||
"dist"
|
||||
"elm-stuff"
|
||||
"node_modules"
|
||||
"result"
|
||||
];
|
||||
|
||||
clientSrc = pkgs.lib.cleanSourceWith {
|
||||
filter = clientFilter;
|
||||
src = ./client;
|
||||
};
|
||||
|
||||
serverSrc = pkgs.lib.cleanSourceWith {
|
||||
filter = clientFilter;
|
||||
src = ./server;
|
||||
};
|
||||
|
||||
client = pkgs.callPackage clientSrc {
|
||||
inherit pkgs;
|
||||
};
|
||||
|
||||
server = pkgs.haskellPackages.callPackage serverSrc {
|
||||
frontend = self.packages.${system}.homepage;
|
||||
};
|
||||
|
||||
in
|
||||
rec {
|
||||
packages = {
|
||||
inherit (client) hello yarnPkgs homepage;
|
||||
inherit (server) server simple;
|
||||
};
|
||||
defaultPackage = self.packages.${system}.simple;
|
||||
devShell = self.defaultPackage.${system};
|
||||
}
|
||||
);
|
||||
}
|
||||
30
server/app/Main.hs
Normal file
30
server/app/Main.hs
Normal file
@@ -0,0 +1,30 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE RecordWildCards #-}
|
||||
|
||||
module Main where
|
||||
|
||||
import Data.Semigroup ((<>))
|
||||
import Network.Wai.Application.Static
|
||||
import Network.Wai.Handler.Warp
|
||||
import Options.Applicative
|
||||
import System.FilePath
|
||||
import WaiAppStatic.Types
|
||||
import Data.Maybe
|
||||
|
||||
data Config = Config
|
||||
{ location :: FilePath,
|
||||
port :: Int
|
||||
}
|
||||
|
||||
configP :: Parser Config
|
||||
configP =
|
||||
let location = strArgument (metavar "PATH" <> help "Directory to serve")
|
||||
port = argument auto (metavar "PORT" <> value 12345)
|
||||
in Config <$> location <*> port
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
Config {..} <- execParser $ info configP fullDesc
|
||||
putStrLn $ "Location: " ++ location
|
||||
putStrLn $ "Port: " ++ show port
|
||||
run port . staticApp $ (defaultWebAppSettings location) {ssIndices = fromMaybe [] $ toPieces ["index.html"]}
|
||||
19
server/default.nix
Normal file
19
server/default.nix
Normal file
@@ -0,0 +1,19 @@
|
||||
{ pkgs, frontend }:
|
||||
|
||||
with pkgs;
|
||||
|
||||
let
|
||||
server = haskell.lib.generateOptparseApplicativeCompletion "FlakeTest" (haskellPackages.callCabal2nix "FlakeTest" ./. {});
|
||||
|
||||
simple = runCommand "FlakeTest" {
|
||||
src = server.src;
|
||||
nativeBuildInputs = [ makeWrapper ];
|
||||
} ''
|
||||
makeWrapper ${server}/bin/FlakeTest $out/bin/FlakeTest \
|
||||
--add-flags ${frontend} \
|
||||
--add-flags 12345
|
||||
'';
|
||||
in
|
||||
{
|
||||
inherit server simple;
|
||||
}
|
||||
28
server/package.yaml
Normal file
28
server/package.yaml
Normal file
@@ -0,0 +1,28 @@
|
||||
_name: &name FlakeTest
|
||||
|
||||
name: *name
|
||||
version: 1.0.0
|
||||
|
||||
ghc-options:
|
||||
- -Wall
|
||||
- -threaded
|
||||
- -O2
|
||||
|
||||
dependencies:
|
||||
- base
|
||||
- filepath
|
||||
- optparse-applicative
|
||||
- wai
|
||||
- wai-app-static
|
||||
- warp
|
||||
|
||||
library:
|
||||
source-dirs: src/
|
||||
|
||||
executables:
|
||||
*name:
|
||||
main: Main.hs
|
||||
source-dirs: app/
|
||||
dependencies:
|
||||
- *name
|
||||
|
||||
Reference in New Issue
Block a user