From 273a717ecf3f52d14e10001710c5267f6277f710 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Mon, 19 Apr 2021 11:16:30 -0400 Subject: Move Biz/Bild/Rules.nix -> Biz/Bild.nix --- Biz/Bild.nix | 167 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Biz/Bild/Rules.nix | 167 ----------------------------------------------------- Biz/Cloud.nix | 2 +- Biz/Dev.nix | 2 +- Biz/Pie.nix | 2 +- Biz/Que/Prod.nix | 2 +- Hero/Prod.nix | 2 +- shell.nix | 2 +- 8 files changed, 173 insertions(+), 173 deletions(-) create mode 100644 Biz/Bild.nix delete mode 100644 Biz/Bild/Rules.nix diff --git a/Biz/Bild.nix b/Biz/Bild.nix new file mode 100644 index 0000000..44c500a --- /dev/null +++ b/Biz/Bild.nix @@ -0,0 +1,167 @@ +{ nixpkgs ? import ./Bild/Nixpkgs.nix }: + +with nixpkgs; + +let + ghcCompiler = "ghc865"; + ghcjsCompiler = "ghcjs86"; + + # provided by .envrc + root = builtins.getEnv "BIZ_ROOT"; + + # general functions to put in a lib + lines = s: lib.pipe s [ + (builtins.split "\n") + (builtins.filter (x: builtins.typeOf x == "string")) + ]; + removeNull = ls: builtins.filter (x: x != null) ls; + + selectAttrs = deps: packageSet: + lib.attrsets.attrVals deps packageSet; + + # returns true if a is a subset of b, where a and b are attrsets + subset = a: b: builtins.all + (x: builtins.elem x b) a; + + haskellDeps = hpkgs: import ./Bild/Deps/Haskell.nix hpkgs; + + mkGhcPackageSet = pkgs.haskell.packages.${ghcCompiler}.ghcWithHoogle; + mkGhcjsPackageSet = pkgs.haskell.packages.${ghcjsCompiler}.ghcWithPackages; + +in rec { + # gather data needed for compiling by analyzing the main module + analyze = main: rec { + # path to the module relative to the git root + relpath = builtins.replaceStrings ["${root}/"] [""] + (builtins.toString main); + # Haskell-appropriate name of the module + module = builtins.replaceStrings ["/" ".hs"] ["." ""] relpath; + # file contents + content = builtins.readFile main; + # search for the ': out' declaration + out = lib.pipe content [ + lines + (map (builtins.match "^-- : out ([[:alnum:]._-]*)$")) + removeNull + lib.lists.flatten + builtins.head + ]; + # collect all of the ': dep' declarations + deps = lib.pipe content [ + lines + (map (builtins.match "^-- : dep ([[:alnum:]._-]*)$")) + removeNull + lib.lists.flatten + ]; + # collect ': sys' declarations + sysdeps = lib.pipe content [ + lines + (map (builtins.match "^-- : sys ([[:alnum:]._-]*)$")) + removeNull + lib.lists.flatten + ]; + }; + + ghcPackageSetFull = mkGhcPackageSet haskellDeps; + + ghc = main: + let + data = analyze main; + ghc = mkGhcPackageSet (hp: selectAttrs data.deps hp); + in stdenv.mkDerivation { + name = data.module; + src = ../.; + nativeBuildInputs = [ ghc ] ++ selectAttrs data.sysdeps nixpkgs; + strictDeps = true; + buildPhase = '' + mkdir -p $out/bin + # compile with ghc + ${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"; + } // { env = ghc; }; + + ghcjs = main: + let + data = analyze main; + ghcjs = mkGhcjsPackageSet (hp: selectAttrs data.deps hp); + in stdenv.mkDerivation { + name = data.module; + src = ../.; + nativeBuildInputs = [ ghcjs ]; + strictDeps = true; + buildPhase = '' + mkdir -p $out/static + # compile with ghcjs + ${ghcjs}/bin/ghcjs \ + -Werror \ + -i. \ + --make ${main} \ + -main-is ${data.module} \ + -o ${data.out} + # optimize js output + ${pkgs.closurecompiler}/bin/closure-compiler \ + ${data.out}/all.js > $out/static/${data.out} + ''; + installPhase = "exit 0"; + } // { env = ghcjs; }; + + env = mkShell { + name = "bizdev"; + buildInputs = [ + # haskell deps + (mkGhcPackageSet haskellDeps) + # ghcjs doesn't need everything, and many things fail to build + (mkGhcjsPackageSet (hp: with hp; [ + aeson + clay + containers + miso + protolude + servant + split + string-quote + text + ghcjs-base + ])) + + # python deps + (nixpkgs.python38.withPackages (p: + [ p.black p.pylint ])) + + # tools + nixpkgs.haskell.packages.${ghcCompiler}.apply-refact + nixpkgs.cmark + nixpkgs.figlet + nixpkgs.haskell.packages.${ghcCompiler}.fast-tags + nixpkgs.hlint + nixpkgs.lolcat + nixpkgs.niv.niv + nixpkgs.nixops + nixpkgs.ormolu + nixpkgs.python37Packages.black + nixpkgs.python37Packages.pylint + nixpkgs.shellcheck + nixpkgs.wemux + nixpkgs.gmnisrv + nixpkgs.gmni + (pkgs.writeScriptBin "ftags" (builtins.readFile ./Ide/ftags.sh)) + ] ++ lib.optional nixpkgs.stdenv.isLinux [ + # scheme deps (i think these are broken on macOS) + nixpkgs.guile + nixpkgs.inspekt3d + nixpkgs.libfive + + nixpkgs.ccze + ]; + shellHook = ". ${./Bild/ShellHook.sh}"; + }; + + os = cfg: (nixos (args: cfg)).toplevel; +} diff --git a/Biz/Bild/Rules.nix b/Biz/Bild/Rules.nix deleted file mode 100644 index afea746..0000000 --- a/Biz/Bild/Rules.nix +++ /dev/null @@ -1,167 +0,0 @@ -{ nixpkgs ? import ./Nixpkgs.nix }: - -with nixpkgs; - -let - ghcCompiler = "ghc865"; - ghcjsCompiler = "ghcjs86"; - - # provided by .envrc - root = builtins.getEnv "BIZ_ROOT"; - - # general functions to put in a lib - lines = s: lib.pipe s [ - (builtins.split "\n") - (builtins.filter (x: builtins.typeOf x == "string")) - ]; - removeNull = ls: builtins.filter (x: x != null) ls; - - selectAttrs = deps: packageSet: - lib.attrsets.attrVals deps packageSet; - - # returns true if a is a subset of b, where a and b are attrsets - subset = a: b: builtins.all - (x: builtins.elem x b) a; - - haskellDeps = hpkgs: import ./Deps/Haskell.nix hpkgs; - - mkGhcPackageSet = pkgs.haskell.packages.${ghcCompiler}.ghcWithHoogle; - mkGhcjsPackageSet = pkgs.haskell.packages.${ghcjsCompiler}.ghcWithPackages; - -in rec { - # gather data needed for compiling by analyzing the main module - analyze = main: rec { - # path to the module relative to the git root - relpath = builtins.replaceStrings ["${root}/"] [""] - (builtins.toString main); - # Haskell-appropriate name of the module - module = builtins.replaceStrings ["/" ".hs"] ["." ""] relpath; - # file contents - content = builtins.readFile main; - # search for the ': out' declaration - out = lib.pipe content [ - lines - (map (builtins.match "^-- : out ([[:alnum:]._-]*)$")) - removeNull - lib.lists.flatten - builtins.head - ]; - # collect all of the ': dep' declarations - deps = lib.pipe content [ - lines - (map (builtins.match "^-- : dep ([[:alnum:]._-]*)$")) - removeNull - lib.lists.flatten - ]; - # collect ': sys' declarations - sysdeps = lib.pipe content [ - lines - (map (builtins.match "^-- : sys ([[:alnum:]._-]*)$")) - removeNull - lib.lists.flatten - ]; - }; - - ghcPackageSetFull = mkGhcPackageSet haskellDeps; - - ghc = main: - let - data = analyze main; - ghc = mkGhcPackageSet (hp: selectAttrs data.deps hp); - in stdenv.mkDerivation { - name = data.module; - src = ../../.; - nativeBuildInputs = [ ghc ] ++ selectAttrs data.sysdeps nixpkgs; - strictDeps = true; - buildPhase = '' - mkdir -p $out/bin - # compile with ghc - ${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"; - } // { env = ghc; }; - - ghcjs = main: - let - data = analyze main; - ghcjs = mkGhcjsPackageSet (hp: selectAttrs data.deps hp); - in stdenv.mkDerivation { - name = data.module; - src = ../../.; - nativeBuildInputs = [ ghcjs ]; - strictDeps = true; - buildPhase = '' - mkdir -p $out/static - # compile with ghcjs - ${ghcjs}/bin/ghcjs \ - -Werror \ - -i. \ - --make ${main} \ - -main-is ${data.module} \ - -o ${data.out} - # optimize js output - ${pkgs.closurecompiler}/bin/closure-compiler \ - ${data.out}/all.js > $out/static/${data.out} - ''; - installPhase = "exit 0"; - } // { env = ghcjs; }; - - env = mkShell { - name = "bizdev"; - buildInputs = [ - # haskell deps - (mkGhcPackageSet haskellDeps) - # ghcjs doesn't need everything, and many things fail to build - (mkGhcjsPackageSet (hp: with hp; [ - aeson - clay - containers - miso - protolude - servant - split - string-quote - text - ghcjs-base - ])) - - # python deps - (nixpkgs.python38.withPackages (p: - [ p.black p.pylint ])) - - # tools - nixpkgs.haskell.packages.${ghcCompiler}.apply-refact - nixpkgs.cmark - nixpkgs.figlet - nixpkgs.haskell.packages.${ghcCompiler}.fast-tags - nixpkgs.hlint - nixpkgs.lolcat - nixpkgs.niv.niv - nixpkgs.nixops - nixpkgs.ormolu - nixpkgs.python37Packages.black - nixpkgs.python37Packages.pylint - nixpkgs.shellcheck - nixpkgs.wemux - nixpkgs.gmnisrv - nixpkgs.gmni - (pkgs.writeScriptBin "ftags" (builtins.readFile ../Ide/ftags.sh)) - ] ++ lib.optional nixpkgs.stdenv.isLinux [ - # scheme deps (i think these are broken on macOS) - nixpkgs.guile - nixpkgs.inspekt3d - nixpkgs.libfive - - nixpkgs.ccze - ]; - shellHook = ". ${./ShellHook.sh}"; - }; - - os = cfg: (nixos (args: cfg)).toplevel; -} diff --git a/Biz/Cloud.nix b/Biz/Cloud.nix index 44fb5a8..6eece13 100644 --- a/Biz/Cloud.nix +++ b/Biz/Cloud.nix @@ -1,4 +1,4 @@ -{ bild ? import ./Bild/Rules.nix {} }: +{ bild ? import ./Bild.nix {} }: # Cloud infrastructure, always online. Mostly for messaging-related stuff. diff --git a/Biz/Dev.nix b/Biz/Dev.nix index ab78b44..cee87a3 100644 --- a/Biz/Dev.nix +++ b/Biz/Dev.nix @@ -1,4 +1,4 @@ -{ bild ? import ./Bild/Rules.nix {} }: +{ bild ? import ./Bild.nix {} }: # Dev machine for work and building stuff. diff --git a/Biz/Pie.nix b/Biz/Pie.nix index de7cf20..b519995 100644 --- a/Biz/Pie.nix +++ b/Biz/Pie.nix @@ -1,2 +1,2 @@ -{ bild ? import ./Bild/Rules.nix {} }: +{ bild ? import ./Bild.nix {} }: bild.ghc ./Pie.hs diff --git a/Biz/Que/Prod.nix b/Biz/Que/Prod.nix index 70272ae..79097d6 100644 --- a/Biz/Que/Prod.nix +++ b/Biz/Que/Prod.nix @@ -1,4 +1,4 @@ -{ bild ? import ../Bild/Rules.nix {} +{ bild ? import ../Bild.nix {} , nixpkgs ? import ../Bild/Nixpkgs.nix }: diff --git a/Hero/Prod.nix b/Hero/Prod.nix index 5b9dde4..3f2ced7 100644 --- a/Hero/Prod.nix +++ b/Hero/Prod.nix @@ -1,4 +1,4 @@ -{ bild ? import ../Biz/Bild/Rules.nix {} +{ bild ? import ../Biz/Bild.nix {} , nixpkgs ? import ../Biz/Bild/Nixpkgs.nix }: diff --git a/shell.nix b/shell.nix index c51f5b8..dabf712 100644 --- a/shell.nix +++ b/shell.nix @@ -1,3 +1,3 @@ -(import ./Biz/Bild/Rules.nix { +(import ./Biz/Bild.nix { nixpkgs = import ./Biz/Bild/Nixpkgs.nix; }).env -- cgit v1.2.3