about summary refs log tree commit diff
path: root/users/Profpatsch/nixpkgs-rewriter
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2021-01-10T20·41+0100
committerProfpatsch <mail@profpatsch.de>2021-01-11T08·58+0000
commit04f91b59575ede2b230c3f563cc163c6014275e0 (patch)
tree61cbf735953a1db47f274bea656e0d46d563d315 /users/Profpatsch/nixpkgs-rewriter
parent2f807d7f141068d2d60676a89213eaa5353ca6e0 (diff)
feat(users/Profpatsch): add script for randomly evaling nixpkgs r/2071
Running this after a codified refactor acts as a good smoke test,
if a big subset of packages is broken or any central packages are
broken, this should find them quite quickly, thanks to randomness™.

Just let it run for a few minutes and check the errors that pop up.

Change-Id: I1505dd31ca25b29254474a15cd6cb71d9743038a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2346
Tested-by: BuildkiteCI
Reviewed-by: Profpatsch <mail@profpatsch.de>
Reviewed-by: lukegb <lukegb@tvl.fyi>
Diffstat (limited to 'users/Profpatsch/nixpkgs-rewriter')
-rw-r--r--users/Profpatsch/nixpkgs-rewriter/default.nix39
1 files changed, 34 insertions, 5 deletions
diff --git a/users/Profpatsch/nixpkgs-rewriter/default.nix b/users/Profpatsch/nixpkgs-rewriter/default.nix
index ab86ff32090c..286530b03f94 100644
--- a/users/Profpatsch/nixpkgs-rewriter/default.nix
+++ b/users/Profpatsch/nixpkgs-rewriter/default.nix
@@ -8,6 +8,12 @@ let
     eprintf
     ;
 
+  bins = depot.nix.getBins pkgs.coreutils [ "head" "shuf" ]
+      // depot.nix.getBins pkgs.jq [ "jq" ]
+      // depot.nix.getBins pkgs.findutils [ "xargs" ]
+      // depot.nix.getBins pkgs.gnused [ "sed" ]
+      ;
+
   export-json-object = pkgs.writers.writePython3 "export-json-object" {} ''
     import json
     import sys
@@ -35,9 +41,9 @@ let
     "importas" "-ui" "file" "fileName"
     "importas" "-ui" "from" "fromLine"
     "importas" "-ui" "to" "toLine"
-    "if" [ eprintf "\${from}-\${to}" ]
+    "if" [ eprintf "%s-%s\n" "$from" "$to" ]
     (debugExec "adding lib")
-    "sed"
+    bins.sed
       "-e" "\${from},\${to} \${1}"
       "-i" "$file"
   ];
@@ -68,17 +74,40 @@ let
     )
     do
       echo "replacing stdenv.lib meta in $file" >&2
-      sed -e '/${metaString}/ s/stdenv.lib/lib/' \
+      ${bins.sed} -e '/${metaString}/ s/stdenv.lib/lib/' \
           -i "$file"
       ${add-lib-if-necessary} "$file"
     done
   '';
 
+  instantiate-nixpkgs-randomly = writeExecline "instantiate-nixpkgs-randomly" { readNArgs = 1; } [
+    "export" "NIXPKGS_ALLOW_BROKEN" "1"
+    "export" "NIXPKGS_ALLOW_UNFREE" "1"
+    "export" "NIXPKGS_ALLOW_INSECURE" "1"
+    "export" "NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM" "1"
+    "pipeline" [
+      "nix"
+        "eval"
+        "--raw"
+        ''(
+          let pkgs = import ''${1} {};
+          in builtins.toJSON (builtins.attrNames pkgs)
+        )''
+    ]
+    "pipeline" [ bins.jq "-r" ".[]" ]
+    "pipeline" [ bins.shuf ]
+    "pipeline" [ bins.head "-n" "1000" ]
+    bins.xargs "-I" "{}" "-n1"
+    "if" [ eprintf "instantiating %s\n" "{}" ]
+    "nix-instantiate" "$1" "-A" "{}"
+  ];
+
 in {
+  inherit
+   instantiate-nixpkgs-randomly
   # requires hnix, which we don’t want in tvl for now
   # uncomment manually if you want to use it.
-  # inherit
   #   meta-stdenv-lib
   #   replace-stdenv-lib
-  #   ;
+    ;
 }