Skip to content
Merged
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
20 changes: 20 additions & 0 deletions Building.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,23 @@ https://github.com/ocaml/dune/issues/57 to see when a coverage report is viable
_pass_ it the path to the binary.)


## Updating Haskell Packages

When the `.cabal` file of a Haskell package is changed you need to make sure the
corresponding `default.nix` file (stored in the same directory as the `.cabal`
file) is kept in sync with it.

As mentioned in the `default.nix` files, these files are automatically generated:

```
# THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT EDIT MANUALLY!
# To regenerate this file execute the following command in this directory:
#
# cp $(nix-build ./generate.nix --no-link)/default.nix ./default.nix
```

Note that they also contain the instructions on how to update them.

Don't worry if you forget to update the `default.nix` file. There are CI jobs
(like [`haskellSrc2nix.lsp-int`](https://hydra.dfinity.systems/job/dfinity-ci-build/motoko/haskellSrc2nix.lsp-int)
that check if the files are in sync and fail with a diff if they aren't.
19 changes: 19 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,25 @@ rec {
};
stdlib-adocs = stdlib-doc.adocs;

haskellSrc2nix =
let
check = dir: nixpkgs.runCommandNoCC "check-${builtins.baseNameOf dir}" {
preferLocalBuild = true;
allowSubstitutes = false;
nativeBuildInputs = [ nixpkgs.diffutils ];
expected = import (dir + "/generate.nix") { pkgs = nixpkgs; };
inherit dir;
} ''
diff -U 3 $expected/default.nix $dir/default.nix
touch $out
'';
in {
lsp-int = check ./test/lsp-int;
qc-motoko = check ./test/random;
ic-stub = check ./ic-stub;
winter = check ./winter;
};

all-systems-go = nixpkgs.releaseTools.aggregate {
name = "all-systems-go";
constituents = [
Expand Down
24 changes: 24 additions & 0 deletions ic-stub/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT EDIT MANUALLY!
# To regenerate this file execute the following command in this directory:
#
# cp $(nix-build ./generate.nix --no-link)/default.nix ./default.nix
{ mkDerivation, base, binary, bytestring, containers
, data-default-class, filepath, hex-text, mtl, optparse-applicative
, primitive, stdenv, text, transformers, utf8-string, vector
, winter
}:
mkDerivation {
pname = "ic-stub";
version = "0.1.0.0";
src = ./.;
isLibrary = false;
isExecutable = true;
executableHaskellDepends = [
base binary bytestring containers data-default-class filepath
hex-text mtl optparse-applicative primitive text transformers
utf8-string vector winter
];
doCheck = false;
license = "unknown";
hydraPlatforms = stdenv.lib.platforms.none;
}
1 change: 1 addition & 0 deletions ic-stub/generate.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ pkgs ? import ../nix {} }: pkgs.localHaskellSrc2nixWithDoc "ic-stub" ./. "--no-check"
40 changes: 40 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,46 @@ let
};
}
)
(self: super: {
# A variant of `haskellSrc2nixWithDoc` for local Haskell packages.
localHaskellSrc2nixWithDoc = name: path: extraCabal2nixOptions:
self.haskellSrc2nixWithDoc {
inherit name extraCabal2nixOptions;
src = import ./gitSource.nix path;
src_subst = "./.";
};

# `haskellSrc2nixWithDoc` is used to generate `default.nix` files for
# Haskell packages which are intended to be stored in the repository.
#
# The function generates a directory containing a `default.nix` which
# is the result of running `cabal2nix` with the `extraCabal2nixOptions`
# on the provided `src`.
#
# A header is added to `default.nix` which contains instructions on
# how to regenerate that file.
#
# Finally the `src` attribute in the `default.nix` will be defined as
# `src_subst` such that it can be pointed to local or niv-managed
# sources.
haskellSrc2nixWithDoc = {name, src, src_subst, extraCabal2nixOptions}:
let
drv = pkgs.haskellPackages.haskellSrc2nix {
inherit name extraCabal2nixOptions src;
};
in drv.overrideAttrs (oldAttrs: {
message = ''
# THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT EDIT MANUALLY!\
# To regenerate this file execute the following command in this directory:\
#\
# cp $(nix-build ./generate.nix --no-link)/default.nix ./default.nix
'';
inherit src_subst;
installPhase = oldAttrs.installPhase + ''
sed -i "1i$message;s|src = .*|src = $src_subst;|" $out/default.nix
'';
});
})
];
};
in
Expand Down
8 changes: 4 additions & 4 deletions nix/haskell-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ nix: subpath:

lsp-test = nix.haskell.lib.dontCheck self.lsp-test_0_10_1_0;

lsp-int = self.callCabal2nix "lsp-int" (subpath "test/lsp-int") { };
lsp-int = super.callPackage ../test/lsp-int {};

qc-motoko = self.callCabal2nix "qc-motoko" (subpath "test/random") { };
qc-motoko = super.callPackage ../test/random {};

winter = self.callCabal2nixWithOptions "winter" nix.sources.winter "--no-check" {};
winter = super.callPackage ../winter {};

ic-stub = self.callCabal2nixWithOptions "ic-stub" (subpath "ic-stub") "-frelease" { };
ic-stub = super.callPackage ../ic-stub {};
}
21 changes: 21 additions & 0 deletions test/lsp-int/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT EDIT MANUALLY!
# To regenerate this file execute the following command in this directory:
#
# cp $(nix-build ./generate.nix --no-link)/default.nix ./default.nix
{ mkDerivation, base, data-default, directory, filepath
, haskell-lsp-types, hspec, HUnit, lens, lsp-test, stdenv, text
}:
mkDerivation {
pname = "lsp-int";
version = "0";
src = ./.;
isLibrary = false;
isExecutable = true;
executableHaskellDepends = [
base data-default directory filepath haskell-lsp-types hspec HUnit
lens lsp-test text
];
description = "Integration tests for the language server";
license = "unknown";
hydraPlatforms = stdenv.lib.platforms.none;
}
1 change: 1 addition & 0 deletions test/lsp-int/generate.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ pkgs ? import ../../nix {} }: pkgs.localHaskellSrc2nixWithDoc "lsp-int" ./. ""
22 changes: 22 additions & 0 deletions test/random/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT EDIT MANUALLY!
# To regenerate this file execute the following command in this directory:
#
# cp $(nix-build ./generate.nix --no-link)/default.nix ./default.nix
{ mkDerivation, base, exceptions, managed, process, QuickCheck
, quickcheck-text, quickcheck-unicode, stdenv, tasty
, tasty-quickcheck, text, turtle
}:
mkDerivation {
pname = "qc-motoko";
version = "1";
src = ./.;
isLibrary = false;
isExecutable = true;
executableHaskellDepends = [
base exceptions managed process QuickCheck quickcheck-text
quickcheck-unicode tasty tasty-quickcheck text turtle
];
description = "generate randomised tests for Motoko";
license = "unknown";
hydraPlatforms = stdenv.lib.platforms.none;
}
1 change: 1 addition & 0 deletions test/random/generate.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ pkgs ? import ../../nix {} }: pkgs.localHaskellSrc2nixWithDoc "qc-motoko" ./. ""
38 changes: 38 additions & 0 deletions winter/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT EDIT MANUALLY!
# To regenerate this file execute the following command in this directory:
#
# cp $(nix-build ./generate.nix --no-link)/default.nix ./default.nix
{ mkDerivation, pkgs, array, base, binary, byte-order, bytestring
, cmdargs, containers, data-default-class, data-fix, deepseq
, directory, filepath, FloatingHex, lifted-base, microlens-platform
, monad-control, mtl, nats, parsec, primitive, primitive-unaligned
, process, stdenv, tasty, tasty-hunit, tasty-quickcheck, temporary
, text, transformers, vector
}:
mkDerivation {
pname = "winter";
version = "1.0.0";
src = pkgs.sources.winter;
isLibrary = true;
isExecutable = true;
libraryHaskellDepends = [
array base binary byte-order bytestring containers
data-default-class data-fix deepseq FloatingHex lifted-base
microlens-platform monad-control mtl nats parsec primitive
primitive-unaligned text transformers vector
];
executableHaskellDepends = [
base binary bytestring cmdargs containers data-default-class mtl
parsec text
];
testHaskellDepends = [
array base binary bytestring containers data-default-class data-fix
deepseq directory filepath FloatingHex lifted-base
microlens-platform monad-control mtl parsec primitive process tasty
tasty-hunit tasty-quickcheck temporary text transformers vector
];
doCheck = false;
homepage = "https://github.com/dfinity/winter";
description = "Haskell port of the WebAssembly OCaml reference interpreter";
license = stdenv.lib.licenses.mit;
}
15 changes: 15 additions & 0 deletions winter/generate.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ pkgs ? import ../nix {} }:
let
drv = pkgs.haskellSrc2nixWithDoc {
name = "winter";
src = pkgs.sources.winter;
src_subst = "pkgs.sources.winter";
extraCabal2nixOptions = "--no-check";
};
in
drv.overrideAttrs (oldAttrs: {
installPhase = oldAttrs.installPhase + ''
# Accept `pkgs` as an argument because the `src` depends on it.
sed -i "s|{ mkDerivation|{ mkDerivation, pkgs|" $out/default.nix
'';
})