summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Biz/App.hs18
-rw-r--r--Biz/Bild/ShellHook.sh8
-rw-r--r--Biz/Cloud.nix2
-rw-r--r--Biz/Cloud/Chat.nix10
-rw-r--r--Biz/Cloud/Web.nix82
-rw-r--r--Biz/Dev.nix6
-rw-r--r--Biz/Dev/Configuration.nix4
-rw-r--r--Biz/Look.hs75
-rw-r--r--Devalloc/Host.hs121
-rw-r--r--Devalloc/Host.nix46
-rw-r--r--Devalloc/Page/Home.hs95
-rw-r--r--Devalloc/Page/Signup.hs46
-rw-r--r--Devalloc/pitch.md12
13 files changed, 475 insertions, 50 deletions
diff --git a/Biz/App.hs b/Biz/App.hs
index d16bba9..5759499 100644
--- a/Biz/App.hs
+++ b/Biz/App.hs
@@ -4,7 +4,12 @@
{-# LANGUAGE NoImplicitPrelude #-}
-- | General utils for apps
-module Biz.App (CSS (..), Manifest (..)) where
+module Biz.App
+ ( CSS (..),
+ Manifest (..),
+ HtmlApp (..),
+ )
+where
import Alpha
import Data.Aeson (ToJSON)
@@ -14,7 +19,7 @@ import Network.HTTP.Media
( (//),
(/:),
)
-import Servant
+import Servant.API (Accept (..), MimeRender (..))
newtype CSS = CSS
{ unCSS :: Text
@@ -38,3 +43,12 @@ data Manifest = Manifest
deriving (Show, Eq, Generic)
instance ToJSON Manifest
+
+-- | A wrapper for an HTML page. You need to provide an orphan
+-- 'Lucid.Base.ToHtml' instance in the Host module of your app.
+--
+-- Ideally this would be captured in a Biz.App type, with overrides for head
+-- elements, and we would wouldn't have to make the same basic orphan instance
+-- for each app.
+newtype HtmlApp a = HtmlApp a
+ deriving (Show, Eq)
diff --git a/Biz/Bild/ShellHook.sh b/Biz/Bild/ShellHook.sh
index 4e78acc..b79f1a6 100644
--- a/Biz/Bild/ShellHook.sh
+++ b/Biz/Bild/ShellHook.sh
@@ -56,9 +56,11 @@ function pie() {
runghc Biz.Pie $@
}
-# TODO: convert to haskell
+# TODO: convert to haskell, see:
+# - https://github.com/awakesecurity/nix-deploy/blob/master/src/Main.hs
+# - http://www.haskellforall.com/2018/08/nixos-in-production.html
function push() {
- prefix=$(echo $PWD | sed -e "s|^$BIZ_ROOT/*||g" -e "s|/|.|g")
+ prefix=$(echo $PWD | sed -e "s|^$BIZ_ROOT/*||g")
if [[ "$prefix" == "" ]]
then
target="$1"
@@ -76,7 +78,6 @@ function push() {
# TODO: convert to haskell
function ship() {
- set -ex
$BIZ_ROOT/Biz/Lint.py
stuff=(${1})
if [[ ${#stuff[@]} -eq 0 ]]
@@ -100,7 +101,6 @@ function ship() {
# Poor man's ci
function ci() {
- set -e
lint
stuff=(
Biz/Pie.hs
diff --git a/Biz/Cloud.nix b/Biz/Cloud.nix
index edf8a85..c70c0ad 100644
--- a/Biz/Cloud.nix
+++ b/Biz/Cloud.nix
@@ -24,4 +24,6 @@ bild.os {
];
networking.hostName = "simatime";
networking.domain = "simatime.com";
+ # the datacenter for this VM is in SF
+ time.timeZone = "America/Los_Angeles";
}
diff --git a/Biz/Cloud/Chat.nix b/Biz/Cloud/Chat.nix
index bc97973..6f8ac3a 100644
--- a/Biz/Cloud/Chat.nix
+++ b/Biz/Cloud/Chat.nix
@@ -2,6 +2,9 @@
#
# a homeserver for matrix.org.
#
+# this uses the config.networking.domain as the ACME host. be sure to add the
+# fqdn and element subdomains to security.acme.certs.<name>.extraDomainNames
+#
# - nixos manual: https://nixos.org/nixos/manual/index.html#module-services-matrix
#
# to create new users:
@@ -72,8 +75,8 @@ in {
};
# reverse proxy for matrix client-server and server-server communication
"${fqdn}" = {
- enableACME = true;
forceSSL = true;
+ useACMEHost = config.networking.domain;
locations."/".extraConfig = ''
return 404;
'';
@@ -90,11 +93,8 @@ in {
# https://github.com/vector-im/element-web#important-security-note
#
services.nginx.virtualHosts."${element}" = {
- enableACME = true;
+ useACMEHost = config.networking.domain;
forceSSL = true;
- serverAliases = [
- "chat.${config.networking.domain}"
- ];
root = pkgs.element-web;
};
}
diff --git a/Biz/Cloud/Web.nix b/Biz/Cloud/Web.nix
index acd5c2f..56eeb2d 100644
--- a/Biz/Cloud/Web.nix
+++ b/Biz/Cloud/Web.nix
@@ -1,6 +1,7 @@
-{ ... }:
+{ config, ... }:
let
+ rootDomain = config.networking.domain;
bensIp = "24.140.84.23";
in
{
@@ -11,31 +12,74 @@ in
recommendedOptimisation = true;
recommendedProxySettings = true;
recommendedTlsSettings = true;
+
+ group = "users";
+
virtualHosts = {
- "bsima.me".root = "/home/ben/public_html/";
- "www.bsima.me".root = "/home/ben/public_html/";
- "simatime.com".locations."/".root = "/srv/www/";
- "firefoxsync.simatime.com".locations."/".proxyPass = "http://localhost:5001";
- "hero.simatime.com".locations."/".proxyPass = "http://${bensIp}:3001";
- "tv.simatime.com".locations."/".proxyPass = "http://${bensIp}:8096"; # emby runs on port 8096
- "deluge.simatime.com".locations."/".proxyPass = "http://${bensIp}:8112";
-
- "notebook.simatime.com".locations = {
- "/" = {
- proxyPass = "http://${bensIp}:3099";
- proxyWebsockets = true;
- extraConfig = ''
- proxy_buffering off;
- proxy_read_timeout 86400;
+ ${rootDomain} = {
+ locations."/".root = "/srv/www/";
+ # serve /~$USER paths
+ locations."~ ^/~(.+?)(/.*)?$" = {
+ alias = "/home/$1/public_html$2";
+ index = "index.html index.htm";
+ extraConfig = ''
+ autoindex on;
'';
};
- "/(api/kernels/[^/]+/channels|terminals/websocket)/" = {
- proxyPass = "http://${bensIp}:3099";
- proxyWebsockets = true;
+ forceSSL = true;
+ enableACME = true;
+ };
+
+ "bsima.me" = {
+ locations."/" = {
+ root = "/home/ben/public_html/";
+ index = "index.html index.htm";
+ extraConfig = ''
+ autoindex on;
+ '';
};
+ serverAliases = [ "www.bsima.me" ];
+ forceSSL = true;
+ useACMEHost = rootDomain;
+ };
+
+ "tv.${rootDomain}" = {
+ locations."/".proxyPass = "http://${bensIp}:8096"; # emby runs on port 8096
+ forceSSL = true;
+ useACMEHost = rootDomain;
};
+
+ "devalloc.io" = {
+ locations."/".proxyPass = "http://${bensIp}:8095";
+ forceSSL = true;
+ useACMEHost = rootDomain;
+ };
+
+ # Jupyter is currently disabled on Biz.Dev
+ #"notebook.simatime.com".locations = {
+ # "/" = {
+ # proxyPass = "http://${bensIp}:3099";
+ # proxyWebsockets = true;
+ # extraConfig = ''
+ # proxy_buffering off;
+ # proxy_read_timeout 86400;
+ # '';
+ # };
+ # "/(api/kernels/[^/]+/channels|terminals/websocket)/" = {
+ # proxyPass = "http://${bensIp}:3099";
+ # proxyWebsockets = true;
+ # };
+ #};
};
};
};
+
+ # This must contain all of the other domains we host
+ security.acme.certs.${rootDomain}.extraDomainNames = [
+ "bsima.me" "www.bsima.me" "tv.${rootDomain}"
+ "devalloc.io"
+ "matrix.${rootDomain}"
+ "chat.${rootDomain}"
+ ];#
}
diff --git a/Biz/Dev.nix b/Biz/Dev.nix
index a08a8f7..cdb3036 100644
--- a/Biz/Dev.nix
+++ b/Biz/Dev.nix
@@ -9,8 +9,14 @@ bild.os {
./Users.nix
./Dev/Configuration.nix
./Dev/Hardware.nix
+ ../Devalloc/Host.nix
];
networking.hostName = "lithium";
networking.domain = "dev.simatime.com";
+ services.devalloc-host = {
+ enable = true;
+ port = 8095;
+ package = bild.ghc ../Devalloc/Host.hs;
+ };
}
diff --git a/Biz/Dev/Configuration.nix b/Biz/Dev/Configuration.nix
index 7fa0e37..24293cf 100644
--- a/Biz/Dev/Configuration.nix
+++ b/Biz/Dev/Configuration.nix
@@ -6,6 +6,8 @@ let
torrents = { from = 3000; to = 3099; };
delugeWeb = 8112;
jellyfin = 8096;
+ httpdev = { from = 8000; to = 8099; };
+ devallocHost = 8095;
};
in {
networking = {
@@ -17,7 +19,6 @@ in {
firewall = {
allowedTCPPorts = [
22 8000 8443 443 # standard ports
- 8080 8081 8082 # mostly for urbit
500 10000 # no idea
ports.jellyfin
ports.delugeWeb
@@ -25,6 +26,7 @@ in {
];
allowedTCPPortRanges = [
ports.torrents
+ ports.httpdev
];
allowedUDPPorts = [ ports.murmur ];
allowedUDPPortRanges = [
diff --git a/Biz/Look.hs b/Biz/Look.hs
index 4315994..51224a9 100644
--- a/Biz/Look.hs
+++ b/Biz/Look.hs
@@ -5,36 +5,87 @@
--
-- https://leerob.io/blog/how-stripe-designs-beautiful-websites
module Biz.Look
- ( fontstack,
+ ( -- | Base stylesheets
+ fuckingStyle,
+ -- | Clay.Media extensions
+ prefersLight,
+ prefersDark,
+ noColorPreference,
+ -- | Font
+ fontStack,
+ -- | Elements
hoverButton,
)
where
+import Alpha
import Clay
+import qualified Clay.Stylesheet as Clay
-fontstack :: Css
-fontstack = do
+fontStack :: Css
+fontStack = do
-- i like adobe source pro, maybe use that instead of camphor
fontFamily ["Camphor", "Open Sans", "Segoe UI"] [sansSerif]
textRendering optimizeLegibility
--- TODO: fontSmoothing is not yet implemented in clay
--- -webkit-font-smoothing: antialiased
--- -moz-osx-font-smoothing: grayscale
-
hoverButton :: Css
-hoverButton = do
+hoverButton =
button # hover ? do
color "#7795f8"
- transform $ translateY $ px (-1)
+ transform <| translateY <| px (-1)
boxShadow
- [ bsColor (rgba 50 50 93 0.1) $
- shadow
+ [ bsColor (rgba 50 50 93 0.1)
+ <| shadow
(px 7)
(px 14),
bsColor
(rgba 0 0 0 0.08)
- $ shadow
+ <| shadow
(px 3)
(px 6)
]
+
+prefersDark :: Clay.Feature
+prefersDark =
+ Clay.Feature "prefers-color-scheme" (Just (Clay.value ("dark" :: Text)))
+
+prefersLight :: Clay.Feature
+prefersLight =
+ Clay.Feature "prefers-color-scheme" (Just (Clay.value ("light" :: Text)))
+
+noColorPreference :: Clay.Feature
+noColorPreference =
+ Clay.Feature
+ "prefers-color-scheme"
+ (Just (Clay.value ("no-preference" :: Text)))
+
+-- | The stylesheet from <https://perfectmotherfuckingwebsite.com> ported to
+-- Clay.
+fuckingStyle :: Css
+fuckingStyle = do
+ "body" ? do
+ maxWidth (px 650)
+ margin (px 40) auto (px 40) auto
+ padding 0 (px 10) 0 (px 10)
+ color "#444"
+ fontSize (px 18)
+ lineHeight (em 1.5)
+ fontFamily
+ [ "Segoe UI",
+ "Roboto",
+ "Helvetica Neue",
+ "Arial",
+ "Noto Sans",
+ "Apple Color Emoji",
+ "Segoe UI Emoji",
+ "Segoe UI Symbol",
+ "Noto Color Emoji"
+ ]
+ [sansSerif]
+ "h1" <> "h2" <> "h3" ? lineHeight (em 1.2)
+ query Clay.all [prefersDark] <| do
+ "body" ? do
+ color white
+ background ("#444" :: Color)
+ "a:link" ? color ("#5bf" :: Color)
+ "a:visited" ? color ("#ccf" :: Color)
diff --git a/Devalloc/Host.hs b/Devalloc/Host.hs
new file mode 100644
index 0000000..6d66f32
--- /dev/null
+++ b/Devalloc/Host.hs
@@ -0,0 +1,121 @@
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE DeriveGeneric #-}
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE TypeApplications #-}
+{-# LANGUAGE TypeOperators #-}
+{-# LANGUAGE NoImplicitPrelude #-}
+{-# OPTIONS_GHC -fno-warn-orphans #-}
+
+-- Developer allocation
+--
+-- : out devalloc-host
+-- : dep clay
+-- : dep cmark
+-- : sys cmark
+-- : dep envy
+-- : dep lucid
+-- : dep miso
+-- : dep protolude
+-- : dep servant
+-- : dep servant-server
+-- : dep warp
+module Devalloc.Host
+ ( main,
+ )
+where
+
+import Alpha
+import Biz.App (CSS (..), HtmlApp (..))
+import qualified Biz.Look
+-- import qualified CMark as Cmark
+import qualified Clay
+import qualified Control.Exception as Exception
+import qualified Devalloc.Page.Home as Home
+import qualified Devalloc.Page.Signup as Signup
+import qualified Lucid
+import qualified Lucid.Base as Lucid
+import Miso hiding (node)
+import qualified Network.Wai as Wai
+import qualified Network.Wai.Handler.Warp as Warp
+import Network.Wai.Middleware.RequestLogger (logStdout)
+import Servant
+import qualified System.Envy as Envy
+
+main :: IO ()
+main = Exception.bracket startup shutdown run
+ where
+ startup =
+ Envy.decodeWithDefaults Envy.defConfig >>= \cfg -> do
+ -- pitchText <- readFile <| pitches cfg
+ -- let pitch = Cmark.commonmarkToHtml [] pitchText
+ putText "@"
+ putText "devalloc"
+ putText <| "port: " <> (show <| port cfg)
+ return (cfg, serve (Proxy @AllRoutes) <| serverHandlers)
+ shutdown :: (Config, Application) -> IO ()
+ shutdown _ = pure ()
+ run :: (Config, Wai.Application) -> IO ()
+ run (cfg, app) = Warp.run (port cfg) (logStdout app)
+
+type HomeServer = ToServerRoutes Home.Path HtmlApp Home.Move
+
+type SignupServer = ToServerRoutes Signup.Path HtmlApp Signup.Move
+
+type AllRoutes = HomeServer :<|> SignupServer :<|> CssRoute
+
+type CssRoute = "css" :> "main.css" :> Get '[CSS] Text
+
+cssHandlers :: Server CssRoute
+cssHandlers = return . toStrict <| Clay.render look
+
+instance Lucid.ToHtml a => Lucid.ToHtml (HtmlApp a) where
+ toHtmlRaw = Lucid.toHtml
+ toHtml (HtmlApp x) =
+ Lucid.doctypehtml_ <| do
+ Lucid.head_ <| do
+ Lucid.meta_ [Lucid.charset_ "utf-8"]
+ jsRef "/static/all.js"
+ jsRef "//unpkg.com/turbolinks@5.2.0/dist/turbolinks.js"
+ cssRef "/css/main.css"
+ Lucid.body_ (Lucid.toHtml x)
+ where
+ jsRef _href =
+ Lucid.with
+ (Lucid.script_ mempty)
+ [ Lucid.makeAttribute "src" _href,
+ Lucid.makeAttribute "async" mempty,
+ Lucid.makeAttribute "defer" mempty
+ ]
+ cssRef _href =
+ Lucid.with
+ (Lucid.link_ mempty)
+ [ Lucid.rel_ "stylesheet",
+ Lucid.type_ "text/css",
+ Lucid.href_ _href
+ ]
+
+data Config = Config
+ { port :: Warp.Port,
+ -- | A yaml file of pitches
+ pitches :: FilePath,
+ node :: FilePath
+ }
+ deriving (Generic, Show)
+
+instance Envy.DefConfig Config where
+ defConfig =
+ Config
+ { port = 3000,
+ pitches = "./Devalloc/pitch.md",
+ node = "_/bild/dev/Devalloc.Node/static"
+ }
+
+instance Envy.FromEnv Config
+
+serverHandlers :: Server AllRoutes
+serverHandlers = Home.host :<|> Signup.host :<|> cssHandlers
+
+look :: Clay.Css
+look = do
+ Biz.Look.fuckingStyle
+ "body" Clay.? Biz.Look.fontStack
diff --git a/Devalloc/Host.nix b/Devalloc/Host.nix
new file mode 100644
index 0000000..51aa85d
--- /dev/null
+++ b/Devalloc/Host.nix
@@ -0,0 +1,46 @@
+{ options
+, lib
+, config
+, pkgs
+, modulesPath
+}:
+
+let
+ cfg = config.services.devalloc-host;
+in
+{
+ options.services.devalloc-host = {
+ enable = lib.mkEnableOption "Enable the devalloc-host service";
+ port = lib.mkOption {
+ type = lib.types.int;
+ default = 3000;
+ description = ''
+ The port on which devalloc-host will listen for
+ incoming HTTP traffic.
+ '';
+ };
+ package = lib.mkOption {
+ type = lib.types.package;
+ description = "devalloc-host package to use";
+ };
+ };
+ config = lib.mkIf cfg.enable {
+ systemd.services.devalloc-host = {
+ path = [ cfg.package ];
+ wantedBy = [ "multi-user.target" ];
+ script = ''
+ ${cfg.package}/bin/devalloc-host
+ '';
+ description = ''
+ Devalloc.Host
+ '';
+ serviceConfig = {
+ Environment = ["PORT=${toString cfg.port}"];
+ KillSignal = "INT";
+ Type = "simple";
+ Restart = "on-abort";
+ RestartSec = "1";
+ };
+ };
+ };
+}
diff --git a/Devalloc/Page/Home.hs b/Devalloc/Page/Home.hs
new file mode 100644
index 0000000..f183881
--- /dev/null
+++ b/Devalloc/Page/Home.hs
@@ -0,0 +1,95 @@
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE NoImplicitPrelude #-}
+
+module Devalloc.Page.Home
+ ( Move (..),
+ Path,
+ Form (..),
+ path,
+ view,
+ host,
+ )
+where
+
+import Alpha
+import Biz.App (HtmlApp (..))
+import Miso
+import Miso.String
+import Servant.API
+import Servant.Links
+import Servant.Server (Handler)
+
+data Move = NoMove
+
+type Path = View Move
+
+newtype Form = Form
+ { uri :: URI
+ }
+
+path :: URI
+path = linkURI <| safeLink (Proxy :: Proxy Path) (Proxy :: Proxy Path)
+
+host :: Handler (HtmlApp (View Move))
+host =
+ Form {uri = path}
+ |> view
+ |> HtmlApp
+ |> pure
+
+signup :: View Move
+signup =
+ p_
+ []
+ [ a_
+ [href_ "mailto:ben@bsima.me?subject=Devalloc+signup"]
+ [text "Request access via email"]
+ ]
+
+view :: Form -> View Move
+view _ =
+ div_
+ []
+ [ h1_ [] [text "Devalloc"],
+ p_
+ []
+ [ text
+ "Devalloc analyzes your codebase trends, finds patterns \
+ \ in how your developers work, and protects against tech debt."
+ ],
+ p_ [] [text "Just hook it up to your CI system - it will warn you when it finds a problem."],
+ signup,
+ h2_ [] [text "Identify blackholes in your codebase"],
+ p_
+ []
+ [ text
+ <| Miso.String.intercalate
+ " "
+ [ "What if none of your active employees have touched some part of the codebase?",
+ "This happens too often with legacy code, and then it turns into a huge source of tech debt.",
+ "Devalloc finds these \"blackholes\" and warns you about them so you can be proactive in eliminating tech debt."
+ ]
+ ],
+ h2_
+ []
+ [text "Protect against lost knowledge"],
+ p_
+ []
+ [text "Not everyone can know every part of a codebase. By finding pieces of code that only 1 or 2 people have touched, devalloc identifes siloed knowledge. This allows you to protect against the risk of this knowledge leaving the company if an employee leaves."],
+ h2_
+ []
+ [text "Don't just measure code coverage - also know your dev coverage"],
+ p_
+ []
+ [text "No matter how smart your employees are, if you are under- or over-utilizing your developers then you will never get optimal performance from your team."],
+ ul_
+ []
+ [ li_ [] [text "Find developer hot spots in your code: which pieces of code get continually rewritten, taking up valuable dev time?"],
+ li_ [] [text "Know how your devs work best: which ones have depth of knowledge, and which ones have breadth?"]
+ ],
+ p_ [] [text "(Paid only)"],
+ h2_ [] [text "See how your teams *actually* organize themselves with cluster analysis"],
+ p_ [] [text "Does your team feel splintered or not cohesive? Which developers work best together? Devalloc analyzes the collaboration patterns between devs and helps you form optimal pairings and teams based on shared code and mindspace."],
+ p_ [] [text "(Paid only)"],
+ signup
+ ]
diff --git a/Devalloc/Page/Signup.hs b/Devalloc/Page/Signup.hs
new file mode 100644
index 0000000..4bcdeec
--- /dev/null
+++ b/Devalloc/Page/Signup.hs
@@ -0,0 +1,46 @@
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE NoImplicitPrelude #-}
+
+module Devalloc.Page.Signup
+ ( Move (..),
+ Path,
+ Form (..),
+ path,
+ view,
+ host,
+ )
+where
+
+import Alpha
+import Biz.App (HtmlApp (..))
+import Miso
+import Miso.String
+import Servant.API
+import Servant.Links
+import Servant.Server (Handler)
+
+data Move = NoMove
+
+type Path = View Move
+
+newtype Form = Form
+ { uri :: URI
+ }
+
+path :: URI
+path = linkURI <| safeLink (Proxy :: Proxy Path) (Proxy :: Proxy Path)
+
+host :: Handler (HtmlApp (View Move))
+host =
+ Form {uri = path}
+ |> view
+ |> HtmlApp
+ |> pure
+
+view :: Form -> View Move
+view _ =
+ div_
+ []
+ [ h1_ [] [text "Signup coming soon"],
+ p_ [] [a_ [href_ "/"] [text "Go back home"]]
+ ]
diff --git a/Devalloc/pitch.md b/Devalloc/pitch.md
index 3d122b4..cfc0b23 100644
--- a/Devalloc/pitch.md
+++ b/Devalloc/pitch.md
@@ -1,11 +1,9 @@
# Devalloc
-Devalloc is a service that analyzes your codebase trends, finds patterns in how
-your developers work, and protects against tech debt.
+Devalloc analyzes your codebase trends, finds patterns in how your developers
+work, and protects against tech debt.
-This pre-release prototype is a script you can download and freely run on your
-git repo (requires Python >=3.6). The next, paid version of Devalloc will have
-an API, easy connectors to common CI systems, and automated reporting.
+Just hook it up to your CI system - it will warn you when it finds a problem.
## Identify blackholes in your codebase
@@ -31,7 +29,7 @@ developers then you will never get optimal performance from your team.
- Know how your devs work best: which ones have depth of knowledge, and which
ones have breadth?
-(Available in future paid service)
+(Paid only)
## See how your teams *actually* organize themselves with cluster analysis
@@ -39,4 +37,4 @@ Does your team feel splintered or not cohesive? Which developers work best
together? Devalloc analyzes the collaboration patterns between devs and helps
you form optimal pairings and teams based on shared code and mindspace.
-(Available in future paid service)
+(Paid only)