-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgnome-extensions.nix
104 lines (88 loc) · 3.95 KB
/
gnome-extensions.nix
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Enables Gnome extensions identified by UUID. Automatically loads packages for
# each extension from nixpkgs, but you may provide custom packages for specific
# extensions.
#
# For usage examples see home-manager/features/gnome/default.nix and
# modules/home-manager/paperwm.nix
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.gnomeExtensions;
# Search through `pkgs.gnomeExtensions` for packages for each extension that
# we want. Packages are found by checking the package's `extensionUuid`
# attribute against the list of enabled extension uuids.
enabledExtensionPackages =
let
allExtensionPackages = builtins.attrValues pkgs.gnomeExtensions;
uuidMatches = extensionPackage:
let packageUuid = extensionUuid extensionPackage;
in
uuid: packageUuid == uuid;
hasPackageOverride = uuid: builtins.any (package: uuidMatches package uuid) cfg.packages;
uuidsWithoutOverride = builtins.filter (uuid: !(hasPackageOverride uuid)) cfg.enabledExtensionUuids;
isEnabled = extensionPackage:
builtins.any (uuidMatches extensionPackage) uuidsWithoutOverride;
in
builtins.filter isEnabled allExtensionPackages;
extensionUuid = extensionPackage:
let p = builtins.tryEval extensionPackage; # tryEval because some packages evaluate to deprecation errors
in
if p.success && builtins.isAttrs p.value && builtins.hasAttr "extensionUuid" p.value
then p.value.extensionUuid
else null;
checkForMissing = extensionPackages:
let
noPackagesMatchUuid = uuid: !(builtins.any (p: extensionUuid p == uuid) extensionPackages);
missingUuids = builtins.filter noPackagesMatchUuid cfg.enabledExtensionUuids;
in
if missingUuids != [ ] then abort "Could not find packages for some Gnome extensions: ${builtins.toString missingUuids}"
else extensionPackages;
checkForExtensionUuids = extensionPackages:
let
isAttributeMissing = extensionPackage: builtins.isNull (extensionUuid extensionPackage);
packagesMissingAttribute = builtins.filter isAttributeMissing extensionPackages;
in
if packagesMissingAttribute != [ ] then
builtins.throw "Some of the given extension packages do not have an `extensionUuid` attribute: ${buitins.toString packagesMissingAttribute}"
else extensionPackages;
in
{
options.gnomeExtensions = {
enable = mkEnableOption "gnome-extensions";
enabledExtensionUuids = mkOption {
type = types.listOf types.str;
description = ''
Provide a list of Gnome extension UUID strings. These will be set as the
list of enabled extensions. The corresponding packages will
automatically be installed from pkgs.gnomeExtensions.
Each Gnome extension has an email-like UUID. Gnome uses these UUIDs to
track which of the installed extensions are enabled. There are a couple of
ways to find the UUID. If you look at the source for an extension it
should have a `metadata.json` with a `uuid` field. Or on
a gnome.extensions.org page you can look at the HTML source and find a div
with an attribute like, `data-uuid="..."`.
'';
};
packages = mkOption {
type = types.listOf types.package;
default = [ ];
description = ''
Any extension packages listed here will be used instead of packages from
pkgs.gnomeExtensions.
Each package must have an `extensionUuid` attribute that matches one of
the UUIDs listed in the `enabledExtensionUuids` option. If you build
a package using `stdenv.mkDerivation` then you can do this by passing an
attribute called `passthru.extensionUuid` to `mkDerivation`.
'';
};
};
config = mkIf cfg.enable {
dconf.settings = {
"org/gnome/shell" = {
disable-user-extensions = false;
enabled-extensions = cfg.enabledExtensionUuids;
};
};
home.packages = checkForMissing (enabledExtensionPackages ++ checkForExtensionUuids cfg.packages);
};
}