summaryrefslogtreecommitdiff
path: root/Biz
diff options
context:
space:
mode:
Diffstat (limited to 'Biz')
-rw-r--r--Biz/App.hs29
-rw-r--r--Biz/Bild.hs97
-rw-r--r--Biz/Bild/Rules.nix34
-rw-r--r--Biz/Bild/ShellHook.sh2
-rw-r--r--Biz/Cloud.nix27
-rw-r--r--Biz/Dev.nix16
-rw-r--r--Biz/Ibb/Client.hs2
-rw-r--r--Biz/Ibb/Server.hs2
-rw-r--r--Biz/Pie.hs9
-rw-r--r--Biz/Pie.nix1
10 files changed, 146 insertions, 73 deletions
diff --git a/Biz/App.hs b/Biz/App.hs
index 95e7271..d16bba9 100644
--- a/Biz/App.hs
+++ b/Biz/App.hs
@@ -1,9 +1,10 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE NoImplicitPrelude #-}
-- | General utils for apps
-module Biz.App (CSS(..), Manifest(..)) where
+module Biz.App (CSS (..), Manifest (..)) where
import Alpha
import Data.Aeson (ToJSON)
@@ -15,10 +16,9 @@ import Network.HTTP.Media
)
import Servant
-newtype CSS
- = CSS
- { unCSS :: Text
- }
+newtype CSS = CSS
+ { unCSS :: Text
+ }
instance Accept CSS where
contentType _ = "text" // "css" /: ("charset", "utf-8")
@@ -27,17 +27,14 @@ instance MimeRender CSS Text where
mimeRender _ = Lazy.encodeUtf8 . Lazy.fromStrict
-- | The manifest describes your app for web app thumbnails, iPhone tiles, etc.
-data Manifest
- = Manifest
- { name :: Text,
- short_name :: Text,
- start_url :: Text,
- display :: Text,
- theme_color :: Text,
- description :: Text
- }
+data Manifest = Manifest
+ { name :: Text,
+ short_name :: Text,
+ start_url :: Text,
+ display :: Text,
+ theme_color :: Text,
+ description :: Text
+ }
deriving (Show, Eq, Generic)
instance ToJSON Manifest
-
-
diff --git a/Biz/Bild.hs b/Biz/Bild.hs
index 92054f9..169fd6f 100644
--- a/Biz/Bild.hs
+++ b/Biz/Bild.hs
@@ -64,7 +64,7 @@
--
-- > bild A/B.hs
--
--- This will build the file at ./A/B.hs, this will translate to something like
+-- This will build the file at ./A/B.hs, which translates to something like
-- `ghc --make A.B`.
--
-- > bild -s <target>
@@ -94,16 +94,16 @@
--
-- The output executable is named with:
--
--- > -- : exe my-program
+-- > -- : out my-program
--
-- or
--
--- > -- : exe my-ap.js
+-- > -- : out my-ap.js
--
-- When multiple compilers are possible (e.g. ghc vs ghcjs) we chose ghcjs when
--- the target exe ends in .js.
+-- the target @out@ ends in .js.
--
--- This method of setting metadata in the module comments works pretty well,
+-- This method of setting metadata in the module comments works pretty well,
-- and really only needs to be done in the entrypoint module anyway.
--
-- Local module deps are included by just giving the repo root to the compiler
@@ -143,14 +143,14 @@ type Namespace = String
type Dep = String
-type Exe = String
+type Out = String
data Compiler = Ghc | Ghcjs | Nix
deriving (Show)
data Target = Target
- { -- | Output executable name
- exe :: Exe,
+ { -- | Output name
+ out :: Out,
-- | Fully qualified namespace partitioned by '.'
namespace :: Namespace,
-- | Absolute path to file
@@ -170,24 +170,30 @@ analyze s = do
case File.takeExtension path of
".hs" -> do
content <- String.lines </ Prelude.readFile path
- let exe = content /> Regex.match metaExe |> catMaybes |> head |> require "exe"
- let compiler = if ".js" `List.isSuffixOf` exe then Ghcjs else Ghc
- return Target {
- namespace = require "namespace"
- <| path
- |> reps root ""
- |> File.dropExtension
- |> reps "/" "."
- |> List.stripPrefix "."
- >>= Regex.match metaNamespace,
- deps = content /> Regex.match metaDep |> catMaybes,
- ..
- }
-
- ".nix" -> return Target {
- namespace = s, path = path, deps = [], compiler = Nix, exe = ""
- }
-
+ let out = content /> Regex.match metaOut |> catMaybes |> head |> require "out"
+ let compiler = if ".js" `List.isSuffixOf` out then Ghcjs else Ghc
+ return
+ Target
+ { namespace =
+ require "namespace"
+ <| path
+ |> reps root ""
+ |> File.dropExtension
+ |> reps "/" "."
+ |> List.stripPrefix "."
+ >>= Regex.match metaNamespace,
+ deps = content /> Regex.match metaDep |> catMaybes,
+ ..
+ }
+ ".nix" ->
+ return
+ Target
+ { namespace = s,
+ path = path,
+ deps = [],
+ compiler = Nix,
+ out = ""
+ }
e -> panic <| "bild does not know this extension: " <> Text.pack e
build :: Target -> IO ()
@@ -196,8 +202,8 @@ build Target {..} = do
case compiler of
Ghc -> do
putText <| "bild: ghc: " <> Text.pack namespace
- let out = root </> "_/bild/dev/bin"
- Dir.createDirectoryIfMissing True out
+ let devOut = root </> "_/bild/dev/bin"
+ Dir.createDirectoryIfMissing True devOut
Process.callProcess
"ghc"
[ "-Werror",
@@ -211,12 +217,12 @@ build Target {..} = do
"-main-is",
namespace,
"-o",
- out </> exe
+ devOut </> out
]
Ghcjs -> do
putText <| "bild: ghcjs: " <> Text.pack namespace
- let out = root </> "_/bild/dev/static"
- Dir.createDirectoryIfMissing True out
+ let devOut = root </> "_/bild/dev/static"
+ Dir.createDirectoryIfMissing True devOut
Process.callProcess
"ghcjs"
[ "-Werror",
@@ -230,19 +236,30 @@ build Target {..} = do
"-main-is",
namespace,
"-o",
- out </> exe
+ devOut </> out
]
Nix -> do
putText <| "bild: nix: " <> Text.pack namespace
cwd <- Dir.getCurrentDirectory
- let qualifiedTarget = reps root "" cwd <> namespace
+ let nixOut = root </> "_/bild/nix"
+ Dir.createDirectoryIfMissing True nixOut
+ let qualifiedTarget = reps root "" cwd </> namespace
Process.callProcess
"nix-build"
- [ "-o",
- root </> "_/bild/nix" </> qualifiedTarget,
- root </> "default.nix",
- "--attr",
- qualifiedTarget
+ [ path,
+ "-o",
+ nixOut </> qualifiedTarget,
+ "--arg",
+ "bild",
+ "import " <> root
+ </> "Biz/Bild/Rules.nix"
+ <> " { nixpkgs = import "
+ <> root
+ </> "Biz/Bild/Nixpkgs.nix"
+ <> "; }",
+ "--arg",
+ "lib",
+ "(import " <> root </> "Biz/Bild/Nixpkgs.nix).lib"
]
metaNamespace :: Regex.RE Char Namespace
@@ -253,8 +270,8 @@ metaNamespace = name <> Regex.many (Regex.sym '.') <> name
metaDep :: Regex.RE Char Dep
metaDep = Regex.string "-- : dep " *> Regex.many (Regex.psym Char.isAlpha)
-metaExe :: Regex.RE Char Exe
-metaExe = Regex.string "-- : exe " *> Regex.many (Regex.psym (/= ' '))
+metaOut :: Regex.RE Char Out
+metaOut = Regex.string "-- : out " *> Regex.many (Regex.psym (/= ' '))
require :: Text -> Maybe a -> a
require _ (Just x) = x
diff --git a/Biz/Bild/Rules.nix b/Biz/Bild/Rules.nix
index e76d7a2..2a1a4d1 100644
--- a/Biz/Bild/Rules.nix
+++ b/Biz/Bild/Rules.nix
@@ -28,9 +28,9 @@ let
module = builtins.replaceStrings ["/" ".hs"] ["." ""] relpath;
# file contents
content = builtins.readFile main;
- # search for the ': exe' declaration
- exe = builtins.head (lib.lists.flatten (removeNull
- (map (builtins.match "^-- : exe ([[:alnum:]._-]*)$")
+ # search for the ': out' declaration
+ out = builtins.head (lib.lists.flatten (removeNull
+ (map (builtins.match "^-- : out ([[:alnum:]._-]*)$")
(lines content))));
# collect all of the ': dep' declarations
deps = lib.lists.flatten (removeNull
@@ -38,7 +38,7 @@ let
(lines content)));
sysdeps = lib.lists.flatten (removeNull
- (map (builtins.match "^-- : sys ([[:alum:]._-]*)$")
+ (map (builtins.match "^-- : sys ([[:alnum:]._-]*)$")
(lines content)));
};
@@ -59,16 +59,18 @@ in {
ghc = ghc_ data.deps;
in stdenv.mkDerivation {
name = data.module;
- src = ../.;
+ src = ../../.;
nativeBuildInputs = [ ghc ] ++ depsToPackageSet nixpkgs data.sysdeps;
strictDeps = true;
buildPhase = ''
mkdir -p $out/bin
# compile with ghc
- ${ghc}/bin/ghc -Werror -Weverything -i. \
- --make ${main} \
- -main-is ${data.module} \
- -o $out/bin/${data.exe}
+ ${ghc}/bin/ghc \
+ -Werror \
+ -i. \
+ --make ${main} \
+ -main-is ${data.module} \
+ -o $out/bin/${data.out}
'';
# the install process was handled above
installPhase = "exit 0";
@@ -80,19 +82,21 @@ in {
ghcjs = ghcjs_ data.deps;
in stdenv.mkDerivation {
name = data.module;
- src = ../.;
+ src = ../../.;
nativeBuildInputs = [ ghcjs ];
strictDeps = true;
buildPhase = ''
mkdir -p $out/static
# compile with ghcjs
- ${ghcjs}/bin/ghcjs -Werror -Weverything -i. \
- --make ${main} \
- -main-is ${data.module} \
- -o ${data.exe}
+ ${ghcjs}/bin/ghcjs \
+ -Werror \
+ -i. \
+ --make ${main} \
+ -main-is ${data.module} \
+ -o ${data.out}
# optimize js output
${pkgs.closurecompiler}/bin/closure-compiler \
- ${data.exe}/all.js > $out/static/${data.exe}
+ ${data.out}/all.js > $out/static/${data.out}
'';
installPhase = "exit 0";
} // { env = ghcjs; };
diff --git a/Biz/Bild/ShellHook.sh b/Biz/Bild/ShellHook.sh
index 89751d3..0fc1781 100644
--- a/Biz/Bild/ShellHook.sh
+++ b/Biz/Bild/ShellHook.sh
@@ -13,6 +13,8 @@ function help() {
echo " ship lint, bild, and push one (or all) namespace(s)"
}
+alias runghc="runghc --ghc-arg=-i$BIZ_ROOT"
+
function bild() {
runghc Biz.Bild $@
}
diff --git a/Biz/Cloud.nix b/Biz/Cloud.nix
new file mode 100644
index 0000000..edf8a85
--- /dev/null
+++ b/Biz/Cloud.nix
@@ -0,0 +1,27 @@
+{ bild }:
+
+# Cloud infrastructure, always online. Mostly for messaging-related stuff.
+
+let
+ nixos-mailserver = let ver = "v2.3.0"; in builtins.fetchTarball {
+ url = "https://gitlab.com/simple-nixos-mailserver/nixos-mailserver/-/archive/${ver}/nixos-mailserver-${ver}.tar.gz";
+ sha256 = "0lpz08qviccvpfws2nm83n7m2r8add2wvfg9bljx9yxx8107r919";
+ };
+in
+bild.os {
+ imports = [
+ ./OsBase.nix
+ ./Packages.nix
+ ./Users.nix
+ ./Cloud/Chat.nix
+ ./Cloud/Git.nix
+ ./Cloud/Hardware.nix
+ ./Cloud/Mail.nix
+ ./Cloud/Networking.nix
+ ./Cloud/Web.nix
+ ./Cloud/Znc.nix
+ nixos-mailserver
+ ];
+ networking.hostName = "simatime";
+ networking.domain = "simatime.com";
+}
diff --git a/Biz/Dev.nix b/Biz/Dev.nix
new file mode 100644
index 0000000..a08a8f7
--- /dev/null
+++ b/Biz/Dev.nix
@@ -0,0 +1,16 @@
+{ bild }:
+
+# Dev machine for work and building stuff.
+
+bild.os {
+ imports = [
+ ./OsBase.nix
+ ./Packages.nix
+ ./Users.nix
+ ./Dev/Configuration.nix
+ ./Dev/Hardware.nix
+ ];
+ networking.hostName = "lithium";
+ networking.domain = "dev.simatime.com";
+}
+
diff --git a/Biz/Ibb/Client.hs b/Biz/Ibb/Client.hs
index c3dae4b..d0ed3e3 100644
--- a/Biz/Ibb/Client.hs
+++ b/Biz/Ibb/Client.hs
@@ -3,7 +3,7 @@
-- | Front-end
--
--- : exe ibb.js
+-- : out ibb.js
--
-- : dep clay
-- : dep miso
diff --git a/Biz/Ibb/Server.hs b/Biz/Ibb/Server.hs
index d7b4969..058bbdc 100644
--- a/Biz/Ibb/Server.hs
+++ b/Biz/Ibb/Server.hs
@@ -7,7 +7,7 @@
-- | Server
--
--- : exe ibb
+-- : out ibb
--
-- : dep clay
-- : dep miso
diff --git a/Biz/Pie.hs b/Biz/Pie.hs
index 7e1c19e..409f14f 100644
--- a/Biz/Pie.hs
+++ b/Biz/Pie.hs
@@ -29,6 +29,15 @@
-- - Sean Ellis' question: "How would you feel if you could no longer use this
-- product? (a) Very disappointed, (b) somewhat disappointed, (c) not
-- disappointed" and then measure the percentage who answer (a).
+--
+-- Bild Metadata:
+--
+-- : out pie
+-- : dep aeson
+-- : dep protolude
+-- : dep optparse-simple
+-- : dep parsec
+-- : dep haskeline
module Biz.Pie
( main,
)
diff --git a/Biz/Pie.nix b/Biz/Pie.nix
new file mode 100644
index 0000000..70e2f23
--- /dev/null
+++ b/Biz/Pie.nix
@@ -0,0 +1 @@
+{ bild }: bild.ghc ./Pie.hs