Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelpj committed Mar 17, 2023
1 parent 8cd90b3 commit 4cf656b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 46 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -268,10 +268,10 @@ You can build packages from CHaP using Nix like this:
```
nix build
--override-input CHaP /home/user/cardano-haskell-packages/_repo
.#haskellPackages.x86_64-linux.ghc8107.plutus-core."1.1.0.0".plutus-core-exe-plc
.#haskellPackages.x86_64-linux.ghc8107.plutus-core."1.1.0.0"
```

The final attribute name is `<package-name>-<component-type>-<component-name>`.
This will build all the components of that package version that CHaP cares about, namely libraries and executables (test suites and benchmarks are not built).

We need to use `--override-input` because the CHaP flake relies on a built repository.
By default it points to a built repository on the main CHaP `repo` branch.
Expand Down Expand Up @@ -329,7 +329,7 @@ Along with requiring linear history, this ensures that package repository that w
- Deploys the package repository to the `repo` branch, along with some static web content.
- Builds a small set of packages using the newly built repository, to flush out any build issues.
- We build with all the major GHC versions we expect to be in use.
- At the moment we don't build all the packages in the repository, only a fixed set.
- At the moment we don't build all the packages in the repository, only the latest versions of a fixed set.

## Creating a repository like CHaP

Expand Down
54 changes: 30 additions & 24 deletions flake.nix
Expand Up @@ -34,16 +34,8 @@
};

outputs = { self, nixpkgs, flake-utils, foliage, haskell-nix, CHaP, iohk-nix, ... }:
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" ]
flake-utils.lib.eachSystem [ "x86_64-linux" ]
(system:
let
pkgs = import nixpkgs {
Expand All @@ -55,6 +47,21 @@
];
};
inherit (pkgs) lib;

compilers = [ "ghc8107" "ghc926" ];

builder = import ./nix/builder.nix { inherit pkgs CHaP; };
chap-meta = import ./nix/chap-meta.nix { inherit pkgs CHaP; };

smokeTestPackages = [
#"cardano-node"
#"cardano-cli"
#"cardano-api"
"plutus-core"
];
# using intersectAttrs like this is a cheap way to throw away everything with keys not in
# smokeTestPackages
smokeTestPackageVersions = builtins.intersectAttrs (lib.genAttrs smokeTestPackages (pkg: {})) chap-meta.chap-package-latest-versions;
in
rec {
devShells.default = with pkgs; mkShellNoCC {
Expand All @@ -69,25 +76,23 @@
];
};

# { ghc8107 = { foo = { X.Y.Z = <components>; ... }; ...}; ... }
# { ghc8107 = { foo = { X.Y.Z = <derivation>; ... }; ...}; ... }
haskellPackages =
let
builder = import ./builder { inherit pkgs CHaP; };
derivations = compiler: (lib.mapAttrs
(name: versions: (lib.genAttrs versions (version: builder compiler name version)))
chap-meta.chap-package-versions);
in
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);
lib.genAttrs compilers derivations;

# The standard checks: build all the smoke test packages
checks = flake-utils.lib.flattenTree smokeTestDerivations;
checks =
# We use recurseIntoAttrs so flattenTree will flatten it back out again.
let
derivations = compiler: lib.recurseIntoAttrs (lib.mapAttrs (name: version: builder compiler name version) smokeTestPackageVersions);
# A nested tree of derivations containing all the smoke test packages for all the compiler versions
perCompilerDerivations = lib.recurseIntoAttrs (lib.genAttrs compilers derivations);
in builtins.trace (builtins.toJSON smokeTestPackageVersions) (flake-utils.lib.flattenTree perCompilerDerivations);

hydraJobs = checks;
});
Expand All @@ -100,7 +105,8 @@
];
extra-trusted-substituters = [
# If you have a nixbuild.net SSH key set up, you can pull builds from there
# by using '--extra-substituters ssh://eu.nixbuild.net' manually
# by using '--extra-substituters ssh://eu.nixbuild.net' manually, otherwise this
# does nothing
"ssh://eu.nixbuild.net"
];
extra-trusted-public-keys = [
Expand Down
20 changes: 1 addition & 19 deletions builder/default.nix → nix/builder.nix
Expand Up @@ -4,20 +4,6 @@ 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.map (p: { name = p.pkg-name; version = p.pkg-version; })
(builtins.fromJSON (builtins.readFile "${CHaP}/foliage/packages.json"));

# { "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;

build-chap-package = package-name: package-version:
let
package-id = "${package-name}-${package-version}";
Expand Down Expand Up @@ -69,8 +55,4 @@ let
# does Hackage).
constituents = components;
};
in
# { foo = { X.Y.Z = <derivation>; P.Q.R = <derivation>; }; ... }
lib.recurseIntoAttrs (lib.mapAttrs
(name: versions: lib.recurseIntoAttrs (lib.genAttrs versions (build-chap-package name)))
chap-package-attrs)
in build-chap-package
29 changes: 29 additions & 0 deletions nix/chap-meta.nix
@@ -0,0 +1,29 @@
{ pkgs, CHaP }:
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.map (p: { name = p.pkg-name; version = p.pkg-version; })
(builtins.fromJSON (builtins.readFile "${CHaP}/foliage/packages.json"));

# { "foo" : [ "X.Y.Z" "P.Q.R" ], ... }
chap-package-versions =
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;

# { "foo" : "X.Y.Z", ... }
chap-package-latest-versions =
let latest = versions: lib.last (lib.naturalSort versions);
in lib.mapAttrs (name: versions: latest versions) chap-package-versions;

in
{
inherit chap-package-versions chap-package-latest-versions;
}
File renamed without changes.

0 comments on commit 4cf656b

Please sign in to comment.