Skip to content

Commit

Permalink
More nix experiments
Browse files Browse the repository at this point in the history
`nix/static` is a plain `nixpkgs` setup, and almost builds a static
version of the binary, if it were not for
nh2/static-haskell-nix#14

`nix/` is using the tooling at https://github.com/input-output-hk/iohk-nix
as advised by @angerman, but it currenty fails to download or build
`/nix/store/j6m77ilz08bsdhs8cba9i0mhs4lw0vak-ghc-8.4.4.drv` because some
patches do not apply. Or something.
  • Loading branch information
nomeata committed Mar 7, 2019
1 parent f14e5bc commit 5c7495d
Show file tree
Hide file tree
Showing 12 changed files with 485 additions and 41 deletions.
27 changes: 27 additions & 0 deletions nix-static/HPDF.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{ mkDerivation, array, base, base64-bytestring, binary, bytestring
, containers, errors, filepath, HTF, mtl, network-uri, parsec
, random, stdenv, text, vector, zlib, fetchgit
}:
mkDerivation {
pname = "HPDF";
version = "1.4.10";
src = fetchgit {
url = "https://github.com/nomeata/HPDF";
rev = "1062cf0378c6bff384380101821e6744d41d0484";
sha256 = "0jjam8s0sl9abgd1a9l6d0ilmzp0l34kvw24548m10r3fg7jc6kd";
};
isLibrary = true;
isExecutable = false;
enableSeparateDataOutput = true;
libraryHaskellDepends = [
array base base64-bytestring binary bytestring containers errors
filepath mtl network-uri parsec random text vector zlib
];
executableHaskellDepends = [
base filepath network-uri random text vector
];
testHaskellDepends = [ base HTF ];
homepage = "http://www.alpheccar.org";
description = "Generation of PDF documents";
license = stdenv.lib.licenses.bsd3;
}
30 changes: 30 additions & 0 deletions nix-static/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
static ? false,
windows ? false
}:

let mypkgs = new: old: rec {
HPDF = new.callPackage ./HPDF.nix { };
tttool = new.callPackage ./project.nix {inherit static; };
}; in

let
config = {
packageOverrides = pkgs: {
haskellPackages = pkgs.haskellPackages.override { overrides = mypkgs; };
haskell = pkgs.haskell // {
packages = pkgs.haskell.packages // {
ghc843 = pkgs.haskell.packages.ghc843.override { overrides = mypkgs; };
};
};
};
};

pkgs = import ./nixpkgs { inherit config; };

in
if windows
then pkgs.pkgsCross.mingw32.haskellPackages.tttool
else if static
then pkgs.pkgsMusl.haskell.packages.ghc843.tttool
else pkgs.haskellPackages.tttool
8 changes: 8 additions & 0 deletions nix-static/nixpkgs/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let
fetchFromGitHub = if (builtins ? "fetchTarball")
then { owner, repo, rev, sha256 }: builtins.fetchTarball {
inherit sha256;
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
}
else (import <nixpkgs> {}).fetchFromGitHub;
in import (fetchFromGitHub (builtins.fromJSON (builtins.readFile ./github.json)))
6 changes: 6 additions & 0 deletions nix-static/nixpkgs/github.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "2c07921cff84dfb0b9e0f6c2d10ee2bfee6a85ac",
"sha256": "1sxh54zxqy54vrak203qci4128z9mxnzfr5bb5pl6xdrdkcdpqrn"
}
10 changes: 9 additions & 1 deletion nix/project.nix → nix-static/project.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
, optparse-applicative, parsec, process, random, split, spool
, stdenv, template-haskell, text, time, vector, yaml, zlib
, pkgs
, static
}:

let sourceByRegex = src: regexes: builtins.filterSource (path: type:
Expand All @@ -14,7 +15,7 @@ let sourceByRegex = src: regexes: builtins.filterSource (path: type:

mkDerivation {
pname = "tttool";
version = "1.8";
version = "1.8.1";
src = sourceByRegex ../. [
"src/"
"src/.*"
Expand All @@ -32,4 +33,11 @@ mkDerivation {
homepage = "https://github.com/entropia/tip-toi-reveng";
description = "Working with files for the Tiptoi® pen";
license = stdenv.lib.licenses.mit;

configureFlags = pkgs.lib.optional static [
"--ghc-option=-optl=-static"
"--extra-lib-dirs=${pkgs.gmp6.override { withStatic = true; }}/lib"
"--extra-lib-dirs=${pkgs.zlib.static}/lib"
"--extra-lib-dirs=${pkgs.ncurses5.override { enableStatic = true; }}/lib"
];
}
75 changes: 48 additions & 27 deletions nix/HPDF.nix
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
{ mkDerivation, array, base, base64-bytestring, binary, bytestring
, containers, errors, filepath, HTF, mtl, network-uri, parsec
, random, stdenv, text, vector, zlib, fetchgit
}:
mkDerivation {
pname = "HPDF";
version = "1.4.10";
src = fetchgit {
url = "https://github.com/nomeata/HPDF";
rev = "1062cf0378c6bff384380101821e6744d41d0484";
sha256 = "0jjam8s0sl9abgd1a9l6d0ilmzp0l34kvw24548m10r3fg7jc6kd";
};
isLibrary = true;
isExecutable = false;
enableSeparateDataOutput = true;
libraryHaskellDepends = [
array base base64-bytestring binary bytestring containers errors
filepath mtl network-uri parsec random text vector zlib
];
executableHaskellDepends = [
base filepath network-uri random text vector
];
testHaskellDepends = [ base HTF ];
homepage = "http://www.alpheccar.org";
description = "Generation of PDF documents";
license = stdenv.lib.licenses.bsd3;
}
{ system, compiler, flags, pkgs, hsPkgs, pkgconfPkgs, ... }:

let
src = pkgs.fetchgit {
url = "https://github.com/nomeata/HPDF";
rev = "1062cf0378c6bff384380101821e6744d41d0484";
sha256 = "0jjam8s0sl9abgd1a9l6d0ilmzp0l34kvw24548m10r3fg7jc6kd";
};
in

{
flags = {};
package = {
specVersion = "1.10";
identifier = { name = "HPDF"; version = "1.4.10"; };
license = "BSD-3-Clause";
copyright = "Copyright (c) 2007-2016, alpheccar.org";
maintainer = "misc@NOSPAMalpheccar.org";
author = "";
homepage = "http://www.alpheccar.org";
url = "";
synopsis = "Generation of PDF documents";
description = "A PDF library with support for several pages, page transitions, outlines, annotations, compression, colors, shapes, patterns, jpegs, fonts, typesetting ... Have a look at the \"Graphics.PDF.Documentation\" module to see how to use it. Or, download the package and look at the test.hs file in the Test folder. That file is giving an example of each feature.";
buildType = "Simple";
};
components = {
"library" = {
depends = [
(hsPkgs.base)
(hsPkgs.containers)
(hsPkgs.random)
(hsPkgs.bytestring)
(hsPkgs.array)
(hsPkgs.zlib)
(hsPkgs.binary)
(hsPkgs.mtl)
(hsPkgs.vector)
(hsPkgs.errors)
(hsPkgs.base64-bytestring)
];
};
tests = {
"HPDF-Tests" = {
depends = [ (hsPkgs.base) (hsPkgs.HTF) (hsPkgs.HPDF) ];
};
};
};
} // rec { inherit src; }
61 changes: 48 additions & 13 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,51 @@
let
config = {
packageOverrides = pkgs: rec {
haskellPackages = pkgs.haskellPackages.override {
overrides = haskellPackagesNew: haskellPackagesOld: rec {
HPDF = haskellPackagesNew.callPackage ./HPDF.nix { };
tttool = haskellPackagesNew.callPackage ./project.nix { };
};
};
};
};
localLib = import ./lib.nix;
in
{ ... }@args:
localLib.nix-tools.default-nix ./pkgs.nix args

pkgs = import ./nixpkgs { inherit config; };

in
pkgs.haskellPackages.tttool
# { pkgs ? import ./nixpkgs {}
# }:
# let
# overrideWith = override: default:
# let
# try = builtins.tryEval (builtins.findFile builtins.nixPath override);
# in if try.success then
# builtins.trace "using search host <${override}>" try.value
# else
# default;
# in
#
# let
# haskellLib = pkgs.fetchFromGitHub {
# owner = "input-output-hk";
# repo = "haskell.nix";
# rev = "3c78fdaede42abe88936a55ecffbadf533cb3d28";
# sha256 = "06rmib2hza6s5gvx52dqw905pc4rmcwxj7xyafk21nbbh76l5rmw";
# name = "haskell-lib-source";
# };
# haskell = import (overrideWith "haskell" haskellLib) { inherit pkgs; };
# in
#
# let
# my-pkgs = import ./pkgs.nix;
#
# pkgSet = haskell.mkPkgSet {
# pkg-def = my-pkgs.pkg-def;
# pkg-def-overlays = [
# # this overlay will provide additional packages
# # ontop of the package set. E.g. extra-deps
# # for stack packages. or local packages for
# # cabal.projects
# my-pkgs.overlay
# ];
# modules = [
# # specific package overrides would go here
# # example:
# # packages.cbors.patches = [ ./one.patch ];
# # packages.cbors.flags.optimize-gmp = false;
# ];
# };
#
# in pkgSet.config.hsPkgs // { _config = pkgSet.config; }
6 changes: 6 additions & 0 deletions nix/iohk-nix.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"url": "https://github.com/input-output-hk/iohk-nix",
"rev": "c92f0119ef5814b0ed1f445c2fdcf8894e326294",
"sha256": "05r90x6x3yp1nb66rkc4n0i8q15c634rrdsr2zvb118s3sdcmmrm",
"fetchSubmodules": false
}
18 changes: 18 additions & 0 deletions nix/lib.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
let
# iohk-nix can be overridden for debugging purposes by setting
# NIX_PATH=iohk_nix=/path/to/iohk-nix
iohkNix = import (
let try = builtins.tryEval <iohk_nix>;
in if try.success
then builtins.trace "using host <iohk_nix>" try.value
else
let
spec = builtins.fromJSON (builtins.readFile ./iohk-nix.json);
in builtins.fetchTarball {
url = "${spec.url}/archive/${spec.rev}.tar.gz";
inherit (spec) sha256;
}) {};

pkgs = iohkNix.pkgs;
lib = pkgs.lib;
in lib // { inherit iohkNix pkgs; inherit (iohkNix) nix-tools; }
32 changes: 32 additions & 0 deletions nix/pkgs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# let plan = import ./plan.nix; in
# { pkg-def = plan;
# overlay =
# { tttool = ./tttool.nix;
# HPDF = ./HPDF2.nix;
# };
# }

{ pkgs ? import <nixpkgs> {}
, haskell
, ...
}:
let

# Build the packageset with module support.
# We can essentially override anything in the modules
# section.
#
# packages.cbors.patches = [ ./one.patch ];
# packages.cbors.flags.optimize-gmp = false;
#
pkgSet = haskell.mkPkgSet {
inherit pkgs;
pkg-def = import ./plan.nix;
pkg-def-overlays = [
{ tttool = ./tttool.nix;
HPDF = ./HPDF.nix;
}];
modules = [ ];
};
in
pkgSet.config.hsPkgs // { _config = pkgSet.config; }
Loading

0 comments on commit 5c7495d

Please sign in to comment.