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

nixos/modules/programs/dconf: redesign profiles #189099

Closed
wants to merge 1 commit into from

Conversation

kekrby
Copy link
Contributor

@kekrby kekrby commented Aug 31, 2022

Description of changes

This PR is a redesign of the NixOS dconf module and provides a way to solve the issues noted in #54150.

If merged, it presents an alternative to extraGSettingsOverrides that is more reliable as the user can disable overriding options with enableUserDb = false;. Users can store their configurations both as dconf keyfiles or as Nix expressions.

This is how the module can be used:

{
  # With keyfiles
  programs.dconf.profiles.user.databases = lib.singleton (pkgs.dconf-utils.mkDconfDb ./files/dconf);

  # With a Nix expression
  programs.dconf.profiles.user.databases = with lib.dconf; lib.singleton {
    org.gnome.shell = {
      disable-user-extensions = true;
      favorite-apps = [ "firefox.desktop" "thunderbird.desktop" ];
      welcome-dialog-last-shown-version = "999";
    };

    org.gnome.desktop.input-sources = {
      sources = [
        (mkTuple [ "xkb" "en" ])
      ];
      xkb-options = [ "terminate:ctrl_alt_bksp" ];
    };
  };
}
Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 22.11 Release Notes (or backporting 22.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@bjornfor
Copy link
Contributor

bjornfor commented Nov 7, 2022

@kekrby: Can you rebase please?

lib/dconf.nix Outdated Show resolved Hide resolved
@kekrby kekrby requested review from jtojnar and removed request for Profpatsch and infinisil November 8, 2022 17:08
@bjornfor
Copy link
Contributor

bjornfor commented Nov 8, 2022

nixos/modules/i18n/input-method/ibus.nix (and possibly more?) refer to the option programs.dconf.packages, which this PR removes. Migrate them in this PR please?

@kekrby kekrby force-pushed the enhance-dconf-module branch 2 times, most recently from 5e0698b to ab3bcd3 Compare November 8, 2022 19:00
@kekrby
Copy link
Contributor Author

kekrby commented Nov 8, 2022

It looks like I missed that. It should now correctly create an ibus profile.

This redesign allows proper creation and management of dconf profiles using NixOS and provides a way to solve the problems noted in issue 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/prs-already-reviewed/2617/891

@@ -3703,6 +3703,8 @@ with pkgs;

dconf = callPackage ../development/libraries/dconf { };

dconf-utils = callPackage ../development/libraries/dconf/utils.nix { };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very tiny, please move it into dconf itself.

Copy link
Contributor

@jtojnar jtojnar Apr 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is only tiny because it is very incomplete. We will eventually want something like https://github.com/nix-community/home-manager/blob/ec06f419af79207b33d797064dfb3fc9dbe1df4a/modules/lib/gvariant.nix Never mind, was looking at a wrong file.

sleep-inactive-battery-timeout=0
''}
'';
programs.dconf.profiles.gdm.databases = [ "${gdm}/share/gdm/greeter-dconf-defaults" ] ++ lib.lists.optional cfg.gdm.autoSuspend {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
programs.dconf.profiles.gdm.databases = [ "${gdm}/share/gdm/greeter-dconf-defaults" ] ++ lib.lists.optional cfg.gdm.autoSuspend {
programs.dconf.profiles.gdm.databases = [ "${gdm}/share/gdm/greeter-dconf-defaults" ]
++ lib.lists.optional cfg.gdm.autoSuspend {

environment.sessionVariables = {
# Needed for unwrapped applications
GIO_EXTRA_MODULES = [ "${pkgs.dconf.lib}/lib/gio/modules" ];
} // (if cfg.defaultProfile != null then { DCONF_PROFILE = cfg.defaultProfile; } else {});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} // (if cfg.defaultProfile != null then { DCONF_PROFILE = cfg.defaultProfile; } else {});
} // lib.optionalAttrs (cfg.defaultProfile != null) { DCONF_PROFILE = cfg.defaultProfile; };

# Needed for unwrapped applications
environment.sessionVariables.GIO_EXTRA_MODULES = mkIf cfg.enable [ "${pkgs.dconf.lib}/lib/gio/modules" ];
environment.sessionVariables = {
# Needed for unwrapped applications
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we rather fix those or is the overhead so big, that we rather not wrap this at all?

in
{
###### interface
imports = [
(lib.mkRemovedOptionModule [ "programs" "dconf" "packages" ] "This option is not supported anymore, you should use `programs.dconf.profiles.<profile>.databases` instead.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We canno use mkRenamedOption here?

@@ -212,6 +217,8 @@ Available as [services.patroni](options.html#opt-services.patroni.enable).
- Emacs now uses the Lucid toolkit by default instead of GTK because of stability and compatibility issues.
Users who still wish to remain using GTK can do so by using `emacs-gtk`.

- The option `programs.dconf.packages` has been removed, use `programs.dconf.profiles.user.databases` instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can definitely be a mkRenamedOption

@@ -125,6 +125,18 @@
would in NixOS 22.05 and earlier.
</para>
</listitem>
<listitem>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer do xml files in nixos/* . Also please carry over the other changelog to 23.05

Comment on lines +5 to +15
rec {
types = {
tuple = "_tuple";
};

mkTuple = _elements: {
inherit _elements;

_type = types.tuple;
};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even need this here? Why not put it into the module.

Copy link
Contributor

@jtojnar jtojnar Apr 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This incomplete implementation of GVariant type system. Ideally, we would have a full implementation like home-manager has and having it separately is nicer for using it in different context, including tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that is the full one, we should keep it separate. Maybe add a comment, that it isn't complete and maybe with a ref to hm.

org.gnome.settings-daemon.plugins.power = {
sleep-inactive-ac-type = "nothing";
sleep-inactive-battery-type = "nothing";
sleep-inactive-ac-timeout = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should require an explicit integer type (eg. lib.gvariant.mkInt). For example, org.gnome.desktop.session’s idle-delay requires uint32 and people regularly trip on it, passing it a Nix number in home-manager, which implicitly gets turned into an int.

Alternative would be making the dconf module internal and creating a separate GSettings module that would also perform validation against schema.

databases = lib.mkOption {
type = with lib.types; listOf (oneOf [ attrs str path package ]);
default = [];
description = lib.mdDoc "List of data sources for the profile. An element can be an attrset, or the path of an already compiled database.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing explanation of string argument.

rrbutani added a commit to rrbutani/nix-config that referenced this pull request Apr 13, 2023
I wrote this before realizing that there's a good implementation of this
in `home-manager`:
  - https://github.com/nix-community/home-manager/blob/master/modules/lib/gvariant.nix
  - https://github.com/nix-community/home-manager/blob/master/tests/lib/types/gvariant-merge.nix
  - https://github.com/nix-community/home-manager/blob/master/modules/misc/dconf.nix

And that there's an INI based adapter for `dconf` in this nixpkgs PR
(which will hopefully be merged soon):
  - NixOS/nixpkgs#189099

Even so, I'm going to keep this for now so that I can set gnome settings
in NixOS configs without needing to wait for that PR or resort to
embedding gschema files.
@linsui
Copy link
Contributor

linsui commented Aug 29, 2023

Suppressed by #234615.

@linsui linsui closed this Aug 29, 2023
@kekrby kekrby deleted the enhance-dconf-module branch August 29, 2023 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants