Skip to content

Commit 7b54df2

Browse files
committed
utility scripts for bisection
1 parent f589934 commit 7b54df2

File tree

3 files changed

+107
-1
lines changed

3 files changed

+107
-1
lines changed

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
inputs = {
3-
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
3+
nixpkgs.url = "/home/astrid/Documents/nixpkgs";
44
flake-utils.url = "github:numtide/flake-utils";
55
naersk = {
66
url = "github:nix-community/naersk/master";

scripts/bisect.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env python3
2+
"""
3+
A quick and dirty script for bisecting nixpkgs to find where we broke
4+
5+
This is not complete and will probably not be, just keeping for reference
6+
"""
7+
8+
from typing import List
9+
import math
10+
import argparse
11+
import logging
12+
import subprocess
13+
import re
14+
import os
15+
import shutil
16+
from pathlib import Path
17+
18+
19+
logger = logging.getLogger(__name__)
20+
21+
22+
def main():
23+
logging.basicConfig(encoding='utf-8', level=logging.DEBUG)
24+
args = argparser().parse_args()
25+
26+
revlist_path: Path = Path(args.revlist)
27+
revlist = read_oneline_log(revlist_path)
28+
logger.info("Found %d revisions, bisection will take approximately %d steps", revlist, math.log2(len(revlist)))
29+
30+
repo_dir = Path(__file__).parent.parent
31+
logger.info("Changing working directory to repo directory %s", repo_dir)
32+
os.chdir(repo_dir)
33+
34+
logger.info("Initiating bisection")
35+
i_bad = 0
36+
i_good = len(revlist) - 1
37+
38+
39+
40+
def argparser():
41+
parser = argparse.ArgumentParser(prog='nixpkgs-bisect', description='Bisect nixpkgs')
42+
parser.add_argument(
43+
"--revlist",
44+
required=True,
45+
description=(
46+
"File containing nixpkgs revision list. Generate this from nixpkgs with this command:\n\n"
47+
"git log --oneline $KNOWN_GOOD_REV..master --no-abbrev-commit"
48+
)
49+
)
50+
return parser
51+
52+
53+
def read_oneline_log(revlist_path: Path) -> List[str]:
54+
with revlist.open() as f:
55+
return [
56+
l.split()[0]
57+
for l in f
58+
]
59+
60+
61+
def change_this_repo_nixpkgs_version(flake_url: str):
62+
flake_file = Path('flake.nix')
63+
64+
logger.info("Setting nixpkgs revision in %s to %s", flake_file, flake_url)
65+
66+
with flakefile.open() as f:
67+
lines = list(f)
68+
lines[3] = f'nixpkgs.url = "{flake_url}";\n'
69+
70+
with flakefile.open("w") as f:
71+
f.write(''.join(lines))
72+
73+
74+
def set_nixpkgs_version():
75+
pass
76+
77+
78+
def try_build() -> bool:
79+
"""
80+
Try to nix flake update and build. Returns True on success, False otherwise.
81+
"""
82+
83+
cmd = "nix flake update && nix build"
84+
logger.info("Executing: %s", cmd)
85+
result = subprocess.run(cmd, shell=True)
86+
return result.returncode == 0
87+
88+
89+
def run_command(cmd: str):
90+
logger.debug("Executing shell command: %s", cmd)
91+
result = subprocess.run(cmd, shell=True)
92+
93+
94+
if __name__ == "__main__":
95+
main()
96+

scripts/bisect_cmd.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
basedir=$(dirname "$0")
4+
5+
set -euxo pipefail
6+
7+
cd "$basedir"
8+
9+
nix flake update && nix build
10+

0 commit comments

Comments
 (0)