···11{ lib }:
2233-let
44- inherit (lib)
55- all
66- concatStringsSep
77- findFirst
88- flip
99- getAttr
1010- head
1111- isFunction
1212- length
1313- recursiveUpdate
1414- splitVersion
1515- tail
1616- take
1717- versionAtLeast
1818- versionOlder
1919- zipListsWith
2020- ;
2121-in
2222-recursiveUpdate lib (rec {
2323-2424- versions =
2525- let
2626- truncate = n: v: concatStringsSep "." (take n (splitVersion v));
2727- opTruncate =
2828- op: v0: v:
2929- let
3030- n = length (splitVersion v0);
3131- in
3232- op (truncate n v) (truncate n v0);
3333- in
3434- rec {
3535-3636- /*
3737- Get string of the first n parts of a version string.
3838-3939- Example:
4040- - truncate 2 "1.2.3-stuff"
4141- => "1.2"
4242-4343- - truncate 4 "1.2.3-stuff"
4444- => "1.2.3.stuff"
4545- */
4646-4747- inherit truncate;
4848-4949- /*
5050- Get string of the first three parts (major, minor and patch)
5151- of a version string.
5252-5353- Example:
5454- majorMinorPatch "1.2.3-stuff"
5555- => "1.2.3"
5656- */
5757- majorMinorPatch = truncate 3;
5858-5959- /*
6060- Version comparison predicates,
6161- - isGe v0 v <-> v is greater or equal than v0 [*]
6262- - isLe v0 v <-> v is lesser or equal than v0 [*]
6363- - isGt v0 v <-> v is strictly greater than v0 [*]
6464- - isLt v0 v <-> v is strictly lesser than v0 [*]
6565- - isEq v0 v <-> v is equal to v0 [*]
6666- - range low high v <-> v is between low and high [**]
6767-6868- [*] truncating v to the same number of digits as v0
6969- [**] truncating v to low for the lower bound and high for the upper bound
7070-7171- Examples:
7272- - isGe "8.10" "8.10.1"
7373- => true
7474- - isLe "8.10" "8.10.1"
7575- => true
7676- - isGt "8.10" "8.10.1"
7777- => false
7878- - isGt "8.10.0" "8.10.1"
7979- => true
8080- - isEq "8.10" "8.10.1"
8181- => true
8282- - range "8.10" "8.11" "8.11.1"
8383- => true
8484- - range "8.10" "8.11+" "8.11.0"
8585- => false
8686- - range "8.10" "8.11+" "8.11+beta1"
8787- => false
8888- */
8989- isGe = opTruncate versionAtLeast;
9090- isGt = opTruncate (flip versionOlder);
9191- isLe = opTruncate (flip versionAtLeast);
9292- isLt = opTruncate versionOlder;
9393- isEq = opTruncate pred.equal;
9494- range = low: high: pred.inter (versions.isGe low) (versions.isLe high);
9595- };
9696-9797- /*
9898- Returns a list of list, splitting it using a predicate.
9999- This is analogous to builtins.split sep list,
100100- with a predicate as a separator and a list instead of a string.
101101-102102- Type: splitList :: (a -> bool) -> [a] -> [[a]]
103103-104104- Example:
105105- splitList (x: x == "x") [ "y" "x" "z" "t" ]
106106- => [ [ "y" ] "x" [ "z" "t" ] ]
107107- */
108108- splitList =
109109- pred: l: # put in file lists
110110- let
111111- loop = (
112112- vv: v: l:
113113- if l == [ ] then
114114- vv ++ [ v ]
115115- else
116116- let
117117- hd = head l;
118118- tl = tail l;
119119- in
120120- if pred hd then
121121- loop (
122122- vv
123123- ++ [
124124- v
125125- hd
126126- ]
127127- ) [ ] tl
128128- else
129129- loop vv (v ++ [ hd ]) tl
130130- );
131131- in
132132- loop [ ] [ ] l;
133133-134134- pred = {
135135- # Predicate intersection, union, and complement
136136- inter =
137137- p: q: x:
138138- p x && q x;
139139- union =
140140- p: q: x:
141141- p x || q x;
142142- compl = p: x: !p x;
143143- true = p: true;
144144- false = p: false;
145145-146146- # predicate "being equal to y"
147147- equal = y: x: x == y;
148148- };
149149-150150- /*
151151- Emulate a "switch - case" construct,
152152- instead of relying on `if then else if ...`
153153- */
154154- /*
155155- Usage:
156156- ```nix
157157- switch-if [
158158- if-clause-1
159159- ..
160160- if-clause-k
161161- ] default-out
162162- ```
163163- where a if-clause has the form `{ cond = b; out = r; }`
164164- the first branch such as `b` is true
165165- */
166166-167167- switch-if = c: d: (findFirst (getAttr "cond") { } c).out or d;
168168-169169- /*
170170- Usage:
171171- ```nix
172172- switch x [
173173- simple-clause-1
174174- ..
175175- simple-clause-k
176176- ] default-out
177177- ```
178178- where a simple-clause has the form `{ case = p; out = r; }`
179179- the first branch such as `p x` is true
180180- or
181181- ```nix
182182- switch [ x1 .. xn ] [
183183- complex-clause-1
184184- ..
185185- complex-clause-k
186186- ] default-out
187187- ```
188188- where a complex-clause is either a simple-clause
189189- or has the form { cases = [ p1 .. pn ]; out = r; }
190190- in which case the first branch such as all `pi x` are true
191191-192192- if the variables p are not functions,
193193- they are converted to a equal p
194194- if out is missing the default-out is taken
195195- */
196196-197197- switch =
198198- var: clauses: default:
199199- with pred;
200200- let
201201- compare = f: if isFunction f then f else equal f;
202202- combine =
203203- cl: var:
204204- if cl ? case then compare cl.case var else all (equal true) (zipListsWith compare cl.cases var);
205205- in
206206- switch-if (map (cl: {
207207- cond = combine cl var;
208208- inherit (cl) out;
209209- }) clauses) default;
33+lib.recursiveUpdate lib (
44+ import ../rocq/extra-lib-common.nix { inherit lib; } // {
21052116 /*
2127 Override arguments to mkCoqDerivation for a Coq library.
···11+{ lib }:
22+33+let
44+ inherit (lib)
55+ all
66+ concatStringsSep
77+ findFirst
88+ flip
99+ getAttr
1010+ head
1111+ isFunction
1212+ length
1313+ recursiveUpdate
1414+ splitVersion
1515+ tail
1616+ take
1717+ versionAtLeast
1818+ versionOlder
1919+ zipListsWith
2020+ ;
2121+in
2222+rec {
2323+2424+ versions =
2525+ let
2626+ truncate = n: v: concatStringsSep "." (take n (splitVersion v));
2727+ opTruncate =
2828+ op: v0: v:
2929+ let
3030+ n = length (splitVersion v0);
3131+ in
3232+ op (truncate n v) (truncate n v0);
3333+ in
3434+ rec {
3535+3636+ /*
3737+ Get string of the first n parts of a version string.
3838+3939+ Example:
4040+ - truncate 2 "1.2.3-stuff"
4141+ => "1.2"
4242+4343+ - truncate 4 "1.2.3-stuff"
4444+ => "1.2.3.stuff"
4545+ */
4646+4747+ inherit truncate;
4848+4949+ /*
5050+ Get string of the first three parts (major, minor and patch)
5151+ of a version string.
5252+5353+ Example:
5454+ majorMinorPatch "1.2.3-stuff"
5555+ => "1.2.3"
5656+ */
5757+ majorMinorPatch = truncate 3;
5858+5959+ /*
6060+ Version comparison predicates,
6161+ - isGe v0 v <-> v is greater or equal than v0 [*]
6262+ - isLe v0 v <-> v is lesser or equal than v0 [*]
6363+ - isGt v0 v <-> v is strictly greater than v0 [*]
6464+ - isLt v0 v <-> v is strictly lesser than v0 [*]
6565+ - isEq v0 v <-> v is equal to v0 [*]
6666+ - range low high v <-> v is between low and high [**]
6767+6868+ [*] truncating v to the same number of digits as v0
6969+ [**] truncating v to low for the lower bound and high for the upper bound
7070+7171+ Examples:
7272+ - isGe "8.10" "8.10.1"
7373+ => true
7474+ - isLe "8.10" "8.10.1"
7575+ => true
7676+ - isGt "8.10" "8.10.1"
7777+ => false
7878+ - isGt "8.10.0" "8.10.1"
7979+ => true
8080+ - isEq "8.10" "8.10.1"
8181+ => true
8282+ - range "8.10" "8.11" "8.11.1"
8383+ => true
8484+ - range "8.10" "8.11+" "8.11.0"
8585+ => false
8686+ - range "8.10" "8.11+" "8.11+beta1"
8787+ => false
8888+ */
8989+ isGe = opTruncate versionAtLeast;
9090+ isGt = opTruncate (flip versionOlder);
9191+ isLe = opTruncate (flip versionAtLeast);
9292+ isLt = opTruncate versionOlder;
9393+ isEq = opTruncate pred.equal;
9494+ range = low: high: pred.inter (versions.isGe low) (versions.isLe high);
9595+ };
9696+9797+ /*
9898+ Returns a list of list, splitting it using a predicate.
9999+ This is analogous to builtins.split sep list,
100100+ with a predicate as a separator and a list instead of a string.
101101+102102+ Type: splitList :: (a -> bool) -> [a] -> [[a]]
103103+104104+ Example:
105105+ splitList (x: x == "x") [ "y" "x" "z" "t" ]
106106+ => [ [ "y" ] "x" [ "z" "t" ] ]
107107+ */
108108+ splitList =
109109+ pred: l: # put in file lists
110110+ let
111111+ loop = (
112112+ vv: v: l:
113113+ if l == [ ] then
114114+ vv ++ [ v ]
115115+ else
116116+ let
117117+ hd = head l;
118118+ tl = tail l;
119119+ in
120120+ if pred hd then
121121+ loop (
122122+ vv
123123+ ++ [
124124+ v
125125+ hd
126126+ ]
127127+ ) [ ] tl
128128+ else
129129+ loop vv (v ++ [ hd ]) tl
130130+ );
131131+ in
132132+ loop [ ] [ ] l;
133133+134134+ pred = {
135135+ # Predicate intersection, union, and complement
136136+ inter =
137137+ p: q: x:
138138+ p x && q x;
139139+ union =
140140+ p: q: x:
141141+ p x || q x;
142142+ compl = p: x: !p x;
143143+ true = p: true;
144144+ false = p: false;
145145+146146+ # predicate "being equal to y"
147147+ equal = y: x: x == y;
148148+ };
149149+150150+ /*
151151+ Emulate a "switch - case" construct,
152152+ instead of relying on `if then else if ...`
153153+ */
154154+ /*
155155+ Usage:
156156+ ```nix
157157+ switch-if [
158158+ if-clause-1
159159+ ..
160160+ if-clause-k
161161+ ] default-out
162162+ ```
163163+ where a if-clause has the form `{ cond = b; out = r; }`
164164+ the first branch such as `b` is true
165165+ */
166166+167167+ switch-if = c: d: (findFirst (getAttr "cond") { } c).out or d;
168168+169169+ /*
170170+ Usage:
171171+ ```nix
172172+ switch x [
173173+ simple-clause-1
174174+ ..
175175+ simple-clause-k
176176+ ] default-out
177177+ ```
178178+ where a simple-clause has the form `{ case = p; out = r; }`
179179+ the first branch such as `p x` is true
180180+ or
181181+ ```nix
182182+ switch [ x1 .. xn ] [
183183+ complex-clause-1
184184+ ..
185185+ complex-clause-k
186186+ ] default-out
187187+ ```
188188+ where a complex-clause is either a simple-clause
189189+ or has the form { cases = [ p1 .. pn ]; out = r; }
190190+ in which case the first branch such as all `pi x` are true
191191+192192+ if the variables p are not functions,
193193+ they are converted to a equal p
194194+ if out is missing the default-out is taken
195195+ */
196196+197197+ switch =
198198+ var: clauses: default:
199199+ with pred;
200200+ let
201201+ compare = f: if isFunction f then f else equal f;
202202+ combine =
203203+ cl: var:
204204+ if cl ? case then compare cl.case var else all (equal true) (zipListsWith compare cl.cases var);
205205+ in
206206+ switch-if (map (cl: {
207207+ cond = combine cl var;
208208+ inherit (cl) out;
209209+ }) clauses) default;
210210+}
+56
pkgs/build-support/rocq/extra-lib.nix
···11+{ lib }:
22+33+lib.recursiveUpdate lib (
44+ import ./extra-lib-common.nix { inherit lib; } // {
55+66+ /*
77+ Override arguments to mkRocqDerivation for a Rocq library.
88+99+ This function allows you to easily override arguments to mkRocqDerivation,
1010+ even when they are not exposed by the Rocq library directly.
1111+1212+ Type: overrideRocqDerivation :: AttrSet -> RocqLibraryDerivation -> RocqLibraryDerivation
1313+1414+ Example:
1515+1616+ ```nix
1717+ rocqPackages.lib.overrideRocqDerivation
1818+ {
1919+ defaultVersion = "9999";
2020+ release."9999".hash = "sha256-fDoP11rtrIM7+OLdMisv2EF7n/IbGuwFxHiPtg3qCNM=";
2121+ }
2222+ rocqPackages.QuickChick;
2323+ ```
2424+2525+ This example overrides the `defaultVersion` and `release` arguments that
2626+ are passed to `mkRocqDerivation` in the QuickChick derivation.
2727+2828+ Note that there is a difference between using `.override` on a Rocq
2929+ library vs this `overrideRocqDerivation` function. `.override` allows you
3030+ to modify arguments to the derivation itself, for instance by passing
3131+ different versions of dependencies:
3232+3333+ ```nix
3434+ rocqPackages.QuickChick.override { ssreflect = my-cool-ssreflect; }
3535+ ```
3636+3737+ whereas `overrideRocqDerivation` allows you to override arguments to the
3838+ call to `mkRocqDerivation` in the Rocq library.
3939+4040+ Note that all Rocq libraries in Nixpkgs have a `version` argument for
4141+ easily using a different version. So if all you want to do is use a
4242+ different version, and the derivation for the Rocq library already has
4343+ support for the version you want, you likely only need to update the
4444+ `version` argument on the library derivation. This is done with
4545+ `.override`:
4646+4747+ ```nix
4848+ rocqPackages.QuickChick.override { version = "1.4.0"; }
4949+ ```
5050+ */
5151+ overrideRocqDerivation =
5252+ f: drv:
5353+ (drv.override (args: {
5454+ mkRocqDerivation = drv_: (args.mkRocqDerivation drv_).override f;
5555+ }));
5656+})
+1-1
pkgs/top-level/rocq-packages.nix
···22, callPackage, newScope, recurseIntoAttrs, ocamlPackages_4_14
33, fetchpatch, makeWrapper,
44}@args:
55-let lib = import ../build-support/coq/extra-lib.nix {inherit (args) lib;}; in
55+let lib = import ../build-support/rocq/extra-lib.nix {inherit (args) lib;}; in
66let
77 mkRocqPackages' = self: rocq-core:
88 let callPackage = self.callPackage; in {