Skip to content

Commit

Permalink
Major flake restructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelpj committed Mar 17, 2023
1 parent a607686 commit 5a43ce3
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 39 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/CI.yml
Expand Up @@ -106,11 +106,6 @@ jobs:
runs-on: ubuntu-latest
needs:
- build-repo
strategy:
matrix:
ghc:
- ghc8107
- ghc926

steps:
- name: Install Nix
Expand All @@ -133,22 +128,21 @@ jobs:
name: built-repo
path: _repo

- name: Build a smoke-test package
- name: Build checks
# The > is the "YAML folded string" marker, which replaces
# newlines with spaces, since the usual bash idiom of \
# doesn't work for some reason
#
# See https://github.com/nixbuild/feedback/issues/14 for
# why some of these options are here
run: >
nix build
nix flake check
-L
--override-input CHaP path:_repo
--eval-store auto
--store ssh-ng://eu.nixbuild.net
--max-jobs 2
--builders ""
.#hydraJobs.${{matrix.ghc}}.plutus-core-1-1-1-0.x86_64-linux
deploy-check:
runs-on: ubuntu-latest
Expand Down
38 changes: 21 additions & 17 deletions builder/default.nix
Expand Up @@ -2,15 +2,25 @@
compiler-nix-name:
let
inherit (pkgs) lib;
inherit (pkgs.haskell-nix) haskellLib;

# [ { name = "foo"; version = "X.Y.Z"; }, { name = "foo"; version = "P.Q.R"; } ]
chap-package-list =
builtins.filter (lib.strings.hasPrefix "plutus-core") (
builtins.map (p: "${p.pkg-name}-${p.pkg-version}")
(builtins.fromJSON (builtins.readFile "${CHaP}/foliage/packages.json")));
builtins.map (p: { name = p.pkg-name; version = p.pkg-version; })
(builtins.fromJSON (builtins.readFile "${CHaP}/foliage/packages.json"));

build-chap-package = package-id:
# { "foo" : [ "X.Y.Z" "P.Q.R" ], ... }
chap-package-attrs =
let
# { "foo" = [{ name = "foo"; version = "X.Y.Z"; }, { name = "foo"; version = "P.Q.R"; }]; ... }
grouped = lib.groupBy (m: m.name) chap-package-list;
# { "foo" : [ "X.Y.Z" "P.Q.R" ], ... }
simplified = lib.mapAttrs (name: metas: builtins.map (m: m.version) metas) grouped;
in simplified;

chap-package-components = package-name: package-version:
let
package-name = (builtins.parseDrvName package-id).name;
package-id = "${package-name}-${package-version}";

# No need to set index-state:
# - haskell.nix will automatically use the latest known one for hackage
Expand Down Expand Up @@ -46,16 +56,10 @@ let
}];

};

in
pkgs.releaseTools.aggregate {
name = package-id;
constituents = lib.collect lib.isDerivation {
inherit (project.hsPkgs.${package-name}) components checks;
};
};

pkg = project.hsPkgs.${package-name};
components = haskellLib.getAllComponents pkg;
# Not an ideal name here, would be nice to use something simpler
in lib.recurseIntoAttrs (builtins.listToAttrs (builtins.map (c: lib.nameValuePair c.name c) components));
in
lib.attrsets.mapAttrs' (name: lib.attrsets.nameValuePair (builtins.replaceStrings [ "." ] [ "-" ] name)) (
lib.attrsets.genAttrs chap-package-list build-chap-package
)
# { foo = { X.Y.Z = <components>; P.Q.R = <components>; }; ... }
lib.recurseIntoAttrs (lib.mapAttrs (name: versions: lib.recurseIntoAttrs (lib.genAttrs versions (version: chap-package-components name version))) chap-package-attrs)
54 changes: 40 additions & 14 deletions flake.nix
Expand Up @@ -34,18 +34,29 @@
};

outputs = { self, nixpkgs, flake-utils, foliage, haskell-nix, CHaP, iohk-nix, ... }:
flake-utils.lib.eachDefaultSystem
let
compilers = [ "ghc8107" "ghc926" ];
smokeTestPackages = [
"cardano-node"
"cardano-cli"
"cardano-api"
"plutus-core"
];
# The foliage flake only works on this system, so we are stuck with it too
in flake-utils.lib.eachSystem [ "x86_64-linux" ]
(system:
let pkgs = import nixpkgs {
inherit system;
inherit (haskell-nix) config;
overlays = [
haskell-nix.overlay
iohk-nix.overlays.crypto
];
};
let
pkgs = import nixpkgs {
inherit system;
inherit (haskell-nix) config;
overlays = [
haskell-nix.overlay
iohk-nix.overlays.crypto
];
};
inherit (pkgs) lib;
in
{
rec {
devShells.default = with pkgs; mkShellNoCC {
name = "cardano-haskell-packages";
buildInputs = [
Expand All @@ -58,13 +69,27 @@
];
};

hydraJobs =
# { ghc8107 = { foo = { X.Y.Z = <components>; ... }; ...}; ... }
haskellPackages =
let
inherit (pkgs) lib;
builder = import ./builder { inherit pkgs CHaP; };
compilers = [ "ghc8107" "ghc926" ];
in
lib.attrsets.genAttrs compilers builder;
lib.recurseIntoAttrs (lib.genAttrs compilers builder);

# A nested tree of derivations containing all the smoke test packages for all the compiler versions
smokeTestDerivations = lib.genAttrs compilers (compiler:
let
# The latest version in the set (attrValues sorts by key). Remove the 'recurseForDerivations' here otherwise
# we get that!
latest = versionToValue: lib.last (lib.attrValues (builtins.removeAttrs versionToValue ["recurseForDerivations"]));
compilerPkgs = builtins.getAttr compiler haskellPackages;
smokeTestPkgs = lib.recurseIntoAttrs (lib.genAttrs smokeTestPackages (pkgname: latest (builtins.getAttr pkgname compilerPkgs)));
in smokeTestPkgs);

# The standard checks: build all the smoke test packages
checks = flake-utils.lib.flattenTree smokeTestDerivations;

hydraJobs = checks;
});

nixConfig = {
Expand All @@ -82,5 +107,6 @@
"loony-tools:pr9m4BkM/5/eSTZlkQyRt57Jz7OMBxNSUiMC4FkcNfk="
"nixbuild.net/smart.contracts@iohk.io-1:s2PhQXWwsZo1y5IxFcx2D/i2yfvgtEnRBOZavlA8Bog="
];
allow-import-from-derivation = true;
};
}

0 comments on commit 5a43ce3

Please sign in to comment.