Skip to content

Commit

Permalink
Merge pull request #26 from input-output-hk/jbgi/flake-fixes
Browse files Browse the repository at this point in the history
flake fixes
  • Loading branch information
disassembler authored Jun 15, 2023
2 parents ddd7ab9 + cd64934 commit cb784dc
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 123 deletions.
35 changes: 35 additions & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
********************************************
Contributing to the ``cardano-cli`` project
********************************************

Updating dependencies
====

... from Hackage
----

Updating package dependencies from Hackage should work like normal in a Haskell project.
The most important thing to note is that we pin the ``index-state`` of the Hackage package index in ``cabal.project``.
This means that cabal will always see Hackage “as if” it was that time, ensuring reproducibility.
But it also means that if you need a package version that was released *after* that time, you need to bump the ``index-state`` (and to run ``cabal update`` locally).

Because of how we use Nix to manage our Haskell build, whenever you do this you will also need to pull in the Nix equivalent of the newer ``index-state``.
You can do this by running ``nix flake lock --update-input haskellNix/hackage``.

... from the Cardano package repository
----

Many Cardano packages are not on Hackage and are instead in the `Cardano package repository <https://github.com/input-output-hk/cardano-haskell-packages>`__, see the README for (lots) more information.
Getting new packages from there works much like getting them from Hackage.
The differences are that it has an independent ``index-state``, and that there is a different Nix command you need to run afterwards: ``nix flake lock --update-input CHaP``.

Using unreleased versions of dependencies
~~~~

Sometimes we need to use an unreleased version of one of our dependencies, either to fix an issue in a package that is not under our control, or to experiment with a pre-release version of one of our own packages.
You can use a ``source-repository-package`` stanza to pull in the unreleased version.
Try only to do this for a short time, as it does not play very well with tooling, and will interfere with the ability to release the node itself.

For packages that we do not control, we can end up in a situation where we have a fork that looks like it will be long-lived or permanent (e.g. the maintainer is unresponsive, or the change has been merged but not released).
In that case, release a patched version to the `Cardano package repository <https://github.com/input-output-hk/cardano-haskell-packages>`__, which allows us to remove the ``source-repository-package`` stanza.
See the README for instructions.
17 changes: 0 additions & 17 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

164 changes: 58 additions & 106 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

CHaP.url = "github:input-output-hk/cardano-haskell-packages?ref=repo";
CHaP.flake = false;

cardano-mainnet-mirror.url = "github:input-output-hk/cardano-mainnet-mirror";
cardano-mainnet-mirror.flake = false;
};

outputs = inputs: let
Expand All @@ -23,9 +20,10 @@
#"aarch64-linux"
#"aarch64-darwin"
];
in { inherit (inputs) incl; } //
inputs.flake-utils.lib.eachSystem supportedSystems (
system: let
in
{inherit (inputs) incl;}
// inputs.flake-utils.lib.eachSystem supportedSystems (
system: let
# setup our nixpkgs with the haskell.nix overlays, and the iohk-nix
# overlays...
nixpkgs = import inputs.nixpkgs {
Expand Down Expand Up @@ -53,8 +51,8 @@

# we also want cross compilation to windows on linux (and only with default compiler).
crossPlatforms = p:
lib.optional (system == "x86_64-linux" && config.compiler-nix-name == defaultCompiler)
p.mingwW64;
lib.optional (system == "x86_64-linux" && config.compiler-nix-name == defaultCompiler)
p.mingwW64;

# CHaP input map, so we can find CHaP packages (needs to be more
# recent than the index-state we set!). Can be updated with
Expand All @@ -72,13 +70,12 @@
}
// lib.optionalAttrs (config.compiler-nix-name == defaultCompiler) {
# tools that work only with default compiler
fourmolu = "0.10.1.0";
stylish-haskell = "0.14.4.0";
hlint = "3.5";
#haskell-language-server = "2.0.0.0";
};
# and from nixpkgs or other inputs
shell.nativeBuildInputs = with nixpkgs; [
haskellPackages.implicit-hie
];
# disable Hoogle until someone request it
shell.withHoogle = false;
Expand All @@ -89,104 +86,59 @@
# specific enough, or doesn't allow setting these.
modules = [
({pkgs, ...}: {
packages.byron-spec-chain.configureFlags = ["--ghc-option=-Werror"];
packages.byron-spec-ledger.configureFlags = ["--ghc-option=-Werror"];
packages.delegation.configureFlags = ["--ghc-option=-Werror"];
packages.non-integral.configureFlags = ["--ghc-option=-Werror"];
packages.cardano-cli-shelley.configureFlags = ["--ghc-option=-Werror"];
packages.cardano-cli-shelley-ma.configureFlags = ["--ghc-option=-Werror"];
packages.cardano-cli-shelley-ma-test.configureFlags = ["--ghc-option=-Werror"];
packages.small-steps.configureFlags = ["--ghc-option=-Werror"];
packages.cardano-cli-byron = {
configureFlags = ["--ghc-option=-Werror"];
components = {
tests.cardano-cli-byron-test = {
preCheck = ''
export CARDANO_MAINNET_MIRROR="${inputs.cardano-mainnet-mirror}/epochs"
cp ${./eras/byron/ledger/impl/mainnet-genesis.json} ./mainnet-genesis.json
'';
testFlags = ["--scenario=ContinuousIntegration"];
};
};
};
packages.cardano-cli.configureFlags = ["--ghc-option=-Werror"];
packages.cardano-cli.components.tests.cardano-cli-test.build-tools =
lib.mkForce (with pkgs.buildPackages; [ jq coreutils shellcheck ]);
lib.mkForce (with pkgs.buildPackages; [jq coreutils shellcheck]);
packages.cardano-cli.components.tests.cardano-cli-golden.build-tools =
lib.mkForce (with pkgs.buildPackages; [ jq coreutils shellcheck ]);
})
({ pkgs, config, ... }:
let
exportCliPath = "export CARDANO_CLI=${config.hsPkgs.cardano-cli.components.exes.cardano-cli}/bin/cardano-cli${pkgs.stdenv.hostPlatform.extensions.executable}";
mainnetConfigFiles = [
"configuration/cardano/mainnet-config.yaml"
"configuration/cardano/mainnet-config.json"
"configuration/cardano/mainnet-byron-genesis.json"
"configuration/cardano/mainnet-shelley-genesis.json"
"configuration/cardano/mainnet-alonzo-genesis.json"
"configuration/cardano/mainnet-conway-genesis.json"
];
goldenConfigFiles = [
"cardano-cli/test/cardano-cli-golden/files/golden/alonzo/genesis.alonzo.spec.json"
"cardano-cli/test/cardano-cli-golden/files/golden/conway/genesis.conway.spec.json"
];
in
{
# cardano-cli tests depend on cardano-cli and some config files:
packages.cardano-cli.components.tests.cardano-cli-golden.preCheck =
let
# This define files included in the directory that will be passed to `H.getProjectBase` for this test:
filteredProjectBase = inputs.incl ./. [
"cabal.project"
"scripts/plutus/scripts/v1/custom-guess-42-datum-42.plutus"
];
in
''
${exportCliPath}
cp -r ${filteredProjectBase}/* ..
'';
packages.cardano-cli.components.tests.cardano-cli-test.preCheck =
let
# This define files included in the directory that will be passed to `H.getProjectBase` for this test:
filteredProjectBase = inputs.incl ./. mainnetConfigFiles;
in
''
${exportCliPath}
cp -r ${filteredProjectBase}/* ..
'';
lib.mkForce (with pkgs.buildPackages; [jq coreutils shellcheck]);
})
({pkgs, ...}:
lib.mkIf pkgs.stdenv.hostPlatform.isUnix {
packages.cardano-cli-shelley-ma-test.components.tests.cardano-ledger-shelley-ma-test.build-tools = [pkgs.cddl pkgs.cbor-diag];
packages.cardano-cli-shelley-test.components.tests.cardano-ledger-shelley-test.build-tools = [pkgs.cddl pkgs.cbor-diag];
packages.cardano-cli-alonzo-test.components.tests.cardano-ledger-alonzo-test.build-tools = [pkgs.cddl pkgs.cbor-diag];
packages.cardano-cli-babbage-test.components.tests.cardano-ledger-babbage-test.build-tools = [pkgs.cddl pkgs.cbor-diag];
packages.cardano-cli-conway-test.components.tests.cardano-ledger-conway-test.build-tools = [pkgs.cddl pkgs.cbor-diag];
})
({pkgs, ...}:
lib.mkIf pkgs.stdenv.hostPlatform.isWindows {
packages.set-algebra.components.tests.tests.buildable = lib.mkForce false;
packages.plutus-preprocessor.package.buildable = lib.mkForce false;
packages.cardano-cli-test.package.buildable = lib.mkForce false;
packages.cardano-cli-shelley-ma-test.package.buildable = lib.mkForce false;
packages.cardano-cli-shelley-test.package.buildable = lib.mkForce false;
packages.cardano-cli-alonzo-test.package.buildable = lib.mkForce false;
packages.cardano-cli-babbage-test.package.buildable = lib.mkForce false;
packages.cardano-cli-conway-test.package.buildable = lib.mkForce false;
({
pkgs,
config,
...
}: let
exportCliPath = "export CARDANO_CLI=${config.hsPkgs.cardano-cli.components.exes.cardano-cli}/bin/cardano-cli${pkgs.stdenv.hostPlatform.extensions.executable}";
mainnetConfigFiles = [
"configuration/cardano/mainnet-config.yaml"
"configuration/cardano/mainnet-config.json"
"configuration/cardano/mainnet-byron-genesis.json"
"configuration/cardano/mainnet-shelley-genesis.json"
"configuration/cardano/mainnet-alonzo-genesis.json"
"configuration/cardano/mainnet-conway-genesis.json"
];
in {
# cardano-cli tests depend on cardano-cli and some config files:
packages.cardano-cli.components.tests.cardano-cli-golden.preCheck = let
# This define files included in the directory that will be passed to `H.getProjectBase` for this test:
filteredProjectBase = inputs.incl ./. [
"cabal.project"
"scripts/plutus/scripts/v1/custom-guess-42-datum-42.plutus"
];
in ''
${exportCliPath}
cp -r ${filteredProjectBase}/* ..
'';
packages.cardano-cli.components.tests.cardano-cli-test.preCheck = let
# This define files included in the directory that will be passed to `H.getProjectBase` for this test:
filteredProjectBase = inputs.incl ./. mainnetConfigFiles;
in ''
${exportCliPath}
cp -r ${filteredProjectBase}/* ..
'';
})
];
});
# ... and construct a flake from the cabal project
flake =
cabalProject.flake (
lib.optionalAttrs (system == "x86_64-linux") {
# on linux, build/test other supported compilers
variants = lib.genAttrs ["ghc8107"] (compiler-nix-name: {
inherit compiler-nix-name;
});
}
);
flake = cabalProject.flake (
lib.optionalAttrs (system == "x86_64-linux") {
# on linux, build/test other supported compilers
variants = lib.genAttrs ["ghc8107"] (compiler-nix-name: {
inherit compiler-nix-name;
});
}
);
in
lib.recursiveUpdate flake rec {
lib.recursiveUpdate flake rec {
# add a required job, that's basically all hydraJobs.
hydraJobs =
nixpkgs.callPackages inputs.iohkNix.utils.ciJobsAggregates
Expand All @@ -197,9 +149,9 @@
# This ensure hydra send a status for the required job (even if no change other than commit hash)
revision = nixpkgs.writeText "revision" (inputs.self.rev or "dirty");
};
};
legacyPackages = rec {
inherit cabalProject nixpkgs;
};
legacyPackages = rec {
inherit cabalProject nixpkgs;
# also provide hydraJobs through legacyPackages to allow building without system prefix:
inherit hydraJobs;
# expose cardano-cli binary at top-level
Expand All @@ -211,17 +163,17 @@
profiling = (p.appendModule {modules = [{enableLibraryProfiling = true;}];}).shell;
};
in
profillingShell cabalProject
profillingShell cabalProject
# Additional shells for every GHC version supported by haskell.nix, eg. `nix develop .#ghc927`
// lib.mapAttrs (compiler-nix-name: _: let
p = cabalProject.appendModule {inherit compiler-nix-name;};
in
p.shell // (profillingShell p))
p.shell // (profillingShell p))
nixpkgs.haskell-nix.compiler;
# formatter used by nix fmt
formatter = nixpkgs.alejandra;
}
);
);

nixConfig = {
extra-substituters = [
Expand Down

0 comments on commit cb784dc

Please sign in to comment.