From 4cf656b8a799842508a3713de139145e51c1ce51 Mon Sep 17 00:00:00 2001 From: Michael Peyton Jones Date: Fri, 17 Mar 2023 10:38:20 +0000 Subject: [PATCH] Refactor --- README.md | 6 +-- flake.nix | 54 ++++++++++++++------------ builder/default.nix => nix/builder.nix | 20 +--------- nix/chap-meta.nix | 29 ++++++++++++++ {builder => nix}/empty/almost/.gitkeep | 0 5 files changed, 63 insertions(+), 46 deletions(-) rename builder/default.nix => nix/builder.nix (69%) create mode 100644 nix/chap-meta.nix rename {builder => nix}/empty/almost/.gitkeep (100%) diff --git a/README.md b/README.md index ba645d66..7e4364cd 100644 --- a/README.md +++ b/README.md @@ -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 `--`. +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. @@ -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 diff --git a/flake.nix b/flake.nix index ea04c419..f84e19e1 100644 --- a/flake.nix +++ b/flake.nix @@ -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 { @@ -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 { @@ -69,25 +76,23 @@ ]; }; - # { ghc8107 = { foo = { X.Y.Z = ; ... }; ...}; ... } + # { ghc8107 = { foo = { X.Y.Z = ; ... }; ...}; ... } 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; }); @@ -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 = [ diff --git a/builder/default.nix b/nix/builder.nix similarity index 69% rename from builder/default.nix rename to nix/builder.nix index 917aeeba..b9cfcc60 100644 --- a/builder/default.nix +++ b/nix/builder.nix @@ -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}"; @@ -69,8 +55,4 @@ let # does Hackage). constituents = components; }; -in -# { foo = { X.Y.Z = ; P.Q.R = ; }; ... } -lib.recurseIntoAttrs (lib.mapAttrs - (name: versions: lib.recurseIntoAttrs (lib.genAttrs versions (build-chap-package name))) - chap-package-attrs) +in build-chap-package diff --git a/nix/chap-meta.nix b/nix/chap-meta.nix new file mode 100644 index 00000000..42f8040b --- /dev/null +++ b/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; +} diff --git a/builder/empty/almost/.gitkeep b/nix/empty/almost/.gitkeep similarity index 100% rename from builder/empty/almost/.gitkeep rename to nix/empty/almost/.gitkeep