about summary refs log tree commit diff
path: root/pkgs/desktops/gnome/update.nix
blob: 8335bb642fb1ba995e269c037f6c887f50b859d6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{ stdenv, pkgs, lib, writeScript, python3, common-updater-scripts }:
{ packageName, attrPath ? packageName, versionPolicy ? "tagged", freeze ? false }:

let
  python = python3.withPackages (p: [ p.requests p.libversion ]);
  package = lib.attrByPath (lib.splitString "." attrPath) (throw "Cannot find attribute ‘${attrPath}’.") pkgs;
  packageVersion = lib.getVersion package;
  upperBoundFlag =
    let
      versionComponents = lib.versions.splitVersion packageVersion;
      minorVersion = lib.versions.minor packageVersion;
      minorAvailable = builtins.length versionComponents > 1 && builtins.match "[0-9]+" minorVersion != null;
      nextMinor = builtins.fromJSON minorVersion + 1;
      upperBound = "${lib.versions.major packageVersion}.${builtins.toString nextMinor}";
    in lib.optionalString (freeze && minorAvailable) ''--upper-bound="${upperBound}"'';
  updateScript = writeScript "gnome-update-script" ''
    #!${stdenv.shell}
    set -o errexit
    attr_path="$1"
    package_name="$2"
    package_version="$3"
    version_policy="$4"
    PATH=${lib.makeBinPath [ common-updater-scripts python ]}
    latest_tag=$(python "${./find-latest-version.py}" "$package_name" "$version_policy" "stable" ${upperBoundFlag})
    update-source-version "$attr_path" "$latest_tag"
    echo '[ { "commitBody": "https://gitlab.gnome.org/GNOME/'$package_name'/-/compare/'$package_version'...'$latest_tag'" } ]'
  '';
in {
  name = "gnome-update-script";
  command = [ updateScript attrPath packageName packageVersion versionPolicy ];
  supportedFeatures = [
    "commit"
  ];
}