Skip to content

Instantly share code, notes, and snippets.

@shlevy
Created November 2, 2018 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shlevy/c50f848bda51f57f285faaa6f45c6a3f to your computer and use it in GitHub Desktop.
Save shlevy/c50f848bda51f57f285faaa6f45c6a3f to your computer and use it in GitHub Desktop.
/* Primitives for unforgeable values in Nix. As long as the make-unforgeable primitive isn't
* available to arbitrary expressions (e.g. it's defined in a let within your entry point
* and only made available through a more constrained interface), you can use this to build
* general functionality to enforcethat some value must have been created by some trusted
* component.
*
* This is stupidly hacky and relies on a number of questionable assumptions.
*/
rec {
make-unforgeable = x: { value = x; };
read-unforgeable = let
reference = builtins.unsafeGetAttrPos "value" (make-unforgeable null);
in x: if reference == builtins.unsafeGetAttrPos "value" x
then x.value
else throw "Forgery!";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment