self: super: let inherit (super) lib mylib; # Haskell projects in the development environment, i.e. directories in # ~/sync/src that contain .cabal. They take precedence over # pkgs/haskell and nixpkgs, and can depend on each other. On hosts without # ~/sync/src, there are none. automaticPackages = let root = /home/tv/sync/src; in lib.optionalAttrs (builtins.pathExists root) (lib.mapAttrs (pname: _type: root + "/${pname}") (lib.filterAttrs (pname: type: type == "directory" && builtins.pathExists (root + "/${pname}/${pname}.cabal")) (builtins.readDir root))); # Copies a Haskell project into the store, leaving out what the build # doesn't need. cleanHaskellSource = name: src: mylib.copyWithout { inherit name src; removeNames = [ ".git" ".graveyard" "dist-newstyle" ]; }; # An automatic package, from the checkout's cabal.nix if it has one, # else from cabal2nix run during evaluation. cabal.nix starts with # the sha256 of the .cabal file it was made from, and fails evaluation # when that changed. automaticPackage = hself: pname: dir: let src = cleanHaskellSource pname dir; stored = dir + "/cabal.nix"; header = "# cabal-sha256: ${builtins.hashFile "sha256" (dir + "/${pname}.cabal")}"; regenerate = ''{ printf '%s\n' '${header}'; cabal2nix .; } > cabal.nix''; in if !builtins.pathExists stored then hself.callCabal2nix pname src {} else if builtins.head (lib.splitString "\n" (builtins.readFile stored)) != header then throw "pkgs/haskell: ${toString stored} is stale against ${pname}.cabal; in ${toString dir}, run: ${regenerate}" else self.haskell.lib.overrideSrc (hself.callPackage stored {}) { inherit src; }; in { # nixpkgs applies packageOverrides to every Haskell package set, including # haskellPackages. haskell = super.haskell // { packageOverrides = lib.composeExtensions super.haskell.packageOverrides (hself: hsuper: mylib.mapNixDir (path: hself.callPackage path {}) [ ./. ] // lib.mapAttrs (automaticPackage hself) automaticPackages); }; }