Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] nixos: add environment.gnome3.enableExtensions #46433

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bjornfor
Copy link
Contributor

@bjornfor bjornfor commented Sep 9, 2018

Motivation for this change

I'd like to enable/disable GNOME3 extensions from configuration.nix. However, when testing this I learned that services.xserver.desktopManager.gnome3.extraGSettingsOverrides, which this is built upon, only provides default values for the system. Users are still able to change settings. And once they have made a change, any change to the system default will be ignored. This is marked WIP since I'd like for this setting to be truly declarative. The first 4 commits would be nice to merge anyway, so one can play with this locally at least.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

@bjornfor bjornfor added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: GNOME GNOME desktop environment and its underlying platform labels Sep 9, 2018
@GrahamcOfBorg GrahamcOfBorg added 8.has: documentation This PR adds or changes documentation 8.has: module (update) This PR changes an existing module in `nixos/` labels Sep 9, 2018
@hedning
Copy link
Contributor

hedning commented Sep 10, 2018

dconf settings are stored per user (under ~/.config/dconf), so it would be hard to enforce fully I think.

But something like running dconf reset /org/gnome/shell/enabled-extensions as the user on startup might work OK though?

@bjornfor
Copy link
Contributor Author

dconf settings are stored per user (under ~/.config/dconf), so it would be hard to enforce fully I think.

According to this, one should be able to create lock files that prevent users from doing modifications. In my last fixup commit you can see I try to use it, but it didn't work for me.

Your "dconf reset ..." command sounds good. What setting in NixOS is best for running commands at user login time? (I'd like something shell agnostic.)

@bjornfor
Copy link
Contributor Author

Well, the commit that tries to create dconf lock files does not do the "dconf update" step. I did that manually.

@ryantm ryantm added the 2.status: work-in-progress This PR isn't done label Feb 24, 2019
@jtojnar
Copy link
Member

jtojnar commented Apr 5, 2019

See also #54150

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/recommended-way-to-add-gnome-extensions/5589/3

@bjornfor bjornfor force-pushed the gnome-extensions branch from 119f3c0 to 661862f Compare May 9, 2020 19:11
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 10.rebuild-linux: 1 and removed 8.has: documentation This PR adds or changes documentation labels May 9, 2020
bjornfor added 2 commits May 24, 2020 10:38
This option takes a list of packages / GNOME extensions that will be
(declaratively) enabled. The default value is null, meaning the
extensions are managed imperatively (backwards compatible).
Try to add add a lock file, to prevent users from modifying / overriding
the system (default) settings. However, it doesn't work.
@bjornfor bjornfor force-pushed the gnome-extensions branch from 661862f to 966f3e2 Compare May 24, 2020 08:39
@bbigras
Copy link
Contributor

bbigras commented Jul 16, 2020

Any progress on this?

@bjornfor
Copy link
Contributor Author

Not from my side.

@bbigras
Copy link
Contributor

bbigras commented Jul 16, 2020

What is needed to move this PR forward?

Does #54150 needs to be done first?

@bjornfor
Copy link
Contributor Author

Does #54150 needs to be done first?

Yep, that's what I'm thinking.

@ryantm ryantm marked this pull request as draft October 23, 2020 03:12
@SuperSandro2000 SuperSandro2000 added the 2.status: merge conflict This PR has merge conflicts with the target branch label Jan 18, 2021
@stale
Copy link

stale bot commented Jul 21, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 21, 2021
@Alizter
Copy link
Contributor

Alizter commented Mar 12, 2023

Any news on this?

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 12, 2023
@bjornfor
Copy link
Contributor Author

Any news on this?

No, #54150 still needs to land first.

@linsui
Copy link
Contributor

linsui commented Sep 1, 2023

You can use the dconf module now.

@bjornfor
Copy link
Contributor Author

bjornfor commented Sep 1, 2023

You can use the dconf module now.

Right, there was another PR (not linked here) that fixed it! Cool!

I'll put this back on my TODO list.

@ulysses4ever
Copy link
Contributor

#54150 has ben merged. Anything else left before this one can land?

@bjornfor
Copy link
Contributor Author

#54150 has ben merged. Anything else left before this one can land?

This PR needs a rewrite. It's not high priority for me, as I'm using home-manager for my gnome extensions. Someone please make new PR on top of #54150.

@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 19, 2024
@WillsterJohnson
Copy link

#54150 has ben merged. Anything else left before this one can land?

This PR needs a rewrite. It's not high priority for me, as I'm using home-manager for my gnome extensions. Someone please make new PR on top of #54150.

How are you doing this via home-manager? I looked at your repo but I see it's been a while since that mirror got an update

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Oct 27, 2024
@bjornfor
Copy link
Contributor Author

How are you doing this via home-manager?

Using the dconf module. For example:

{ pkgs, lib, ... }:

let
  # Make widgets smaller to not clip other widgets (default: 100).
  graphWidth = 95;
in
{
  dconf.settings."org/gnome/shell".enabled-extensions = [
    pkgs.gnomeExtensions.system-monitor-next.extensionUuid
  ];

  dconf.settings = {
    "org/gnome/shell/extensions/system-monitor" = {
      # Highlight IO wait with dark red
      cpu-iowait-color = "#a40000ff";

      disk-display = true;
      # In the default color scheme it's impossible to separate reads and
      # writes.
      disk-read-color = "#00ff00ff"; # bright green
      disk-write-color = "#ff0000ff"; # bright red

      cpu-graph-width = graphWidth;
      memory-graph-width = graphWidth;
      net-graph-width = graphWidth;
      disk-graph-width = graphWidth;
    };
  };
}

I looked at your repo but I see it's been a while since that mirror got an update

Yes, I intentionally stopped updating it.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/changing-gdm-gsettings-declaratively/49579/8

@Grraahaam
Copy link

Grraahaam commented Dec 6, 2024

Just to update this thread if ever someone is looking for some answers. As mentioned above, the dconf module is now available.

Here's an example on how to install and enable gnome extensions directly with the dconf module (thanks @Electrostasy) :

{ config, pkgs, lib, ... }:

{
  environment.systemPackages = with pkgs.gnomeExtensions; [
    blur-my-shell
    desktop-cube
    native-window-placement
    panel-date-format
    tiling-shell
    unblank
    user-themes
    system-monitor
  ];

  programs.dconf.profiles.user.databases = [{
    settings = with lib.gvariant; {
      "org/gnome/shell".enabled-extensions =
        builtins.map
          (x: x.extensionUuid)
          (lib.filter (p: p ? extensionUuid) config.environment.systemPackages);
    };
  }];
}

Additionally here's a fix to make it work without having to reboot (logout/in only), again thanks @Electrostasy!

  # Normally, when dconf changes are made to the `user` profile, the user will
  # need to log out and log in again for the changes to be applied. However,
  # in NixOS, this is not sufficient for some cases (automatically enabling
  # extensions), because on a live system, the /etc/dconf path is not updated
  # to the new database on activation. This restores the intended behaviour.
  system.activationScripts.update-dconf-path = lib.mkIf config.programs.dconf.enable {
    text = ''
      dconf_nix_path='${config.environment.etc.dconf.source}'
      if ! [[ /etc/dconf -ef "$dconf_nix_path" ]]; then
        ln -sf "$dconf_nix_path" /etc/dconf
        dconf update /etc/dconf
      fi
    '';
  };

Note

If your extensions aren't enabled, run dconf reset /org/gnome/shell/disabled-extensions and dconf reset /org/gnome/shell/enabled-extensions, to make sure dconf follows what's in your config

Since we can enable extensions that way (and through home-manager), is this PR still relevant? @bjornfor @jtojnar

Discussed here

Edit: Gnome extensions now also include their own UUID, so you only have to add them up to your systemPackages to benefit from the dynamic mapping to enable them (or any other array containing the extension packages)

@bjornfor
Copy link
Contributor Author

bjornfor commented Dec 7, 2024

Since we can enable extensions that way (and through home-manager), is this PR still relevant? @bjornfor @jtojnar

I still think it's valuable to have a simple interface. Why not turn your code above into a NixOS module with environment.gnom3.enableExtensions = [ ... ] interface?

@Grraahaam
Copy link

I still think it's valuable to have a simple interface. Why not turn your code above into a NixOS module with environment.gnom3.enableExtensions = [ ... ] interface?

I agree that having something easier could help.

I have a working local module for this. The config path seems to be environment.gnome.<key> now (e.g. excludePackages).

I'm wondering if I should also add up a module similar to what home-manager does with dconf.settings, and use UUID as keys (or something easier to map an extension to its settings, or keep the dconf way), in order to avoid to write the long programs.dconf.profiles.user.databases.settings + dconf keys, something like :

environment.gnome.extensionsSettings = {
  pkgs.gnomeExtensions.system-monitor.extensionUuid = {
    key = "value";
  };
  pkgs.gnomeExtensions.user-themes.extensionUuid = {
    key = "value";
  };
};

@jtojnar Do you think enableExtensions and potentially extensionsSettings are interesting? If yes I'll continue and open another PR

@jtojnar
Copy link
Member

jtojnar commented Dec 15, 2024

You would need to interpolate it with ${pkgs.gnomeExtensions.system-monitor.extensionUuid}, otherwise the attribute set would contain something like the following:

{
  pkgs = {
    gnomeExtensions = {
      system-monitor = { extensionUuid = { key = "value"; }; };
      user-themes = { extensionUuid = { key = "value"; }; };
    };
  };
}

But I do not think there is a relation between the UUID and schema id for most extensions.


Also, I generally prefer generic options instead of creating specific options (in line with RFC42). enableExtensions would probably be fine since we can just redirect it to programs.gsettings.settings."org.gnome.shell".enabled-extensions + programs.gsettings.schemaPackages once that is implemented. It would be harder to do that for random extensions without somehow keeping track of the UUID → package mapping.

@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: merge conflict This PR has merge conflicts with the target branch 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 2.status: work-in-progress This PR isn't done 6.topic: GNOME GNOME desktop environment and its underlying platform 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 10.rebuild-linux: 1
Projects
None yet
Development

Successfully merging this pull request may close these issues.