GNOME: Difference between revisions

From NixOS Wiki
Added examples of managing extensions; updated dynamic triple buffering overlay, added warning; added curly braces (as NixOS manual do) to configuration examples to indicate its type (attribute set).
m Excluding more GNOME applications
 
(14 intermediate revisions by 6 users not shown)
Line 1: Line 1:
[[{{PAGENAME}}]] (/(ɡ)noʊm/) is a [[desktop environment]] known for its focus on being simple, intuitive, and easy to use. It is made by The GNOME Project and is composed entirely of free and open-source software. Its Mutter compositor supports both [[Wayland]] and X server, and the GNOME Shell user interface is customizable by extensions.
[[{{PAGENAME}}]] (/(ɡ)noʊm/) is a [[:Category:Desktop environment|desktop environment]] known for its focus on being simple, intuitive, and easy to use. It is made by The GNOME Project and is composed entirely of free and open-source software. Its Mutter compositor supports both [[Wayland]] and X server, and the GNOME Shell user interface is customizable by extensions.


This article is an extension of the documentation in the [https://nixos.org/manual/nixos/stable/#chap-gnome NixOS manual].
This article is an extension of the documentation in the [https://nixos.org/manual/nixos/stable/#chap-gnome NixOS manual].
Line 23: Line 23:
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{
{
   environment.gnome.excludePackages = (with pkgs; [
   environment.gnome.excludePackages = with pkgs; [
     # for packages that are pkgs.***
     orca
     gnome-tour
    evince
    # file-roller
    geary
    gnome-disk-utility
    # seahorse
    # sushi
    # sysprof
    #
    # gnome-shell-extensions
    #
    # adwaita-icon-theme
    # nixos-background-info
    gnome-backgrounds
    # gnome-bluetooth
    # gnome-color-manager
    # gnome-control-center
    # gnome-shell-extensions
    gnome-tour # GNOME Shell detects the .desktop file on first log-in.
    gnome-user-docs
    # glib # for gsettings program
    # gnome-menus
    # gtk3.out # for gtk-launch program
    # xdg-user-dirs # Update user dirs as described in https://freedesktop.org/wiki/Software/xdg-user-dirs/
    # xdg-user-dirs-gtk # Used to create the default bookmarks
    #
    baobab
    epiphany
     gnome-text-editor
    gnome-calculator
    gnome-calendar
    gnome-characters
    # gnome-clocks
    gnome-console
    gnome-contacts
    gnome-font-viewer
    gnome-logs
    gnome-maps
    gnome-music
    # gnome-system-monitor
    gnome-weather
    # loupe
    # nautilus
     gnome-connections
     gnome-connections
  ]) ++ (with pkgs.gnome; [
    simple-scan
     # for packages that are pkgs.gnome.*
     snapshot
     epiphany # web browser
     totem
     geary # email reader
     yelp
     evince # document viewer
     gnome-software
   ]);
   ];
}
}
</nowiki>}}
</nowiki>}}
Line 38: Line 79:
== Configuration ==
== Configuration ==


=== Managing Extensions ===
=== Managing extensions ===


GNOME extensions are managed and configured by the program "Extensions" that comes with GNOME.
GNOME extensions are managed and configured by the program "Extensions" that comes with GNOME. Some of them can be installed with Nix, however they aren't enabled by default. To enable them the "Extensions" program can be used.
 
Extensions can be installed with Nix, however they aren't enabled by default. To enable them the "Extensions" program can be used.


{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
Line 54: Line 93:
</nowiki>}}
</nowiki>}}


Extension can be enabled and configured in your system configuration. Look at the following example.
Installed extensions can be enabled and configured in Extension app that comes preinstalled with GNOME. If you want to do that declaratively in your configuration, you can use [[Home Manager]] <code>dconf</code> module by adding following lines.
 
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{
  programs.dconf = {
    enable = true;
    profiles.user.databases = [
      {
        settings = {
          "org/gnome/shell" = {
            disable-user-extensions = false; # enables user extensions (disabled by default)
            enabled-extensions = [
              # Put UUIDs of extensions that you want to enable here.
              # If the extension you want to enable is packaged in nixpkgs,
              # you can easily get its UUID by accessing its extensionUuid
              # field (look at the following example).
              pkgs.gnomeExtensions.blur-my-shell.extensionUuid 
              # Alternatively, you can manually pass UUID as a string. 
              "blur-my-shell@aunetx"
              # ...
            ];
          };
 
          # Configure individual extensions
          "org/gnome/shell/extensions/blur-my-shell" = {
            brightness = 0.75;
            noise-amount = 0;
          };
        };
      }
    ];
  };
}
</nowiki>}}
 
Same result can be achieved for specific user only by using [[Home Manager]] module.


{{file|~/.config/home-manager/home.nix|nix|<nowiki>
{{file|~/.config/home-manager/home.nix|nix|<nowiki>
Line 97: Line 101:
     settings = {
     settings = {
       "org/gnome/shell" = {
       "org/gnome/shell" = {
         disable-user-extensions = false;
         disable-user-extensions = false; # enables user extensions
         enabled-extensions = [
         enabled-extensions = [
           pkgs.gnomeExtensions.blur-my-shell.extensionUuid   
          # Put UUIDs of extensions that you want to enable here.
          # If the extension you want to enable is packaged in nixpkgs,
          # you can easily get its UUID by accessing its extensionUuid
          # field (look at the following example).
           pkgs.gnomeExtensions.gsconnect.extensionUuid
         
          # Alternatively, you can manually pass UUID as a string.  
           "blur-my-shell@aunetx"
           "blur-my-shell@aunetx"
           # ...
           # ...
Line 105: Line 115:
       };
       };


      # Configure individual extensions
       "org/gnome/shell/extensions/blur-my-shell" = {
       "org/gnome/shell/extensions/blur-my-shell" = {
         brightness = 0.75;
         brightness = 0.75;
Line 114: Line 125:
</nowiki>}}
</nowiki>}}


To learn about settings that can be configured with dconf either look into "dconf-editor" program (provided by <code>gnome.dconf-editor</code> package) or type <code>dconf watch /</code> in the terminal and change settings from the GUI and see which options are responsible for that component/element.
=== dconf settings ===
 
Most of the GNOME settings are stored in [https://en.wikipedia.org/wiki/Dconf dconf] database. Settings are stored as keys placed in folders.
 
To learn about settings that can be configured with dconf either look into <code>dconf-editor</code> program (provided by <code>gnome.dconf-editor</code> package) or type <code>dconf watch /</code> in the terminal and change settings from the GUI and see which options are responsible for that component/element.
 
These settings can be changed by NixOS via <code>programs.dconf</code> module or by [[Home Manager]] via <code>dconf</code> module. To so in Home Manager, you need to change <code>dconf.settings</code> attribute set. This attribute set contains absolute folder paths (without leading slash) as attributes' names which value is another attribute set with keys (settings).
 
For example, to change the value of <code>clock-show-weekday</code> key that is located in <code>/org/gnome/desktop/interface</code>, you need to the following:
 
{{file|~/.config/home-manager/home.nix|nix|<nowiki>
{
  dconf.settings = {
    enable = true;
 
    # You need quotes to escape '/'
    "org/gnome/desktop/interface" = {
      clock-show-weekday = true;
    };
  };
}
</nowiki>}}
 
Same can be achieved by using system configuration.
 
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{
  programs.dconf = {
    enable = true;
    profiles.user.databases = [
      {
        lockAll = true; # prevents overriding
        settings = {
          "org/gnome/desktop/interface" = {
            clock-show-weekday = true;
          };
        };
      }
    ];
  };
}
</nowiki>}}
 
{{Note|Since dconf have more data types than Nix language (for example, tuples), in some cases you'll need to convert Nix value to a GVariant value. You can achieve that by using function defined in <code>lib.gvariant</code>, they're documented [https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-gvariant here].}}


=== Dark mode ===
=== Dark mode ===
Line 151: Line 205:
Many applications rely heavily on having an icon theme available, GNOME’s Adwaita is a good choice but most recent icon themes should work as well.
Many applications rely heavily on having an icon theme available, GNOME’s Adwaita is a good choice but most recent icon themes should work as well.


<syntaxHighlight lang="nix">
<syntaxhighlight lang="nix">
{
{
   environment.systemPackages = with pkgs; [ gnome.adwaita-icon-theme ];
   environment.systemPackages = [ pkgs.adwaita-icon-theme ];
}
}
</syntaxHighlight>
</syntaxhighlight>


=== Systray Icons ===
=== Systray Icons ===
Line 201: Line 255:
If you wish to try this patch for yourself, add the following to your NixOS configuration:
If you wish to try this patch for yourself, add the following to your NixOS configuration:


{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{
  nixpkgs.overlays = [
    # GNOME 46: triple-buffering-v4-46
    (final: prev: {
      mutter = prev.mutter.overrideAttrs (old: {
        src = pkgs.fetchFromGitLab  {
          domain = "gitlab.gnome.org";
          owner = "vanvugt";
          repo = "mutter";
          rev = "triple-buffering-v4-46";
          hash = "sha256-C2VfW3ThPEZ37YkX7ejlyumLnWa9oij333d5c4yfZxc=";
        };
      });
    })
  ];
}
</nowiki>}}
Prior to [https://github.com/NixOS/nixpkgs/commit/7f387d6bf915b8fd7d7131edd3e5107f4a98cc9d commit 7f387d6b] (~01.09.2024 for master) <code>mutter</code> was located in <code>gnome</code> scope, so <code>overrideScope</code> was required to achieve the same result:
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{
{
Line 221: Line 295:
}
}
</nowiki>}}
</nowiki>}}


You might need to disable aliases to make it work:
You might need to disable aliases to make it work:
Line 226: Line 301:
<syntaxHighlight lang="nix">
<syntaxHighlight lang="nix">
   nixpkgs.config.allowAliases = false;
   nixpkgs.config.allowAliases = false;
</syntaxHighlight>
</syntaxHighlight>'''NOTE''' - the "allowAliases" set to false has been known to break stylix (if you use it).


=== Profiling (with sysprof) ===
=== Profiling (with sysprof) ===
Line 250: Line 325:
$ mv /path/to/image.jpg ~/.face
$ mv /path/to/image.jpg ~/.face
</syntaxHighlight>
</syntaxHighlight>
==== Change Profile Photo for Login and Lockscreen - Declarative ====
This is admittedly a hack way of doing it, however does work.
Considerations:
* image must be a PNG
* permissions matter
* this is absolutely a workaround
* assumes you are already using a .face file
* you will need to update the paths and username as applicable to your system (CAPITALIZED in the code)
* you cannot change the photo using Gnome Control Center
You can place this in your configuration.nix:<syntaxhighlight lang="nix">
system.activationScripts.script.text = ''
    mkdir -p /var/lib/AccountsService/{icons,users}
    cp /home/YOUR-USER-NAME/PATH-TO/.face /var/lib/AccountsService/icons/YOUR-USER-NAME
    echo -e "[User]\nIcon=/var/lib/AccountsService/icons/YOUR-USER-NAME\n" > /var/lib/AccountsService/users/YOUR-USER-NAME
    chown root:root /var/lib/AccountsService/users/YOUR-USER-NAME
    chmod 0600 /var/lib/AccountsService/users/YOUR-USER-NAME
    chown root:root /var/lib/AccountsService/icons/YOUR-USER-NAME
    chmod 0444 /var/lib/AccountsService/icons/YOUR-USER-NAME
'';
</syntaxhighlight>


=== Automatic login ===
=== Automatic login ===


If you have enabled [https://help.gnome.org/admin/system-admin-guide/stable/login-automatic.html.en auto login] (with <!-- [[GDM]] -->[[{{PAGENAME}}]]) with something like
If you have enabled [https://help.gnome.org/admin/system-admin-guide/stable/login-automatic.html.en auto login] (with <!-- [[GDM]] -->[[{{PAGENAME}}]]) with something like
: <syntaxHighlight lang="bash">
: <syntaxHighlight lang="console">
grep autoLogin /etc/nixos/configuration.nix
$ grep autoLogin /etc/nixos/configuration.nix
</syntaxHighlight>
</syntaxHighlight>
<syntaxHighlight lang="nix">
<syntaxHighlight lang="nix">
Line 262: Line 364:
</syntaxHighlight>
</syntaxHighlight>
than add the following (as a workaround for a current (2023)<ref>https://github.com/NixOS/nixpkgs/issues/103746#issuecomment-945091229</ref> problem)
than add the following (as a workaround for a current (2023)<ref>https://github.com/NixOS/nixpkgs/issues/103746#issuecomment-945091229</ref> problem)
: <syntaxHighlight lang=console># nano /etc/nixos/configuration.nix</syntaxHighlight>
: <syntaxHighlight lang="console"># nano /etc/nixos/configuration.nix</syntaxHighlight>
<syntaxHighlight lang="nix">
<syntaxHighlight lang="nix">
{
   systemd.services."getty@tty1".enable = false;
   systemd.services."getty@tty1".enable = false;
   systemd.services."autovt@tty1".enable = false;
   systemd.services."autovt@tty1".enable = false;
}
</syntaxHighlight>
</syntaxHighlight>


== Also see ==
== See also ==
 
* [[GNOME/Calendar]]
[[GNOME/Calendar]]


[[Category:Desktop environment]]
[[Category:Desktop environment]]
[[Category:Applications]]
[[Category:Applications]]
[[Category:NixOS Manual]]
[[Category:NixOS Manual]]
[[Category:GNOME]]

Latest revision as of 08:50, 22 November 2024

GNOME (/(ɡ)noʊm/) is a desktop environment known for its focus on being simple, intuitive, and easy to use. It is made by The GNOME Project and is composed entirely of free and open-source software. Its Mutter compositor supports both Wayland and X server, and the GNOME Shell user interface is customizable by extensions.

This article is an extension of the documentation in the NixOS manual.

GNOME is available as a module and can be enabled with services.xserver.desktopManager.

Installation

To use GNOME, add this to your configuration.nix:

/etc/nixos/configuration.nix
{
  services.xserver.enable = true;
  services.xserver.displayManager.gdm.enable = true;
  services.xserver.desktopManager.gnome.enable = true;
}

Excluding GNOME Applications

To exclude certain applications that are installed by default with GNOME edit configuration.nix as follows:

/etc/nixos/configuration.nix
{
  environment.gnome.excludePackages = with pkgs; [
    orca
    evince
    # file-roller
    geary
    gnome-disk-utility
    # seahorse
    # sushi
    # sysprof
    #
    # gnome-shell-extensions
    #
    # adwaita-icon-theme
    # nixos-background-info
    gnome-backgrounds
    # gnome-bluetooth
    # gnome-color-manager
    # gnome-control-center
    # gnome-shell-extensions
    gnome-tour # GNOME Shell detects the .desktop file on first log-in.
    gnome-user-docs
    # glib # for gsettings program
    # gnome-menus
    # gtk3.out # for gtk-launch program
    # xdg-user-dirs # Update user dirs as described in https://freedesktop.org/wiki/Software/xdg-user-dirs/
    # xdg-user-dirs-gtk # Used to create the default bookmarks
    #
    baobab
    epiphany
    gnome-text-editor
    gnome-calculator
    gnome-calendar
    gnome-characters
    # gnome-clocks
    gnome-console
    gnome-contacts
    gnome-font-viewer
    gnome-logs
    gnome-maps
    gnome-music
    # gnome-system-monitor
    gnome-weather
    # loupe
    # nautilus
    gnome-connections
    simple-scan
    snapshot
    totem
    yelp
    gnome-software
  ];
}

Configuration

Managing extensions

GNOME extensions are managed and configured by the program "Extensions" that comes with GNOME. Some of them can be installed with Nix, however they aren't enabled by default. To enable them the "Extensions" program can be used.

/etc/nixos/configuration.nix
{
  environment.systemPackages = with pkgs.gnomeExtensions; [
    blur-my-shell
    pop-shell
    # ...
  ];
}

Installed extensions can be enabled and configured in Extension app that comes preinstalled with GNOME. If you want to do that declaratively in your configuration, you can use Home Manager dconf module by adding following lines.

~/.config/home-manager/home.nix
{
  dconf = {
    enable = true;
    settings = {
      "org/gnome/shell" = {
        disable-user-extensions = false; # enables user extensions
        enabled-extensions = [
          # Put UUIDs of extensions that you want to enable here.
          # If the extension you want to enable is packaged in nixpkgs,
          # you can easily get its UUID by accessing its extensionUuid
          # field (look at the following example).
          pkgs.gnomeExtensions.gsconnect.extensionUuid
          
          # Alternatively, you can manually pass UUID as a string.  
          "blur-my-shell@aunetx"
          # ...
        ];
      };

      # Configure individual extensions
      "org/gnome/shell/extensions/blur-my-shell" = {
        brightness = 0.75;
        noise-amount = 0;
      };
    };
  };
}

dconf settings

Most of the GNOME settings are stored in dconf database. Settings are stored as keys placed in folders.

To learn about settings that can be configured with dconf either look into dconf-editor program (provided by gnome.dconf-editor package) or type dconf watch / in the terminal and change settings from the GUI and see which options are responsible for that component/element.

These settings can be changed by NixOS via programs.dconf module or by Home Manager via dconf module. To so in Home Manager, you need to change dconf.settings attribute set. This attribute set contains absolute folder paths (without leading slash) as attributes' names which value is another attribute set with keys (settings).

For example, to change the value of clock-show-weekday key that is located in /org/gnome/desktop/interface, you need to the following:

~/.config/home-manager/home.nix
{
  dconf.settings = {
    enable = true;

    # You need quotes to escape '/'
    "org/gnome/desktop/interface" = {
      clock-show-weekday = true;
    };
  };
}

Same can be achieved by using system configuration.

/etc/nixos/configuration.nix
{
  programs.dconf = {
    enable = true;
    profiles.user.databases = [
      {
        lockAll = true; # prevents overriding
        settings = {
          "org/gnome/desktop/interface" = {
            clock-show-weekday = true;
          };
        };
      }
    ];
  };
}
Note: Since dconf have more data types than Nix language (for example, tuples), in some cases you'll need to convert Nix value to a GVariant value. You can achieve that by using function defined in lib.gvariant, they're documented here.

Dark mode

Change default color theme for all GTK4 applications to dark using Home Manager.

~/.config/home-manager/home.nix
{
  dconf = {
    enable = true;
    settings."org/gnome/desktop/interface".color-scheme = "prefer-dark";
  };
}

Tips and tricks

To run GNOME programs outside of GNOME

GNOME platform-based applications are largely self-contained, but they still depend, for one reason or another, on some global configuration. The gnome.nix module sets all the necessary options for you but if you are running customized set-up, you might need to replicate that yourself.

For instance, if you see the following error:

dconf-WARNING **: failed to commit changes to dconf: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name ca.desrt.dconf was not provided by any .service files

you should enable dconf module:

{
  programs.dconf.enable = true;
}

Many applications rely heavily on having an icon theme available, GNOME’s Adwaita is a good choice but most recent icon themes should work as well.

{
  environment.systemPackages = [ pkgs.adwaita-icon-theme ];
}

Systray Icons

To get systray icons, install the related GNOME shell extension

{
  environment.systemPackages = [ pkgs.gnomeExtensions.appindicator ];
}

And ensure gnome-settings-daemon udev rules are enabled:

{
  services.udev.packages = [ pkgs.gnome.gnome-settings-daemon ];
}

To run old applications

Some old applications use GConf service to store configuration. This has been deprecated for many years but some applications were abandoned before they managed to upgrade to a newer dconf system. If you are running such application and getting an error like:

GLib.GException: Failed to contact configuration server; the most common cause is a missing or misconfigured D-Bus session bus daemon. See http://projects.gnome.org/gconf/ for information

you need to add gnome2.GConf to the list of dbus packages in your configuration.nix:

{
  services.dbus.packages = with pkgs; [ gnome2.GConf ];
}

After applying the update restart your desktop session to refresh the user-specific dbus session.

Dynamic triple buffering

Warning: Dynamic triple buffering is a still developing feature that is not merged into GNOME's mutter. Some bugs and unexpected behavior can occur. Use at your own risk!

Big merge request against Mutter improves the performance of the window manager by a lot (and is already used by Ubuntu). Not merged into nixpkgs due to philosophy of nixpkgs, but users are free to add this overlay to get it too.

If you wish to try this patch for yourself, add the following to your NixOS configuration:

/etc/nixos/configuration.nix
{
  nixpkgs.overlays = [
    # GNOME 46: triple-buffering-v4-46
    (final: prev: {
      mutter = prev.mutter.overrideAttrs (old: {
        src = pkgs.fetchFromGitLab  {
          domain = "gitlab.gnome.org";
          owner = "vanvugt";
          repo = "mutter";
          rev = "triple-buffering-v4-46";
          hash = "sha256-C2VfW3ThPEZ37YkX7ejlyumLnWa9oij333d5c4yfZxc=";
        };
      });
    })
  ];
}

Prior to commit 7f387d6b (~01.09.2024 for master) mutter was located in gnome scope, so overrideScope was required to achieve the same result:

/etc/nixos/configuration.nix
{
  nixpkgs.overlays = [
    # GNOME 46: triple-buffering-v4-46
    (final: prev: {
      gnome = prev.gnome.overrideScope (gnomeFinal: gnomePrev: {
        mutter = gnomePrev.mutter.overrideAttrs (old: {
          src = pkgs.fetchFromGitLab  {
            domain = "gitlab.gnome.org";
            owner = "vanvugt";
            repo = "mutter";
            rev = "triple-buffering-v4-46";
            hash = "sha256-fkPjB/5DPBX06t7yj0Rb3UEuu5b9mu3aS+jhH18+lpI=";
          };
        });
      });
    })
  ];
}


You might need to disable aliases to make it work:

  nixpkgs.config.allowAliases = false;

NOTE - the "allowAliases" set to false has been known to break stylix (if you use it).

Profiling (with sysprof)

Install sysprof as a system package (it won't work properly if installed against users). Then enable the associated service with

  services.sysprof.enable = true;

Automatic screen rotation

  hardware.sensor.iio.enable = true;

Troubleshoots

Change user's profile picture

Currently there is no way to change the user's profile picture using Gnome Control Center (see this issue) and currently there is no plan to support it officially in NixOS. However, you can modify it by copying the profile picture that you want to the path /home/$USER/.face as a workaround, i.e.

$ mv /path/to/image.jpg ~/.face

Change Profile Photo for Login and Lockscreen - Declarative

This is admittedly a hack way of doing it, however does work.

Considerations:

  • image must be a PNG
  • permissions matter
  • this is absolutely a workaround
  • assumes you are already using a .face file
  • you will need to update the paths and username as applicable to your system (CAPITALIZED in the code)
  • you cannot change the photo using Gnome Control Center


You can place this in your configuration.nix:

system.activationScripts.script.text = ''
    mkdir -p /var/lib/AccountsService/{icons,users}
    cp /home/YOUR-USER-NAME/PATH-TO/.face /var/lib/AccountsService/icons/YOUR-USER-NAME
    echo -e "[User]\nIcon=/var/lib/AccountsService/icons/YOUR-USER-NAME\n" > /var/lib/AccountsService/users/YOUR-USER-NAME

    chown root:root /var/lib/AccountsService/users/YOUR-USER-NAME
    chmod 0600 /var/lib/AccountsService/users/YOUR-USER-NAME

    chown root:root /var/lib/AccountsService/icons/YOUR-USER-NAME
    chmod 0444 /var/lib/AccountsService/icons/YOUR-USER-NAME
'';

Automatic login

If you have enabled auto login (with GNOME) with something like

$ grep autoLogin /etc/nixos/configuration.nix
services.xserver.displayManager.autoLogin.enable = true;
services.xserver.displayManager.autoLogin.user = "account";

than add the following (as a workaround for a current (2023)[1] problem)

# nano /etc/nixos/configuration.nix
{
  systemd.services."getty@tty1".enable = false;
  systemd.services."autovt@tty1".enable = false;
}

See also