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

Commit

Permalink
qgis-plugins: improve nix hash creation during update
Browse files Browse the repository at this point in the history
  • Loading branch information
imincik committed May 23, 2024
1 parent 706d9bb commit 1cf36f6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
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

0 comments on commit 1cf36f6

Please sign in to comment.