2021-01-10 20:56:52 +01:00
|
|
|
|
{ depot, pkgs, ... }:
|
|
|
|
|
let
|
|
|
|
|
inherit (depot.nix)
|
|
|
|
|
writeExecline
|
|
|
|
|
;
|
|
|
|
|
inherit (depot.users.Profpatsch.lib)
|
|
|
|
|
debugExec
|
|
|
|
|
;
|
|
|
|
|
|
2021-01-10 21:41:33 +01:00
|
|
|
|
bins = depot.nix.getBins pkgs.coreutils [ "head" "shuf" ]
|
2022-01-30 17:06:58 +01:00
|
|
|
|
// depot.nix.getBins pkgs.jq [ "jq" ]
|
|
|
|
|
// depot.nix.getBins pkgs.findutils [ "xargs" ]
|
|
|
|
|
// depot.nix.getBins pkgs.gnused [ "sed" ]
|
|
|
|
|
;
|
2021-01-10 21:41:33 +01:00
|
|
|
|
|
2022-01-30 17:06:58 +01:00
|
|
|
|
export-json-object = pkgs.writers.writePython3 "export-json-object" { } ''
|
2021-01-10 20:56:52 +01:00
|
|
|
|
import json
|
|
|
|
|
import sys
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
d = json.load(sys.stdin)
|
|
|
|
|
|
|
|
|
|
if d == {}:
|
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
|
for k, v in d.items():
|
|
|
|
|
os.environ[k] = str(v)
|
|
|
|
|
|
|
|
|
|
os.execvp(sys.argv[1], sys.argv[1:])
|
|
|
|
|
'';
|
|
|
|
|
|
2022-01-30 17:06:58 +01:00
|
|
|
|
meta-stdenv-lib = pkgs.writers.writeHaskell "meta-stdenv-lib"
|
|
|
|
|
{
|
|
|
|
|
libraries = [
|
|
|
|
|
pkgs.haskellPackages.hnix
|
|
|
|
|
pkgs.haskellPackages.aeson
|
|
|
|
|
];
|
|
|
|
|
} ./MetaStdenvLib.hs;
|
2021-01-10 20:56:52 +01:00
|
|
|
|
|
|
|
|
|
replace-between-lines = writeExecline "replace-between-lines" { readNArgs = 1; } [
|
2022-01-30 17:06:58 +01:00
|
|
|
|
"importas"
|
|
|
|
|
"-ui"
|
|
|
|
|
"file"
|
|
|
|
|
"fileName"
|
|
|
|
|
"importas"
|
|
|
|
|
"-ui"
|
|
|
|
|
"from"
|
|
|
|
|
"fromLine"
|
|
|
|
|
"importas"
|
|
|
|
|
"-ui"
|
|
|
|
|
"to"
|
|
|
|
|
"toLine"
|
|
|
|
|
"if"
|
|
|
|
|
[ depot.tools.eprintf "%s-%s\n" "$from" "$to" ]
|
2021-01-10 20:56:52 +01:00
|
|
|
|
(debugExec "adding lib")
|
2021-01-10 21:41:33 +01:00
|
|
|
|
bins.sed
|
2022-01-30 17:06:58 +01:00
|
|
|
|
"-e"
|
|
|
|
|
"\${from},\${to} \${1}"
|
|
|
|
|
"-i"
|
|
|
|
|
"$file"
|
2021-01-10 20:56:52 +01:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
add-lib-if-necessary = writeExecline "add-lib-if-necessary" { readNArgs = 1; } [
|
2022-01-30 17:06:58 +01:00
|
|
|
|
"pipeline"
|
|
|
|
|
[ meta-stdenv-lib "$1" ]
|
|
|
|
|
export-json-object
|
|
|
|
|
# first replace any stdenv.lib mentions in the arg header
|
|
|
|
|
# if this is not done, the replace below kills these.
|
|
|
|
|
# Since we want it anyway ultimately, let’s do it here.
|
|
|
|
|
"if"
|
|
|
|
|
[ replace-between-lines "s/stdenv\.lib/lib/" ]
|
|
|
|
|
# then add the lib argument
|
|
|
|
|
# (has to be before stdenv, otherwise default arguments might be in the way)
|
|
|
|
|
replace-between-lines
|
|
|
|
|
"s/stdenv/lib, stdenv/"
|
2021-01-10 20:56:52 +01:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
metaString = ''meta = with stdenv.lib; {'';
|
|
|
|
|
|
|
|
|
|
replace-stdenv-lib = pkgs.writers.writeBash "replace-stdenv-lib" ''
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
sourceDir="$1"
|
|
|
|
|
for file in $(
|
|
|
|
|
${pkgs.ripgrep}/bin/rg \
|
|
|
|
|
--files-with-matches \
|
|
|
|
|
--fixed-strings \
|
|
|
|
|
-e '${metaString}' \
|
|
|
|
|
"$sourceDir"
|
|
|
|
|
)
|
|
|
|
|
do
|
|
|
|
|
echo "replacing stdenv.lib meta in $file" >&2
|
2021-01-10 21:41:33 +01:00
|
|
|
|
${bins.sed} -e '/${metaString}/ s/stdenv.lib/lib/' \
|
2021-01-10 20:56:52 +01:00
|
|
|
|
-i "$file"
|
|
|
|
|
${add-lib-if-necessary} "$file"
|
|
|
|
|
done
|
|
|
|
|
'';
|
|
|
|
|
|
2021-01-10 21:41:33 +01:00
|
|
|
|
instantiate-nixpkgs-randomly = writeExecline "instantiate-nixpkgs-randomly" { readNArgs = 1; } [
|
2022-01-30 17:06:58 +01:00
|
|
|
|
"export"
|
|
|
|
|
"NIXPKGS_ALLOW_BROKEN"
|
|
|
|
|
"1"
|
|
|
|
|
"export"
|
|
|
|
|
"NIXPKGS_ALLOW_UNFREE"
|
|
|
|
|
"1"
|
|
|
|
|
"export"
|
|
|
|
|
"NIXPKGS_ALLOW_INSECURE"
|
|
|
|
|
"1"
|
|
|
|
|
"export"
|
|
|
|
|
"NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM"
|
|
|
|
|
"1"
|
|
|
|
|
"pipeline"
|
|
|
|
|
[
|
2021-01-10 21:41:33 +01:00
|
|
|
|
"nix"
|
2022-01-30 17:06:58 +01:00
|
|
|
|
"eval"
|
|
|
|
|
"--raw"
|
|
|
|
|
''(
|
2021-01-10 21:41:33 +01:00
|
|
|
|
let pkgs = import ''${1} {};
|
|
|
|
|
in builtins.toJSON (builtins.attrNames pkgs)
|
|
|
|
|
)''
|
|
|
|
|
]
|
2022-01-30 17:06:58 +01:00
|
|
|
|
"pipeline"
|
|
|
|
|
[ bins.jq "-r" ".[]" ]
|
|
|
|
|
"pipeline"
|
|
|
|
|
[ bins.shuf ]
|
|
|
|
|
"pipeline"
|
|
|
|
|
[ bins.head "-n" "1000" ]
|
|
|
|
|
bins.xargs
|
|
|
|
|
"-I"
|
|
|
|
|
"{}"
|
|
|
|
|
"-n1"
|
|
|
|
|
"if"
|
|
|
|
|
[ depot.tools.eprintf "instantiating %s\n" "{}" ]
|
|
|
|
|
"nix-instantiate"
|
|
|
|
|
"$1"
|
|
|
|
|
"-A"
|
|
|
|
|
"{}"
|
2021-01-10 21:41:33 +01:00
|
|
|
|
];
|
|
|
|
|
|
2022-01-30 17:06:58 +01:00
|
|
|
|
in
|
|
|
|
|
depot.nix.readTree.drvTargets {
|
2021-01-10 21:41:33 +01:00
|
|
|
|
inherit
|
2022-01-30 17:06:58 +01:00
|
|
|
|
instantiate-nixpkgs-randomly
|
|
|
|
|
# requires hnix, which we don’t want in tvl for now
|
|
|
|
|
# uncomment manually if you want to use it.
|
|
|
|
|
# meta-stdenv-lib
|
|
|
|
|
# replace-stdenv-lib
|
2021-01-10 21:41:33 +01:00
|
|
|
|
;
|
2021-01-10 20:56:52 +01:00
|
|
|
|
}
|