about summary refs log tree commit diff
path: root/pkgs/desktops/gnome/extensions/buildGnomeExtension.nix
blob: a36251e81ec86f48220a9affd339446482ed5247 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
{ pkgs, lib, stdenv, fetchzip, nixosTests }:

let

  buildGnomeExtension = {
    # Every gnome extension has a UUID. It's the name of the extension folder once unpacked
    # and can always be found in the metadata.json of every extension.
    uuid,
    name,
    pname,
    description,
    # extensions.gnome.org extension URL
    link,
    # Extension version numbers are integers
    version,
    sha256,
    # Hex-encoded string of JSON bytes
    metadata,
  }:

  stdenv.mkDerivation {
    pname = "gnome-shell-extension-${pname}";
    version = builtins.toString version;
    src = fetchzip {
      url = "https://extensions.gnome.org/extension-data/${
          builtins.replaceStrings [ "@" ] [ "" ] uuid
        }.v${builtins.toString version}.shell-extension.zip";
      inherit sha256;
      stripRoot = false;
      # The download URL may change content over time. This is because the
      # metadata.json is automatically generated, and parts of it can be changed
      # without making a new release. We simply substitute the possibly changed fields
      # with their content from when we last updated, and thus get a deterministic output
      # hash.
      postFetch = ''
        echo "${metadata}" | base64 --decode > $out/metadata.json
      '';
    };
    nativeBuildInputs = with pkgs; [ buildPackages.glib ];
    buildPhase = ''
      runHook preBuild
      if [ -d schemas ]; then
        glib-compile-schemas --strict schemas
      fi
      runHook postBuild
    '';
    installPhase = ''
      runHook preInstall
      mkdir -p $out/share/gnome-shell/extensions/
      cp -r -T . $out/share/gnome-shell/extensions/${uuid}
      runHook postInstall
    '';
    meta = {
      description = builtins.head (lib.splitString "\n" description);
      longDescription = description;
      homepage = link;
      license = lib.licenses.gpl2Plus; # https://wiki.gnome.org/Projects/GnomeShell/Extensions/Review#Licensing
      maintainers = with lib.maintainers; [ ];
    };
    passthru = {
      extensionPortalSlug = pname;
      # Store the extension's UUID, because we might need it at some places
      extensionUuid = uuid;

      tests = {
        gnome-extensions = nixosTests.gnome-extensions;
      };
    };
  };
in
  lib.makeOverridable buildGnomeExtension