Skip to content

Preliminary new-package-set logic #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
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
94 changes: 94 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@

# Created by https://www.gitignore.io/api/haskell,emacs,vim

### Emacs ###
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*

# Org-mode
.org-id-locations
*_archive

# flymake-mode
*_flymake.*

# eshell files
/eshell/history
/eshell/lastdir

# elpa packages
/elpa/

# reftex files
*.rel

# AUCTeX auto folder
/auto/

# cask packages
.cask/
dist/

# Flycheck
flycheck_*.el

# server auth directory
/server/

# projectiles files
.projectile

# directory configuration
.dir-locals.el

### Haskell ###
dist
dist-*
cabal-dev
*.o
*.hi
*.chi
*.chs.h
*.dyn_o
*.dyn_hi
.hpc
.hsenv
.cabal-sandbox/
cabal.sandbox.config
*.prof
*.aux
*.hp
*.eventlog
.stack-work/
cabal.project.local
cabal.project.local~
.HTF/
.ghc.environment.*

### Vim ###
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]

# Session
Session.vim

# Temporary
.netrwhist
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~


# End of https://www.gitignore.io/api/haskell,emacs,vim
108 changes: 108 additions & 0 deletions builder/comp-builder.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{ stdenv, ghc, lib, pkgconfig, writeText, haskellLib }:

{ componentId
, component
, package
, name
, setup
, src
, flags
, cabalFile
}:

let
flagsAndConfig = field: xs: {
flags = map (x: "--${field}=${x}") xs;
config = lib.optional (xs != []) "${field}: ${lib.concatStringsSep " " xs}";
};

allFlagsAndConfigs = {
packageDbs =
let
makePairs = map (p: rec { key="${val}"; val=p.components.${p.identifier.name}; });
closure = builtins.genericClosure {
startSet = makePairs component.depends;
operator = {val,...}: makePairs val.config.depends;
};
flatDepends = map ({val,...}: val) closure;
in flagsAndConfig "package-db" (map (p: "${p}/package.conf.d") flatDepends);

extraLibDirs = flagsAndConfig "extra-lib-dirs" (map (p: "${p}/lib") component.libs);
extraIncludeDirs = flagsAndConfig "extra-include-dirs" (map (p: "${lib.getDev p}/include") component.libs);
extraFameworks = flagsAndConfig "extra-framework-dirs" (map (p: "${p}/Library/Frameworks") component.frameworks);
userFlags = {
flags = [("--flags=\"" + lib.concatStringsSep " " (lib.mapAttrsToList (fname: val: lib.optionalString (!val) "-" + fname) flags) + "\"")];
config = [];
};
};

finalConfigureFlags = lib.concatStringsSep " " (
[ "--prefix=$out" "${componentId.ctype}:${componentId.cname}" ]
++ builtins.concatLists (lib.mapAttrsToList (_: x: x.flags) allFlagsAndConfigs)
++ component.configureFlags
);
in stdenv.mkDerivation {
name = "${name}-${componentId.ctype}-${componentId.cname}";

inherit src;

doCheck = componentId.ctype == "test";

passthru = {
inherit (package) identifier;
config = component;
};

meta = {
homepage = package.homepage;
description = package.synopsis;
license = (import ../lib/cabal-licenses.nix lib).${package.license};
};

CABAL_CONFIG = writeText
"package-db-cabal.config"
(lib.concatStringsSep "\n" (builtins.concatLists (lib.mapAttrsToList (_: x: x.config) allFlagsAndConfigs)));

enableParallelBuilding = true;

buildInputs = component.libs
++ component.pkgconfig;

nativeBuildInputs =
[ghc]
++ lib.optional (component.pkgconfig != []) pkgconfig
++ lib.concatMap (c: if c.isHaskell or false
then builtins.attrValues (c.components.exes or {})
else [c]) component.build-tools;

SETUP_HS = setup + /bin/Setup;

# Phases
prePatch = lib.optionalString (cabalFile != null) ''
cat ${cabalFile} > ${package.identifier.name}.cabal
'';

configurePhase = ''
echo Configure flags:
printf "%q " ${finalConfigureFlags}
echo
$SETUP_HS configure ${finalConfigureFlags}
'';

buildPhase = ''
$SETUP_HS build -j$NIX_BUILD_CORES
'';

checkPhase = ''
$SETUP_HS test
'';

installPhase = ''
$SETUP_HS copy
${lib.optionalString (haskellLib.isLibrary componentId) ''
$SETUP_HS register --gen-pkg-config=${name}.conf
ghc-pkg init $out/package.conf.d
ghc-pkg ${lib.concatStringsSep " " allFlagsAndConfigs.packageDbs.flags} -f $out/package.conf.d register ${name}.conf
''}
'';
}
81 changes: 81 additions & 0 deletions builder/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{ pkgs, stdenv, lib, haskellLib, ghc, fetchurl, writeText, runCommand, pkgconfig, weakCallPackage }:

{ flags ? {}
, package ? {}
, components ? {}

, name ? "${package.identifier.name}-${package.identifier.version}"
, sha256 ? null
, src ? fetchurl { url = "mirror://hackage/${name}.tar.gz"; inherit sha256; }
, revision ? null
, revisionSha256 ? null
}@config:

let
cabalFile = if revision == null || revision == 0 then null else
fetchurl {
url = "https://hackage.haskell.org/package/${name}/revision/${toString revision}.cabal";
sha256 = revisionSha256;
};
defaultSetupSrc = builtins.toFile "Setup.hs" ''
import Distribution.Simple
main = defaultMain
'';
defaultSetup = runCommand "default-Setup" { nativeBuildInputs = [ghc]; } ''
cat ${defaultSetupSrc} > Setup.hs
ghc Setup.hs --make -o $out
'';

setup = stdenv.mkDerivation {
name = "${name}-setup";
nativeBuildInputs = [ghc];
inherit src;
phases = ["unpackPhase" "buildPhase" "installPhase"];
buildPhase = ''
setup=${defaultSetup}
for f in Setup.hs Setup.lhs; do
if [ -f $f ]; then
if ! (diff $f ${defaultSetupSrc} > /dev/null); then
echo Compiling package $f
ghc $f --make -o ./Setup
setup=$(pwd)/Setup
else
echo Using default Setup
fi
break
fi
done
'';

installPhase = ''
mkdir -p $out/bin
install $setup $out/bin/Setup
'';
};

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

buildComp = componentId: component: comp-builder {
inherit componentId package name src flags setup cabalFile;
component =
let
nonNullLists = fs: component // lib.genAttrs fs (field:
if component ? ${field}
then builtins.filter (x: x != null) component.${field}
else []);
in nonNullLists [
"depends"
"libs"
"frameworks"
"pkgconfig"
"build-tools"
"configureFlags"
];
};

in {
components = haskellLib.applyComponents buildComp components;
inherit (package) identifier;
inherit setup cabalFile;
isHaskell = true;
}
Loading