{ nixpkgs ? import ./Bild/Nixpkgs.nix }: let constants = import ./Bild/Constants.nix; lib = nixpkgs.lib; # put all of our stuff in the 'bild' namespace in nixpkgs // { bild = rec { # provided by .envrc root = builtins.getEnv "BIZ_ROOT"; inherit (nixpkgs) sources; haskell = rec { inherit (constants) ghcCompiler; # all available packages deps = import ./Bild/Deps/Haskell.nix; packages = lib.attrsets.getAttrs deps nixpkgs.haskellPackages; # make a ghc with dependencies ghcWith = nixpkgs.haskell.packages.${ghcCompiler}.ghcWithHoogle; # ghc with all packages, used for generating bild's package database ghcPackageSetFull = ghcWith (p: lib.attrsets.attrVals deps p); # bild's dependencies, needs to be hand-written 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 hostname wai # can remove when removed from Biz.Log ]); }; lisp = { sbclWith = nixpkgs.lispPackages_new.sbclWithPackages; }; python = { packages = nixpkgs.python3Packages; pythonWith = nixpkgs.python3.withPackages; buildPythonApplication = nixpkgs.python3.pkgs.buildPythonApplication; }; # c packages are just nixpkgs, filtered to just the list of deps i want c.packages = lib.attrsets.getAttrs (import ./Bild/Deps/C.nix) nixpkgs.pkgs; # expose some packages for inclusion in os/image builds pkgs = with nixpkgs.pkgs; { inherit git; }; # this is needed to do builds without calling out to nix, remove this when I # switch to all-nix builds bildRuntimeDeps = with nixpkgs; [ pkg-config # this is just to get access to ghc-pkg in bild (haskell.ghcWith (hpkgs: with hpkgs; [])) # lisp deps guile (lisp.sbclWith (p: with p; [asdf alexandria])) # just enough to build Example.lisp ]; # a standard nix build for `bild` - this should be the only hand-written # builder we need bild = nixpkgs.stdenv.mkDerivation { name = "bild"; src = ../.; nativeBuildInputs = [ haskell.ghcPackageSetBild ]; buildInputs = [ nixpkgs.makeWrapper ]; propagatedBuildInputs = bildRuntimeDeps; strictDeps = true; buildPhase = '' mkdir -p $out/bin $out/lib/ghc-${haskell.ghcPackageSetFull.version} cp -r \ ${haskell.ghcPackageSetFull}/lib/ghc-${haskell.ghcPackageSetFull.version}/package.conf.d \ $out/lib/ghc-${haskell.ghcPackageSetFull.version} ghc \ -threaded \ -Werror \ -i. \ --make Biz/Bild.hs \ -main-is Biz.Bild \ -o $out/bin/bild ''; installPhase = '' wrapProgram $out/bin/bild \ --prefix PATH : ${lib.makeBinPath [ haskell.ghcPackageSetBild ]} \ --set GHC_PACKAGE_PATH \ $out/lib/ghc-${haskell.ghcPackageSetFull.version}/package.conf.d ''; }; # wrapper around bild runBildAnalyze = main: nixpkgs.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. returns the # json object of the build analyze = main: builtins.readFile (runBildAnalyze main + "/analysis.json"); # i think this isn't going to work because we have a nix-in-nix problem. # instead: # - get the store path some other way. if i can pass that to bild.os, then nix # should automatically get all the deps required # - just do runBildAnalyze, pass the args to Bild/Builder.nix, should continue # no problem run = main: import ./Bild/Builder.nix { analysisJSON = analyze main; }; # the main development environment env = let linters = with nixpkgs.pkgs; [ ormolu hlint deadnix indent black]; in nixpkgs.pkgs.mkShell { name = "bizdev"; # this should just be dev tools buildInputs = with nixpkgs.pkgs; linters ++ bildRuntimeDeps ++ [ bild ctags figlet git nixpkgs.haskell.packages.${constants.ghcCompiler}.fast-tags hlint lolcat #nixops # fails to build ormolu shellcheck wemux ]; shellHook = '' export GHC_PACKAGE_PATH=${bild}/lib/ghc-${haskell.ghcPackageSetFull.version}/package.conf.d ''; }; # build an operating system. 'cfg' is the NixOS config os = cfg: (nixpkgs.nixos (_args: cfg)).toplevel; # build a docker image image = nixpkgs.pkgs.dockerTools.buildImage; }; }