From 06ece659f09716f744ee5e6fcf5565d7dcbab30b Mon Sep 17 00:00:00 2001 From: Dennis Gosnell Date: Mon, 29 Aug 2022 14:41:03 +0900 Subject: [PATCH 1/4] coqPackages.mkCoqDerivation: add a coqPackages.lib.overrideCoqDerivation function `overrideCoqDerivation` allows end-users the ability to easily override arguments to the underlying call to `mkCoqDerivation` for a given Coq library. This is similar to `haskell.lib.overrideCabal` for Haskell packages and `.overridePythonAttrs` for Python packges. --- pkgs/build-support/coq/extra-lib.nix | 37 ++++++++++++++++++++++++++++ pkgs/top-level/coq-packages.nix | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/coq/extra-lib.nix b/pkgs/build-support/coq/extra-lib.nix index 65b48f511267..90600271d42b 100644 --- a/pkgs/build-support/coq/extra-lib.nix +++ b/pkgs/build-support/coq/extra-lib.nix @@ -142,4 +142,41 @@ with builtins; with lib; recursiveUpdate lib (rec { if cl?case then compare cl.case var else all (equal true) (zipListsWith compare cl.cases var); in switch-if (map (cl: { cond = combine cl var; inherit (cl) out; }) clauses) default; + + /* Override arguments to mkCoqDerivation for a Coq library. + + This function allows you to easily override arguments to mkCoqDerivation, + even when they are not exposed by the Coq library directly. + + Type: overrideCoqDerivation :: AttrSet -> CoqLibraryDerivation -> CoqLibraryDerivation + + Example: + + ```nix + coqPackages.lib.overrideCoqDerivation + { + defaultVersion = "9999"; + release."9999".sha256 = "1lq8x86vd3vqqh2yq6hvyagpnhfq5wmk5pg2z0xq7b7dbbbhyfkw"; + } + coqPackages.QuickChick; + ``` + + This example overrides the `defaultVersion` and `release` arguments that + are passed to `mkCoqDerivation` in the QuickChick derivation. + + Note that there is a difference between using `.override` on a Coq + library vs this `overrideCoqDerivation` function. `.override` allows you + to modify arguments to the derivation itself, for instance by passing + different versions of dependencies: + + ```nix + coqPackages.QuickCick.override { ssreflect = my-cool-ssreflect; } + ``` + + whereas `overrideCoqDerivation` allows you to override arguments to the + call to `mkCoqDerivation` in the Coq library. + */ + overrideCoqDerivation = f: drv: (drv.override (args: { + mkCoqDerivation = drv_: (args.mkCoqDerivation drv_).override f; + })); }) diff --git a/pkgs/top-level/coq-packages.nix b/pkgs/top-level/coq-packages.nix index e013bf7cd1bc..0cf24f1d8b9f 100644 --- a/pkgs/top-level/coq-packages.nix +++ b/pkgs/top-level/coq-packages.nix @@ -11,7 +11,7 @@ let metaFetch = import ../build-support/coq/meta-fetch/default.nix {inherit lib stdenv fetchzip; }; - mkCoqDerivation = callPackage ../build-support/coq {}; + mkCoqDerivation = lib.makeOverridable (callPackage ../build-support/coq {}); contribs = recurseIntoAttrs (callPackage ../development/coq-modules/contribs {}); From 7efd4aa67c44be8fa854daf81243b300cf94259f Mon Sep 17 00:00:00 2001 From: Dennis Gosnell Date: Mon, 29 Aug 2022 14:46:20 +0900 Subject: [PATCH 2/4] tests.coq.overrideCoqDerivation: add test --- pkgs/test/coq/default.nix | 6 +++ .../coq/overrideCoqDerivation/default.nix | 40 +++++++++++++++++++ pkgs/test/default.nix | 2 + 3 files changed, 48 insertions(+) create mode 100644 pkgs/test/coq/default.nix create mode 100644 pkgs/test/coq/overrideCoqDerivation/default.nix diff --git a/pkgs/test/coq/default.nix b/pkgs/test/coq/default.nix new file mode 100644 index 000000000000..cf59dd473b4c --- /dev/null +++ b/pkgs/test/coq/default.nix @@ -0,0 +1,6 @@ +{ lib, callPackage }: + +lib.recurseIntoAttrs { + overrideCoqDerivation = callPackage ./overrideCoqDerivation { }; +} + diff --git a/pkgs/test/coq/overrideCoqDerivation/default.nix b/pkgs/test/coq/overrideCoqDerivation/default.nix new file mode 100644 index 000000000000..9fef57765400 --- /dev/null +++ b/pkgs/test/coq/overrideCoqDerivation/default.nix @@ -0,0 +1,40 @@ +{ lib, coq, mkCoqPackages, runCommandNoCC }: + +let + + # This is just coq, but with dontFilter set to true. We need to set + # dontFilter to true here so that _all_ packages are visibile in coqPackages. + # There may be some versions of the top-level coq and coqPackages that don't + # build QuickChick, which is what we are using for this test below. + coqWithAllPackages = coq // { dontFilter = true; }; + + coqPackages = mkCoqPackages coqWithAllPackages; + + # This is the main test. This uses overrideCoqDerivation to + # override arguments to mkCoqDerivation. + # + # Here, we override the defaultVersion and release arguments to + # mkCoqDerivation. + overriddenQuickChick = + coqPackages.lib.overrideCoqDerivation + { + defaultVersion = "9999"; + release."9999".sha256 = lib.fakeSha256; + } + coqPackages.QuickChick; +in + +runCommandNoCC + "coq-overrideCoqDerivation-test-0.1" + { meta.maintainers = with lib.maintainers; [cdepillabout]; } + '' + # Confirm that the computed version number for the overridden QuickChick does + # actually become 9999, as set above. + if [ "${overriddenQuickChick.version}" -eq "9999" ]; then + echo "overriddenQuickChick version was successfully set to 9999" + touch $out + else + echo "ERROR: overriddenQuickChick version was supposed to be 9999, but was actually: ${overriddenQuickChick.version}" + exit 1 + fi + '' diff --git a/pkgs/test/default.nix b/pkgs/test/default.nix index 82975efb5917..2638bbc37e6b 100644 --- a/pkgs/test/default.nix +++ b/pkgs/test/default.nix @@ -75,6 +75,8 @@ with pkgs; dhall = callPackage ./dhall { }; + coq = callPackage ./coq {}; + makeWrapper = callPackage ./make-wrapper { }; makeBinaryWrapper = callPackage ./make-binary-wrapper { makeBinaryWrapper = pkgs.makeBinaryWrapper.override { From 49e6d1b81329a7847114dfa377f17d144a416acc Mon Sep 17 00:00:00 2001 From: Dennis Gosnell Date: Sat, 3 Sep 2022 21:02:17 +0900 Subject: [PATCH 3/4] tests.coq.overrideCoqDerivation: use runCommand instead of runCommandNoCC --- pkgs/test/coq/overrideCoqDerivation/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/test/coq/overrideCoqDerivation/default.nix b/pkgs/test/coq/overrideCoqDerivation/default.nix index 9fef57765400..c251c498e609 100644 --- a/pkgs/test/coq/overrideCoqDerivation/default.nix +++ b/pkgs/test/coq/overrideCoqDerivation/default.nix @@ -1,4 +1,4 @@ -{ lib, coq, mkCoqPackages, runCommandNoCC }: +{ lib, coq, mkCoqPackages, runCommand }: let @@ -24,7 +24,7 @@ let coqPackages.QuickChick; in -runCommandNoCC +runCommand "coq-overrideCoqDerivation-test-0.1" { meta.maintainers = with lib.maintainers; [cdepillabout]; } '' From 346454873ef27dc476fcbdab9a6b9188ab1d0fcb Mon Sep 17 00:00:00 2001 From: Dennis Gosnell Date: Sun, 11 Sep 2022 07:41:17 +0900 Subject: [PATCH 4/4] coqPackages.lib.overrideCoqDerivation: update documentation for overriding version --- pkgs/build-support/coq/extra-lib.nix | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/coq/extra-lib.nix b/pkgs/build-support/coq/extra-lib.nix index 90600271d42b..3c226b4920b6 100644 --- a/pkgs/build-support/coq/extra-lib.nix +++ b/pkgs/build-support/coq/extra-lib.nix @@ -170,11 +170,22 @@ with builtins; with lib; recursiveUpdate lib (rec { different versions of dependencies: ```nix - coqPackages.QuickCick.override { ssreflect = my-cool-ssreflect; } + coqPackages.QuickChick.override { ssreflect = my-cool-ssreflect; } ``` whereas `overrideCoqDerivation` allows you to override arguments to the call to `mkCoqDerivation` in the Coq library. + + Note that all Coq libraries in Nixpkgs have a `version` argument for + easily using a different version. So if all you want to do is use a + different version, and the derivation for the Coq library already has + support for the version you want, you likely only need to update the + `version` argument on the library derivation. This is done with + `.override`: + + ```nix + coqPackages.QuickChick.override { version = "1.4.0"; } + ``` */ overrideCoqDerivation = f: drv: (drv.override (args: { mkCoqDerivation = drv_: (args.mkCoqDerivation drv_).override f;