From ae422c13534d62aae68f06e5e02028dbe6884e33 Mon Sep 17 00:00:00 2001 From: sterni Date: Thu, 26 May 2022 18:47:56 +0200 Subject: feat(sterni/nix/misc): predicate to check if isRestrictedEval This is merely a little demonstration of nix#6579: `users.sterni.nix.misc.isRestrictEval` returns whether the restrict-eval setting is true or false by exploiting the aforementioned Nix bug. Change-Id: Icca354d1cd6571cdf0804abae27aac91a18cda1e Reviewed-on: https://cl.tvl.fyi/c/depot/+/5692 Autosubmit: sterni Reviewed-by: sterni Reviewed-by: tazjin Tested-by: BuildkiteCI --- users/sterni/nix/misc/default.nix | 18 ++++++++++++++++++ users/sterni/nix/misc/guinea-pig | 1 + 2 files changed, 19 insertions(+) create mode 100644 users/sterni/nix/misc/default.nix create mode 120000 users/sterni/nix/misc/guinea-pig diff --git a/users/sterni/nix/misc/default.nix b/users/sterni/nix/misc/default.nix new file mode 100644 index 0000000000..1de9c973ec --- /dev/null +++ b/users/sterni/nix/misc/default.nix @@ -0,0 +1,18 @@ +{ ... }: + +let + /* Returns true if it is being evaluated using restrict-eval, false if not. + It's more robust than using `builtins.getEnv` since it isn't fooled by + `env -i`. + + See https://github.com/NixOS/nix/issues/6579 for a description of the + behavior. Precise cause in the evaluator / store implementation is unclear. + + Type: bool + */ + inRestrictedEval = builtins.pathExists (toString ./guinea-pig + "/."); +in + +{ + inherit inRestrictedEval; +} diff --git a/users/sterni/nix/misc/guinea-pig b/users/sterni/nix/misc/guinea-pig new file mode 120000 index 0000000000..73537e478e --- /dev/null +++ b/users/sterni/nix/misc/guinea-pig @@ -0,0 +1 @@ +default.nix \ No newline at end of file -- cgit 1.4.1