nixos-config/scripts/diff-drvs.py

50 lines
1.6 KiB
Python
Raw Normal View History

2022-05-15 20:31:22 +00:00
#!/usr/bin/env python3
import sys
import subprocess
import json
old_drv = sys.argv[1]
new_drv = sys.argv[2]
# Read both derivations recursively
2022-05-15 20:54:48 +00:00
old_derivation = json.load(open(old_drv))
new_derivation = json.load(open(new_drv))
2022-05-15 20:31:22 +00:00
packages = {}
for drv in old_derivation:
drvData = old_derivation[drv]
if "pname" in drvData["env"]:
2022-05-18 20:19:41 +00:00
version = drvData["env"]["version"] if "version" in drvData[
"env"] else drv
if drvData["env"]["pname"] in packages:
packages[drvData["env"]["pname"]]["old"].add(version)
else:
2022-05-18 20:19:41 +00:00
packages[drvData["env"]["pname"]] = {"old": {version}}
2022-05-15 20:31:22 +00:00
for drv in new_derivation:
drvData = new_derivation[drv]
if "pname" in drvData["env"]:
2022-05-18 20:19:41 +00:00
version = drvData["env"]["version"] if "version" in drvData[
"env"] else drv
2022-05-15 20:31:22 +00:00
if drvData["env"]["pname"] in packages:
if "new" in packages[drvData["env"]["pname"]]:
packages[drvData["env"]["pname"]]["new"].add(version)
else:
packages[drvData["env"]["pname"]]["new"] = {version}
2022-05-15 20:31:22 +00:00
else:
2022-05-18 20:19:41 +00:00
packages[drvData["env"]["pname"]] = {"new": {version}}
2022-05-15 20:31:22 +00:00
for package in packages:
if "old" in packages[package] and "new" in packages[package]:
if packages[package]["old"] != packages[package]["new"]:
2022-05-18 20:19:41 +00:00
print(
f"{package}: {packages[package]['old']} -> {packages[package]['new']}"
)
2022-05-15 20:31:22 +00:00
elif "old" in packages[package]:
print(f"{package}: {packages[package]['old']} -> removed")
elif "new" in packages[package]:
print(f"{package}: added -> {packages[package]['new']}")