mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 00:08:07 +02:00
765436e300
End goal: make `(mkDerivation x).drvPath` behave like a non-DrvDeep context. Problem: users won't be able to recover the DrvDeep behavior when nixpkgs makes this change. Solution: add this primop. The new primop is fairly simple, and is supposed to complement other existing ones (`builtins.storePath`, `builtins.outputOf`) so there are simple ways to construct strings with every type of string context element. (It allows nothing we couldn't already do with `builtins.getContext` and `builtins.appendContext`, which is also true of those other two primops.) This was originally in #8595, but then it was proposed to land some doc changes separately. So now the code changes proper is just moved to this, and the doc will be done in that. Co-authored-by: Robert Hensing <roberth@users.noreply.github.com> Co-authored-by: Théophane Hufschmitt <7226587+thufschmitt@users.nore github.com> Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io
59 lines
1.6 KiB
Nix
59 lines
1.6 KiB
Nix
let
|
|
drv = derivation {
|
|
name = "fail";
|
|
builder = "/bin/false";
|
|
system = "x86_64-linux";
|
|
outputs = [ "out" "foo" ];
|
|
};
|
|
|
|
path = "${./eval-okay-context-introspection.nix}";
|
|
|
|
desired-context = {
|
|
"${builtins.unsafeDiscardStringContext path}" = {
|
|
path = true;
|
|
};
|
|
"${builtins.unsafeDiscardStringContext drv.drvPath}" = {
|
|
outputs = [ "foo" "out" ];
|
|
allOutputs = true;
|
|
};
|
|
};
|
|
|
|
combo-path = "${path}${drv.outPath}${drv.foo.outPath}${drv.drvPath}";
|
|
legit-context = builtins.getContext combo-path;
|
|
|
|
reconstructed-path = builtins.appendContext
|
|
(builtins.unsafeDiscardStringContext combo-path)
|
|
desired-context;
|
|
|
|
# Eta rule for strings with context.
|
|
etaRule = str:
|
|
str == builtins.appendContext
|
|
(builtins.unsafeDiscardStringContext str)
|
|
(builtins.getContext str);
|
|
|
|
# Only holds true if string context contains both a `DrvDeep` and
|
|
# `Opaque` element.
|
|
almostEtaRule = str:
|
|
str == builtins.addDrvOutputDependencies
|
|
(builtins.unsafeDiscardOutputDependency str);
|
|
|
|
addDrvOutputDependencies_idempotent = str:
|
|
builtins.addDrvOutputDependencies str ==
|
|
builtins.addDrvOutputDependencies (builtins.addDrvOutputDependencies str);
|
|
|
|
rules = str: [
|
|
(etaRule str)
|
|
(almostEtaRule str)
|
|
(addDrvOutputDependencies_idempotent str)
|
|
];
|
|
|
|
in [
|
|
(legit-context == desired-context)
|
|
(reconstructed-path == combo-path)
|
|
(etaRule "foo")
|
|
(etaRule drv.foo.outPath)
|
|
] ++ builtins.concatMap rules [
|
|
drv.drvPath
|
|
(builtins.addDrvOutputDependencies drv.drvPath)
|
|
(builtins.unsafeDiscardOutputDependency drv.drvPath)
|
|
]
|