|
| 1 | +{ |
| 2 | + inputs, |
| 3 | + cell, |
| 4 | +}: let |
| 5 | + inherit (inputs) nixpkgs; |
| 6 | + l = nixpkgs.lib // builtins; |
| 7 | +in |
| 8 | + /* |
| 9 | + Utility function to allow for building containers in a mono-repo style environment where |
| 10 | + the source code is contained in the same repository as the std code, specifically so that |
| 11 | + one may detect meaningful changes to the image via its tag in the special case where the |
| 12 | + package's output includes the revision of the source code (e.g. for displaying the version |
| 13 | + to the user). |
| 14 | +
|
| 15 | + Without special processing, this kind of package would cause the OCI image tag to change |
| 16 | + on each new revision whether the actual contents of the image changed or not. Combined |
| 17 | + with `std.incl`, one may have a very strong indicator for when the contents of the image |
| 18 | + actually includes meaningful changes which avoids flooding the remote registry with superflous |
| 19 | + copies. |
| 20 | +
|
| 21 | + This function can also be called where the package does not need the revsion at build time |
| 22 | + but you simply want to tag the image by its hash for later processing by the proviso, and |
| 23 | + you also want to include additional tags on the image, such as the revision. |
| 24 | +
|
| 25 | + Args: |
| 26 | + args: arguments to the mkOCI function to be called. |
| 27 | + mkOCI: defaults to `mkStandardOCI` |
| 28 | + operable: The operable to include in the container |
| 29 | + ...: The same arguments expected by the given standard OCI builder |
| 30 | +
|
| 31 | + Returns: |
| 32 | + An image tagged with the output hash of an identical image, except where the target package |
| 33 | + and operable are both built with the revision input set to "not-a-commit" instead of the true |
| 34 | + revision, so that the hash does not change unless something inside the image does. |
| 35 | + */ |
| 36 | + args @ { |
| 37 | + operable, |
| 38 | + mkOCI ? cell.ops.mkStandardOCI, |
| 39 | + ... |
| 40 | + }: let |
| 41 | + revision = cell.ops.revise mkOCI args.operable (operable: builtins.removeAttrs (args // {inherit operable;}) ["mkOCI"]); |
| 42 | + in |
| 43 | + if args.operable ? sansrev |
| 44 | + then |
| 45 | + mkOCI (args |
| 46 | + // { |
| 47 | + meta = |
| 48 | + args.meta |
| 49 | + or {} |
| 50 | + // { |
| 51 | + tags = [revision.sansrev.outHash] ++ (args.meta.tags or []); |
| 52 | + }; |
| 53 | + }) |
| 54 | + else |
| 55 | + mkOCI (args |
| 56 | + // { |
| 57 | + meta = |
| 58 | + args.meta |
| 59 | + or {} |
| 60 | + // { |
| 61 | + tags = [(cell.ops.hashOfPath revision.outPath)] ++ (args.meta.tags or []); |
| 62 | + }; |
| 63 | + }) |
0 commit comments