From 3a9e4af6daf50bec0ae07db99fa196f00f641851 Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 7 Nov 2024 02:53:32 +0000 Subject: [PATCH] modules/programs: introduce a `gsettings` config option, which so far routes to dconf but later will stand alone --- hosts/common/programs/dconf.nix | 16 +++++++++-- hosts/common/programs/gnome-weather.nix | 38 ++++++++++++++----------- hosts/common/programs/sane-theme.nix | 18 +++--------- modules/programs/default.nix | 22 ++++++++++++++ 4 files changed, 62 insertions(+), 32 deletions(-) diff --git a/hosts/common/programs/dconf.nix b/hosts/common/programs/dconf.nix index db09e5c60..0e270947c 100644 --- a/hosts/common/programs/dconf.nix +++ b/hosts/common/programs/dconf.nix @@ -5,6 +5,17 @@ { config, lib, pkgs, ... }: let + # [ ProgramConfig ] + enabledPrograms = builtins.filter + (p: p.enabled && p.gsettings != {}) + (builtins.attrValues config.sane.programs); + + sitePackages = lib.map (p: pkgs.writeTextFile { + name = "${p.name}-dconf"; + destination = "/etc/dconf/db/site.d/10_${p.name}"; + text = lib.generators.toDconfINI p.gsettings; + }) enabledPrograms; + cfg = config.sane.programs.dconf; in { @@ -13,10 +24,11 @@ in type = types.submodule { options = { site = mkOption { + # TODO: this option shouldn't be necessary; generate it all directly from `gsettings` type = types.listOf types.package; default = []; description = '' - extra packages to link into /etc/dconf + dconf values to link into /etc/dconf ''; }; }; @@ -40,7 +52,7 @@ in # but in practice seems unnecessary. # env.GIO_EXTRA_MODULES = "${pkgs.dconf.lib}/lib/gio/modules"; - config.site = [ + config.site = sitePackages ++ [ (pkgs.writeTextFile { name = "dconf-user-profile"; destination = "/etc/dconf/profile/user"; diff --git a/hosts/common/programs/gnome-weather.nix b/hosts/common/programs/gnome-weather.nix index 8b3465cd8..c426fa914 100644 --- a/hosts/common/programs/gnome-weather.nix +++ b/hosts/common/programs/gnome-weather.nix @@ -1,6 +1,4 @@ -# preferences are saved via dconf; see `dconf dump /` -# cache dir is just for weather data (or maybe a http cache) -{ config, lib, pkgs, ... }: +{ lib, pkgs, ... }: { sane.programs.gnome-weather = { buildCost = 1; @@ -16,21 +14,29 @@ sandbox.wrapperType = "inplace"; #< /share/org.gnome.Weather/org.gnome.Weather file refers to bins by full path sandbox.whitelistWayland = true; sandbox.net = "clearnet"; - suggestedPrograms = [ "dconf" ]; #< stores city/location settings persist.byStore.plaintext = [ - ".cache/libgweather" + ".cache/libgweather" # weather data (or maybe a http cache) ]; - }; - sane.programs.dconf.config.site = lib.mkIf config.sane.programs.gnome-weather.enabled [ - (pkgs.writeTextFile { - name = "sane-gnome-weather"; - destination = "/etc/dconf/db/site.d/10_gnome_weather"; - text = '' - [org/gnome/Weather] - locations=[<(uint32 2, <('Seattle', 'KBFI', true, [(0.82983133145337307, -2.134775231953554)], [(0.83088509144255718, -2.135097419733472)])>)>] - ''; - }) - ]; + gsettings."org/gnome/Weather" = with lib.gvariant; { + # i have no idea the schema: i just exported this after manually entering a location + locations = [ + (mkVariant + (mkTuple [ + (mkUint32 2) + (mkVariant + (mkTuple [ + "Seattle" + "KBFI" + true + [ (mkTuple [ 0.82983133145337307 (-2.134775231953554) ]) ] + [ (mkTuple [ 0.83088509144255718 (-2.135097419733472) ]) ] + ]) + ) + ]) + ) + ]; + }; + }; } diff --git a/hosts/common/programs/sane-theme.nix b/hosts/common/programs/sane-theme.nix index fa90ee931..656033592 100644 --- a/hosts/common/programs/sane-theme.nix +++ b/hosts/common/programs/sane-theme.nix @@ -312,27 +312,17 @@ in suggestedPrograms = [ "sane-backgrounds" ]; + + gsettings."org/gnome/desktop/interface" = { + inherit (cfg) color-scheme cursor-theme gtk-theme icon-theme; + }; }; sane.programs.sane-backgrounds = { sandbox.enable = false; #< no binaries }; - environment.pathsToLink = lib.mkIf config.sane.programs.sane-backgrounds.enabled [ "/share/backgrounds" ]; - sane.programs.dconf.config.site = lib.mkIf config.sane.programs.sane-theme.enabled [ - (pkgs.writeTextFile { - name = "sane-theme"; - destination = "/etc/dconf/db/site.d/10_gtk_settings"; - text = '' - [org/gnome/desktop/interface] - color-scheme="${cfg.color-scheme}" - cursor-theme="${cfg.cursor-theme}" - gtk-theme="${cfg.gtk-theme}" - icon-theme="${cfg.icon-theme}" - ''; - }) - ]; } diff --git a/modules/programs/default.nix b/modules/programs/default.nix index 1c0dc00fa..a80927026 100644 --- a/modules/programs/default.nix +++ b/modules/programs/default.nix @@ -111,6 +111,10 @@ let ); pkgSpec = with lib; types.submodule ({ config, name, ... }: { options = { + name = mkOption { + type = types.str; + default = name; + }; packageUnwrapped = mkOption { type = types.nullOr types.package; description = '' @@ -165,6 +169,24 @@ let type = types.bool; default = true; }; + # XXX: even if these `gsettings` and `mime` properties aren't used by this module, + # putting them here allows for the visibility by the consumers that do actually use them. + gsettings = mkOption { + type = types.attrs; + default = {}; + description = '' + gsetting config values to provide this program (and the broader system). + this is the nix representation of what you'd want `dconf dump /` to show + (only, it's not plumbed to dconf but rather the layer above it -- gsettings). + ''; + example = '' + { + "org/erikreider/swaync" = { + dnd-state = true; + }; + } + ''; + }; mime.priority = mkOption { type = types.int; default = 100;