Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions builder/comp-builder.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{ stdenv, buildPackages, ghc, lib, pkgconfig, writeText, runCommand, haskellLib, nonReinstallablePkgs }:

{ componentId
let
crossFlags = map (arg: "--hsc2hs-option=" + arg) ["--cross-compile" "--via-asm"];
in { componentId
, component
, package
, name
Expand Down Expand Up @@ -66,13 +68,13 @@ let
# Copy over the nonReinstallablePkgs from the global package db.
# Note: we need to use --global-package-db with ghc-pkg to prevent it
# from looking into the implicit global package db when registering the package.
${lib.concatMapStringsSep "\n" (p: ''
${ghc.targetPrefix}ghc-pkg -v0 describe ${p} | ${ghc.targetPrefix}ghc-pkg -v0 --force --global-package-db $out/package.conf.d register - || true
'') nonReinstallablePkgs}
for pkg in ${toString nonReinstallablePkgs}; do
${ghc.targetPrefix}ghc-pkg -v0 describe ''${pkg} | ${ghc.targetPrefix}ghc-pkg -v0 --force --global-package-db $out/package.conf.d register - || true
done

${lib.concatMapStringsSep "\n" (p: ''
${ghc.targetPrefix}ghc-pkg -v0 --package-db ${p}/package.conf.d dump | ${ghc.targetPrefix}ghc-pkg -v0 --force --package-db $out/package.conf.d register -
'') flatDepends}
for pkg in ${toString flatDepends}; do
${ghc.targetPrefix}ghc-pkg -v0 --package-db ''${pkg}/package.conf.d dump | ${ghc.targetPrefix}ghc-pkg -v0 --force --package-db $out/package.conf.d register -
done

# Note: we pass `clear` first to ensure that we never consult the implicit global package db.
${flagsAndConfig "package-db" ["clear" "$out/package.conf.d"]}
Expand Down Expand Up @@ -140,7 +142,7 @@ let
] ++ lib.optional (deadCodeElimination && stdenv.hostPlatform.isLinux) "--enable-split-sections"
++ lib.optional (static) "--enable-static"
++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) (
map (arg: "--hsc2hs-option=" + arg) ["--cross-compile" "--via-asm"]
crossFlags
++ lib.optional (package.buildType == "Configure") "--configure-option=--host=${stdenv.hostPlatform.config}" )
++ component.configureFlags
);
Expand Down
7 changes: 4 additions & 3 deletions builder/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{ pkgs, buildPackages, stdenv, lib, haskellLib, ghc, buildGHC, fetchurl, writeText, runCommand, pkgconfig, nonReinstallablePkgs }:

let
comp-builder = haskellLib.weakCallPackage pkgs ./comp-builder.nix { inherit ghc haskellLib nonReinstallablePkgs; };
in
{ flags
, package
, components
Expand Down Expand Up @@ -38,7 +41,7 @@ let
main = defaultMain
'';
defaultSetup = buildPackages.runCommand "default-Setup" { nativeBuildInputs = [buildGHC]; } ''
cat ${defaultSetupSrc} > Setup.hs
cp ${defaultSetupSrc} Setup.hs
mkdir -p $out/bin
${buildGHC.targetPrefix}ghc Setup.hs --make -o $out/bin/Setup
'';
Expand Down Expand Up @@ -67,8 +70,6 @@ let
'';
};

comp-builder = haskellLib.weakCallPackage pkgs ./comp-builder.nix { inherit ghc haskellLib nonReinstallablePkgs; };

buildComp = componentId: component: comp-builder {
inherit componentId component package name src flags setup cabalFile patches revision
preUnpack postUnpack preConfigure postConfigure preBuild postBuild preCheck postCheck preInstall postInstall
Expand Down
20 changes: 11 additions & 9 deletions modules/hackage.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,18 @@ let
revision = rev.revNum;
revisionSha256 = rev.sha256;
} // import rev modArgs;
f = rev: acc: acc // {
# If there's a collision (e.g. a revision was
# reverted), pick the one with the smaller
# revNum. They're identical, but if the smaller one is
# r0 then we don't have to download a cabal file.
${rev.sha256} = if lib.hasAttr rev.sha256 acc && acc.${rev.sha256}.revNum < rev.revNum
then acc.${rev.sha256}
else rev;
f = rev: {
name = rev.sha256;
value = rev;
};
contentAddressedRevs = lib.foldr f {} (builtins.attrValues version.revisions);
sortedRevisions = builtins.sort (a: b: a.revNum < b.revNum) (builtins.attrValues version.revisions);
# if you give listToAttrs duplicate keys, the 1st one wins (but
# the internal array for the set will be larger then it needs to
# be). This implicitly means if there were collisions in the
# revsisions (e.g. a version was reverted), we pick the one with
# the samller revNum. They are identical, but if the smaller one
# is r0 then we don't have to download a cabal file.
contentAddressedRevs = builtins.listToAttrs (map f sortedRevisions);
in lib.mapAttrs (_: rev2Config) (version.revisions // contentAddressedRevs);
}));

Expand Down
16 changes: 8 additions & 8 deletions modules/plan.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

{ lib, config, pkgs, pkgconfPkgs, ... }:

with lib;
with types;

{
let
inherit (lib) mkOption mapAttrs filterAttrs mkDefault;
inherit (lib.types) attrsOf submodule str unspecified;
in {
options = {
packages = mkOption {
type = attrsOf (submodule {
Expand Down Expand Up @@ -47,14 +47,14 @@ with types;
};
};

config = let module = config.plan.pkg-def config.hackage.configs; in {
config = let module = config.plan.pkg-def; in {
inherit (module) compiler;
packages = lib.mapAttrs (name: { revision, ... }@revArgs: { system, compiler, flags, pkgs, hsPkgs, pkgconfPkgs, ... }@modArgs:
packages = mapAttrs (name: { revision, ... }@revArgs: { system, compiler, flags, pkgs, hsPkgs, pkgconfPkgs, ... }@modArgs:

let m = if revision == null
then (abort "${name} has no revision!")
else revision modArgs;
in m // { flags = lib.mapAttrs (_: lib.mkDefault) (m.flags // revArgs.flags or {}); }
) (lib.filterAttrs (n: v: v == null || v.revision != null ) module.packages);
in m // { flags = mapAttrs (_: mkDefault) (m.flags // revArgs.flags or {}); }
) (filterAttrs (n: v: v == null || v.revision != null ) module.packages);
};
}
47 changes: 23 additions & 24 deletions package-set.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let f = { hackage, pkgs, pkg-def, pkg-def-overlays ? [], modules ? [] }: let
buildModules = f { inherit hackage pkg-def pkg-def-overlays modules; pkgs = pkgs.buildPackages; };
in pkgs.lib.evalModules {
modules = modules ++ [
({ lib, ... }: {
({ config, lib, ... }: {
# Provide all modules with haskellLib, pkgs, and pkgconfPkgs arguments
_module.args = {
# this is *not* the hasekllLib from nixpkgs; it is rather our own
Expand All @@ -22,7 +22,7 @@ in pkgs.lib.evalModules {
hackage.db = hackage;

# Set the plan for modules/plan.nix
plan.pkg-def = hackage: with builtins;
plan.pkg-def =
# The desugar reason.
#
# it is quite combersome to write
Expand All @@ -33,26 +33,25 @@ in pkgs.lib.evalModules {
# or
# { y = ./foo.nix; }
# As such the desugarer desugars this short hand syntax.
let desugar = overlay:
let
isPath = x: builtins.typeOf x == "path";
# rewrite
# { ... }
# into
# { package = { ... }; }
inject-packages = o: if o ? "packages" then o else { packages = o; };
# rewrite
# x = pkg;
# into
# x.revision = pkg;
inject-revision = pkg: if pkg ? "revision" then pkg else { revision = pkg; };
# rewrite
# x.revision = ./some/path;
# into
# x.revision = import ./some/path;
expand-paths = pkg: if !(isPath pkg.revision) then pkg else { revision = import pkg.revision; };
let
isPath = x: builtins.typeOf x == "path";
# rewrite
# { ... }
# into
# { package = { ... }; }
inject-packages = o: if o ? "packages" then o else { packages = o; };
# rewrite
# x = pkg;
# into
# x.revision = pkg;
inject-revision = pkg: if pkg ? "revision" then pkg else { revision = pkg; };
# rewrite
# x.revision = ./some/path;
# into
# x.revision = import ./some/path;
expand-paths = pkg: if !(isPath pkg.revision) then pkg else { revision = import pkg.revision; };
# apply injection and expansion to the "packages" in overlay.
in lib.mapAttrs (k: v: if k != "packages"
desugar = overlay: lib.mapAttrs (k: v: if k != "packages"
then v
else lib.mapAttrs (_: pkg: (expand-paths (inject-revision pkg))) v)
(inject-packages overlay);
Expand All @@ -61,9 +60,9 @@ in pkgs.lib.evalModules {
#
# This means you can have a base definition (e.g. stackage)
# and augment it with custom packages to your liking.
in foldl' lib.recursiveUpdate
(pkg-def hackage)
(map (p: desugar (if builtins.isFunction p then p hackage else p)) pkg-def-overlays)
in lib.foldl' lib.recursiveUpdate
(pkg-def config.hackage.configs)
(map (p: desugar (if builtins.isFunction p then p config.hackage.configs else p)) pkg-def-overlays)
;

})
Expand Down