{ nixpkgs ? import ./Bild/Nixpkgs.nix }: with import ./Bild/Constants.nix; let # provided by .envrc root = builtins.getEnv "BIZ_ROOT"; selectAttrs = deps: packageSet: nixpkgs.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; # 44 = lib.strings.stringLength "/nix/store/gia2r9mxhc900y1m97dlmr1g3rm3ich3-" dropNixStore = s: nixpkgs.lib.strings.substring 44 (nixpkgs.lib.strings.stringLength s) s; haskellDeps = import ./Bild/Deps/Haskell.nix; ghcWith = nixpkgs.haskell.packages.${ghcCompiler}.ghcWithHoogle; #mkGhcjsPackageSet = nixpkgs.haskell.packages.${ghcjsCompiler}.ghcWithPackages; ghcPackageSetFull = ghcWith haskellDeps; ghcPackageSetBild = ghcWith (hpkgs: with hpkgs; [ aeson async base bytestring conduit conduit-extra containers directory docopt filepath process protolude rainbow regex-applicative split tasty tasty-hunit tasty-quickcheck text wai # can remove when removed from Biz.Log ]); in rec { inherit (nixpkgs) lib stdenv sources; inherit ghcWith; # a standard nix build for `bild` - this should be the only hand-written # builder we need bild = stdenv.mkDerivation { name = "bild"; src = ../.; nativeBuildInputs = [ ghcPackageSetBild ]; buildInputs = [ nixpkgs.makeWrapper ]; strictDeps = true; buildPhase = '' mkdir -p $out/bin $out/lib/ghc-${ghcPackageSetFull.version} cp -r \ ${ghcPackageSetFull}/lib/ghc-${ghcPackageSetFull.version}/package.conf.d \ $out/lib/ghc-${ghcPackageSetFull.version} ghc \ -Werror \ -i. \ --make Biz/Bild.hs \ -main-is Biz.Bild \ -o $out/bin/bild ''; installPhase = '' wrapProgram $out/bin/bild \ --prefix PATH : ${lib.makeBinPath [ ghcPackageSetBild ]} \ --set GHC_PACKAGE_PATH \ $out/lib/ghc-${ghcPackageSetFull.version}/package.conf.d ''; }; # wrapper around bild runBildAnalyze = main: stdenv.mkDerivation rec { name = "bild-analysis"; src = ../.; USER = "nixbld"; HOSTNAME = "nix-sandbox"; # this is the default sandbox path where bild will be working: BIZ_ROOT = "/build/biz"; # we need to remove the $src root because bild expects paths relative to the # working directory: MAIN = "." + lib.strings.removePrefix (toString src) (toString main); buildPhase = '' mkdir $out ${bild}/bin/bild --json "$MAIN" 1> $out/analysis.json \ 2> >(tee -a $out/stderr >&2) ''; installPhase = "exit 0"; }; # gather data needed for compiling by analyzing the main module analyze = main: builtins.head (lib.trivial.importJSON (runBildAnalyze main + "/analysis.json")); ghc = main: let data = analyze main; ghc = ghcWith (hp: selectAttrs data.langdeps hp); module = lib.strings.concatStringsSep "." data.namespace.path; in stdenv.mkDerivation { name = module; src = ../.; nativeBuildInputs = [ ghc ] ++ selectAttrs data.sysdeps nixpkgs.pkgs; strictDeps = true; buildPhase = '' set -eux mkdir -p $out/bin : compiling with ghc ${ghc}/bin/ghc \ -Werror \ -i. \ --make ${main} \ -main-is ${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 # ${nixpkgs.pkgs.closurecompiler}/bin/closure-compiler \ # ${data.out}/all.js > $out/static/${data.out} # ''; # installPhase = "exit 0"; # } // { env = ghcjs; }; env = nixpkgs.pkgs.mkShell { name = "bizdev"; buildInputs = with nixpkgs.pkgs; [ # this should just be dev tools haskell.packages.${ghcCompiler}.apply-refact bild figlet haskell.packages.${ghcCompiler}.fast-tags hlint lolcat niv.niv nixops ormolu python38Packages.black python38Packages.pylint shellcheck wemux ] ++ lib.optional nixpkgs.stdenv.isLinux [ # scheme deps (i think these are broken on macOS) guile #inspekt3d #libfive ]; shellHook = ". ${./Bild/ShellHook.sh}"; }; os = cfg: (nixpkgs.nixos (args: cfg)).toplevel; pkgs = { inherit (nixpkgs) git; }; image = nixpkgs.pkgs.dockerTools.buildImage; }