Skip to content

Commit

Permalink
utility scripts for bisection
Browse files Browse the repository at this point in the history
  • Loading branch information
ifd3f committed Nov 16, 2024
1 parent f589934 commit 0e3a3a2
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs.url = "/home/astrid/Documents/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
naersk = {
url = "github:nix-community/naersk/master";
Expand Down
96 changes: 96 additions & 0 deletions scripts/bisect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/env python3
"""
A quick and dirty script for bisecting nixpkgs to find where we broke
This is not complete and will probably not be, just keeping for reference
"""

from typing import List
import math
import argparse
import logging
import subprocess
import re
import os
import shutil
from pathlib import Path


logger = logging.getLogger(__name__)


def main():
logging.basicConfig(encoding='utf-8', level=logging.DEBUG)
args = argparser().parse_args()

revlist_path: Path = Path(args.revlist)
revlist = read_oneline_log(revlist_path)
logger.info("Found %d revisions, bisection will take approximately %d steps", revlist, math.log2(len(revlist)))

repo_dir = Path(__file__).parent.parent
logger.info("Changing working directory to repo directory %s", repo_dir)
os.chdir(repo_dir)

logger.info("Initiating bisection")
i_bad = 0
i_good = len(revlist) - 1



def argparser():
parser = argparse.ArgumentParser(prog='nixpkgs-bisect', description='Bisect nixpkgs')
parser.add_argument(
"--revlist",
required=True,
description=(
"File containing nixpkgs revision list. Generate this from nixpkgs with this command:\n\n"
"git log --oneline $KNOWN_GOOD_REV..master --no-abbrev-commit"
)
)
return parser


def read_oneline_log(revlist_path: Path) -> List[str]:
with revlist.open() as f:
return [
l.split()[0]
for l in f
]


def change_this_repo_nixpkgs_version(flake_url: str):
flake_file = Path('flake.nix')

logger.info("Setting nixpkgs revision in %s to %s", flake_file, flake_url)

with flakefile.open() as f:
lines = list(f)
lines[3] = f'nixpkgs.url = "{flake_url}";\n'

with flakefile.open("w") as f:
f.write(''.join(lines))


def set_nixpkgs_version():
pass


def try_build() -> bool:
"""
Try to nix flake update and build. Returns True on success, False otherwise.
"""

cmd = "nix flake update && nix build"
logger.info("Executing: %s", cmd)
result = subprocess.run(cmd, shell=True)
return result.returncode == 0


def run_command(cmd: str):
logger.debug("Executing shell command: %s", cmd)
result = subprocess.run(cmd, shell=True)


if __name__ == "__main__":
main()

4 changes: 4 additions & 0 deletions scripts/bisect_cmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

nix flake update && nix build

0 comments on commit 0e3a3a2

Please sign in to comment.