Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

qgis-plugins: improve nix hash creation during update #492

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkgs/qgis/plugins.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ stdenv.mkDerivation {

src = fetchurl {
url = plugin.url;
sha256 = plugin.hash;
hash = plugin.hash;
};

dontUnpack = true;
Expand Down
44 changes: 35 additions & 9 deletions pkgs/qgis/update-plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,39 @@

MIN_DOWNLOADS = 100000

qgis_plugins_xml = sys.argv[1]
plugins_xml = sys.argv[1]

if plugins_xml == "qgis-plugins.xml":
qgis_package = "qgis"
elif plugins_xml == "qgis-ltr-plugins.xml":
qgis_package = "qgis-ltr"

def get_nix_hash(url):

def get_nix_hash(qgis_package, name, version):
cmd = run(
["nix", "store", "prefetch-file",
"--option", "download-attempts", "10",
"--json", url
], capture_output=True, text=True
["nix", "eval", "--raw", ".#{}-plugin-{}.version".format(qgis_package, name)],
capture_output=True,
text=True,
)
return json.loads(cmd.stdout)["hash"]

# if plugin already exists in the same version
if cmd.stdout == version:
cmd = run(
["nix", "eval", "--raw", ".#qgis-plugin-{}.src.outputHash".format(name)],
capture_output=True,
text=True,
)
return cmd.stdout

# if plugin doesn't exist or the version is different
else:
cmd = run(
["nix", "store", "prefetch-file",
"--option", "download-attempts", "10",
"--json", url
], capture_output=True, text=True
)
return json.loads(cmd.stdout)["hash"]


def fix_plugin_name(name):
Expand All @@ -30,7 +52,7 @@ def fix_plugin_name(name):


# generate plugins.nix code
tree = etree.parse(qgis_plugins_xml)
tree = etree.parse(plugins_xml)
root = tree.getroot()

print("{") # opening curly
Expand All @@ -45,7 +67,11 @@ def fix_plugin_name(name):
name = fix_plugin_name(plugin.attrib["name"])
url = plugin.find("download_url").text
version = plugin.find("version").text
hash = get_nix_hash(url)
hash = get_nix_hash(
qgis_package,
name,
version
)

print(
f"""
Expand Down
4 changes: 3 additions & 1 deletion pkgs/qgis/update-plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ for package in "${QGIS_PACKAGES[@]}"; do
echo -e "\nUpdating $package plugins ..."
curl $QGIS_PLUGINS_XML_URL?qgis="$major_version" -o "$package"-plugins.xml

python ./update-plugins.py "$package"-plugins.xml > "$package"-plugins-list.nix
python ./update-plugins.py "$package"-plugins.xml > "$package"-plugins-list.nix.new
cp "$package"-plugins-list.nix.new "$package"-plugins-list.nix
rm "$package"-plugins-list.nix.new
done