diff options
author | Ben Sima <ben@bsima.me> | 2020-10-13 11:57:29 -0400 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2020-10-13 12:02:32 -0400 |
commit | 1d92f4686c4803c802dce66804eba9ebe61efc1a (patch) | |
tree | caf95700e5c587d4908138004baf4273f6bf5466 | |
parent | dbea29d0c604c69968adbf658ca19a6cc207890d (diff) |
Move nix files into Biz.Bild namespace
-rw-r--r-- | Biz/Bild/Deps.nix (renamed from nix/haskell-deps.nix) | 0 | ||||
-rw-r--r-- | Biz/Bild/Nixpkgs.nix (renamed from nix/default.nix) | 7 | ||||
-rw-r--r-- | Biz/Bild/Overlay.nix (renamed from nix/haskell-overlay.nix) | 19 | ||||
-rw-r--r-- | Biz/Bild/Repl.nix (renamed from nix/repl.nix) | 0 | ||||
-rw-r--r-- | Biz/Bild/Rules.nix (renamed from nix/build.nix) | 8 | ||||
-rw-r--r-- | Biz/Bild/ShellHook.sh | 98 | ||||
-rw-r--r-- | Biz/Bild/Sources.json (renamed from nix/sources.json) | 0 | ||||
-rw-r--r-- | Biz/Bild/Sources.nix (renamed from nix/sources.nix) | 2 | ||||
-rw-r--r-- | Biz/Bild/Wemux.nix (renamed from nix/wemux.nix) | 0 | ||||
-rw-r--r-- | Hero/Host.hs | 2 | ||||
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | default.nix | 4 | ||||
-rw-r--r-- | nix/sources-overlay.nix | 16 |
13 files changed, 126 insertions, 33 deletions
diff --git a/nix/haskell-deps.nix b/Biz/Bild/Deps.nix index dccbd81..dccbd81 100644 --- a/nix/haskell-deps.nix +++ b/Biz/Bild/Deps.nix diff --git a/nix/default.nix b/Biz/Bild/Nixpkgs.nix index 04f9ee4..21be382 100644 --- a/nix/default.nix +++ b/Biz/Bild/Nixpkgs.nix @@ -1,14 +1,13 @@ let - sources = import ./sources.nix; + sources = import ./Sources.nix; nixpkgs = import sources.nixpkgs { system = __currentSystem; overlays = [ (_: _: { inherit sources; }) - (import ./sources-overlay.nix) + (import ./Overlay.nix) (_: pkgs: pkgs.overridePinnedDeps pkgs.overrideSource) (_: _: { niv = import sources.niv {}; }) - (import ./haskell-overlay.nix) - (_: pkgs: { wemux = pkgs.callPackage ./wemux.nix {}; }) + (_: pkgs: { wemux = pkgs.callPackage ./Wemux.nix {}; }) ]; }; in nixpkgs diff --git a/nix/haskell-overlay.nix b/Biz/Bild/Overlay.nix index a6aad12..b8fe269 100644 --- a/nix/haskell-overlay.nix +++ b/Biz/Bild/Overlay.nix @@ -8,13 +8,26 @@ let self.callCabal2nix name pkgs.sources.${name} {} else self.callCabal2nix name (pkgs.sources.${name} + "/${subdir}") {}; -in +in rec { + pinnedDeps = builtins.attrNames + (builtins.removeAttrs pkgs.sources ["__functor"]); + overridePinnedDeps = builder: pkgs.lib.genAttrs pinnedDeps builder; + + # Modifies a derivation with our source and version, keeping old build + # rules. This will fail if build steps have changed, or if no build + # rules are available upstream.. + overrideSource = name: pkgs.${name}.overrideAttrs (old: old // rec { + name = "${name}-${version}"; + version = pkgs.sources.${name}.version or pkgs.sources.${name}.rev; + src = pkgs.sources.${name}; + }); + haskell = pkgs.haskell // { packages = pkgs.haskell.packages // { ghc865 = pkgs.haskell.packages.ghc865.override (old: { overrides = with pkgs.pkgs.haskell.lib; self: super: - pkgs.overridePinnedDeps (simpleCabalBuilder self) // { + overridePinnedDeps (simpleCabalBuilder self) // { acid-state = dontCheck super.acid-state; # mac: "too many open files" servant-auth = buildCabal self "servant-auth" "servant-auth"; wai-middleware-metrics = dontCheck super.wai-middleware-metrics; @@ -22,7 +35,7 @@ in }); ghcjs = pkgs.haskell.packages.ghcjs.override (old: { overrides = with pkgs.haskell.lib; self: super: - pkgs.overridePinnedDeps (simpleCabalBuilder self) // { + overridePinnedDeps (simpleCabalBuilder self) // { Glob = dontCheck super.Glob; QuickCheck = dontCheck super.QuickCheck; base-compat-batteries = dontCheck super.http-types; diff --git a/nix/repl.nix b/Biz/Bild/Repl.nix index 94edf3a..94edf3a 100644 --- a/nix/repl.nix +++ b/Biz/Bild/Repl.nix diff --git a/nix/build.nix b/Biz/Bild/Rules.nix index 5258313..6afe9a0 100644 --- a/nix/build.nix +++ b/Biz/Bild/Rules.nix @@ -17,7 +17,7 @@ let subset = a: b: builtins.all (x: builtins.elem x b) a; - allDeps = import ./haskell-deps.nix; + allDeps = import ./Deps.nix; # gather data needed for compiling by analyzing the main module analyze = main: rec { @@ -61,7 +61,7 @@ in { buildPhase = '' mkdir -p $out/bin # compile with ghc - ${ghc}/bin/ghc -Werror -i. \ + ${ghc}/bin/ghc -Werror -Weverything -i. \ --make ${main} \ -main-is ${data.module} \ -o $out/bin/${data.exe} @@ -82,7 +82,7 @@ in { buildPhase = '' mkdir -p $out/static # compile with ghcjs - ${ghcjs}/bin/ghcjs -Werror -i. \ + ${ghcjs}/bin/ghcjs -Werror -Weverything -i. \ --make ${main} \ -main-is ${data.module} \ -o ${data.exe} @@ -120,7 +120,7 @@ in { nixpkgs.python37Packages.pylint nixpkgs.wemux ]; - shellHook = ". ${./shellHook.sh}"; + shellHook = ". ${./ShellHook.sh}"; }; os = cfg: (nixos (args: lib.attrsets.recursiveUpdate cfg { diff --git a/Biz/Bild/ShellHook.sh b/Biz/Bild/ShellHook.sh new file mode 100644 index 0000000..75a0842 --- /dev/null +++ b/Biz/Bild/ShellHook.sh @@ -0,0 +1,98 @@ +function help() { + echo "" + echo "bizdev" | figlet | lolcat + echo "" + echo " bild compile code" + echo " deps manage dependencies with niv" + echo " ghci start ghci with correct options" + echo " help show this message" + echo " hero compile and start a dev server for herocomics.app" + echo " lint auto-lint all changed files" + echo " pie product improvement engine" + echo " push send a namespace to the cloud" + echo " ship lint, bild, and push one (or all) namespace(s)" +} + +function bild() { + runghc Biz.Bild $@ +} + +function deps() { + niv --sources-file $BIZ_ROOT/Biz/Bild/Sources.json $@ +} + +alias ghci="ghci -i$BIZ_ROOT -ghci-script $BIZ_ROOT/.ghci" + +function hero() { + export HERO_PORT=3000 + export HERO_KEEP=$BIZ_ROOT/_/keep + export HERO_SKEY=$BIZ_ROOT/_/skey + bild="runghc Biz.Bild" + if [[ ! -z "${IN_NIX_SHELL}" ]] + then + out="_/bild/dev" + # in dev mode, mmc.js is a directory of js assets + export HERO_NODE=$BIZ_ROOT/$out/static/mmc.js + rg --files \ + | entr -rcs \ + "$bild Hero.Host.hs && $bild Hero.Node.hs && $out/bin/mmc" + else + out="_/bild/nix" + export HERO_NODE=$BIZ_ROOT/$out/Hero.Node/static + rg --files \ + | entr -rcs \ + "$bild Hero.Host && $bild Hero.Node && $out/Hero.Host/bin/mmc" + fi +} + +function lint() { + alias lint=$BIZ_ROOT/Biz/lint.py +} + +function pie() { + runghc Biz.Pie $@ +} + +# TODO: convert to haskell +function push() { + prefix=$(echo $PWD | sed -e "s|^$BIZ_ROOT/*||g" -e "s|/|.|g") + if [[ "$prefix" == "" ]] + then + target="$1" + else + target="$prefix.$1" + fi + what=$(realpath "$BIZ_ROOT/_/bild/$target") + # hack: get the domain from the activation script. there does not seem + # to be a way to get it from nix-instantiate + where=$(rg -r '$2' -e '(domainname ")(.*)(")' "$what/activate") + nix copy --to ssh://root@$where $what + ssh root@$where $what/bin/switch-to-configuration switch + ssh root@$where nix-env --profile /nix/var/nix/profiles/system --set $what +} + +# TODO: convert to haskell +function ship() { + set -ex + $BIZ_ROOT/Biz/lint.py + stuff=(${1}) + if [[ ${#stuff[@]} -eq 0 ]] + then + stuff=( + Biz.Cloud + Biz.Dev + Que.Prod + Hero.Prod + ) + fi + for thing in ${stuff[@]} + do + bild $thing + done + for thing in ${stuff[@]} + do + push $thing + done +} + +help diff --git a/nix/sources.json b/Biz/Bild/Sources.json index d2565a7..d2565a7 100644 --- a/nix/sources.json +++ b/Biz/Bild/Sources.json diff --git a/nix/sources.nix b/Biz/Bild/Sources.nix index 7bd0f3e..8da4974 100644 --- a/nix/sources.nix +++ b/Biz/Bild/Sources.nix @@ -124,7 +124,7 @@ let # The "config" used by the fetchers mkConfig = - { sourcesFile ? ./sources.json + { sourcesFile ? ./Sources.json , sources ? builtins.fromJSON (builtins.readFile sourcesFile) , pkgs ? mkPkgs sources }: rec { diff --git a/nix/wemux.nix b/Biz/Bild/Wemux.nix index 365853f..365853f 100644 --- a/nix/wemux.nix +++ b/Biz/Bild/Wemux.nix diff --git a/Hero/Host.hs b/Hero/Host.hs index 87b9d33..326738b 100644 --- a/Hero/Host.hs +++ b/Hero/Host.hs @@ -10,7 +10,7 @@ {-# LANGUAGE TypeOperators #-} {-# LANGUAGE NoImplicitPrelude #-} -{-# OPTIONS_GHC -fno-warn-orphan #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} -- | Hero web app -- @@ -12,8 +12,7 @@ application. Development aspects should be localized to their sub-namespaces as much as possible. Only after sufficient iteration such that interfaces are solidified and functionality is well-established should some code be -promoted up the namespace hierarchy. The one special namespace/directory -is `nix` which has all of our build rules. +promoted up the namespace hierarchy. Boundaries and interfaces between namespaces should be small and well-defined. Likewise, the functionality and purpose of a particular diff --git a/default.nix b/default.nix index 5d2021b..29ed1a3 100644 --- a/default.nix +++ b/default.nix @@ -1,6 +1,6 @@ let - nixpkgs = import ./nix; - build = import ./nix/build.nix { inherit nixpkgs; }; + nixpkgs = import ./Biz/Bild/Nixpkgs.nix; + build = import ./Biz/Bild/Rules.nix { inherit nixpkgs; }; 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"; diff --git a/nix/sources-overlay.nix b/nix/sources-overlay.nix deleted file mode 100644 index b19bb34..0000000 --- a/nix/sources-overlay.nix +++ /dev/null @@ -1,16 +0,0 @@ -_: pkgs: - -rec { - pinnedDeps = builtins.attrNames - (builtins.removeAttrs pkgs.sources ["__functor"]); - overridePinnedDeps = builder: pkgs.lib.genAttrs pinnedDeps builder; - - # Modifies a derivation with our source and version, keeping old build - # rules. This will fail if build steps have changed, or if no build - # rules are available upstream.. - overrideSource = name: pkgs.${name}.overrideAttrs (old: old // rec { - name = "${name}-${version}"; - version = pkgs.sources.${name}.version or pkgs.sources.${name}.rev; - src = pkgs.sources.${name}; - }); -} |