about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorgnidorah <gnidorah@users.noreply.github.com>2019-10-12 14:18:00 +0300
committergnidorah <gnidorah@users.noreply.github.com>2020-02-21 18:57:56 +0300
commit193e2ed86ea122b288ff8a616512bf821656ac47 (patch)
treec24e2df01d921fc5464b70858579ffd2d3cdbd00 /nixos
parent8130f3c1c2bb0e533b5e150c39911d6e61dcecc2 (diff)
downloadnixlib-193e2ed86ea122b288ff8a616512bf821656ac47.tar
nixlib-193e2ed86ea122b288ff8a616512bf821656ac47.tar.gz
nixlib-193e2ed86ea122b288ff8a616512bf821656ac47.tar.bz2
nixlib-193e2ed86ea122b288ff8a616512bf821656ac47.tar.lz
nixlib-193e2ed86ea122b288ff8a616512bf821656ac47.tar.xz
nixlib-193e2ed86ea122b288ff8a616512bf821656ac47.tar.zst
nixlib-193e2ed86ea122b288ff8a616512bf821656ac47.zip
nixos/gtk: init
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/config/gtk/gtk.nix160
-rw-r--r--nixos/modules/module-list.nix1
2 files changed, 161 insertions, 0 deletions
diff --git a/nixos/modules/config/gtk/gtk.nix b/nixos/modules/config/gtk/gtk.nix
new file mode 100644
index 000000000000..22f1e5d74835
--- /dev/null
+++ b/nixos/modules/config/gtk/gtk.nix
@@ -0,0 +1,160 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+  cfg = config.gtk;
+  gtk2 = cfg.enable && cfg.gtk2;
+
+  toGtk2File = key: value:
+    let
+      value' =
+        if isBool value then (if value then "true" else "false")
+        else if isString value then "\"${value}\""
+        else toString value;
+    in
+      "${key} = ${value'}";
+  toGtk3File = generators.toINI {
+    mkKeyValue = key: value:
+      let
+        value' =
+          if isBool value then (if value then "true" else "false")
+          else toString value;
+      in
+        "${key}=${value'}";
+  };
+
+  settings =
+    optionalAttrs (cfg.font != null)
+      { gtk-font-name = cfg.font.name; }
+    //
+    optionalAttrs (cfg.theme != null)
+      { gtk-theme-name = cfg.theme.name; }
+    //
+    optionalAttrs (cfg.iconTheme != null)
+      { gtk-icon-theme-name = cfg.iconTheme.name; }
+    //
+    optionalAttrs (cfg.cursorTheme != null)
+      { gtk-cursor-theme-name = cfg.cursorTheme.name; };
+
+  fontType = types.submodule {
+    options = {
+      package = mkOption {
+        internal = true;
+        type = types.nullOr types.package;
+        default = null;
+      };
+      name = mkOption {
+        internal = true;
+        type = types.str;
+      };
+    };
+  };
+  themeType = types.submodule {
+    options = {
+      package = mkOption {
+        internal = true;
+        type = types.nullOr types.package;
+        default = null;
+      };
+      name = mkOption {
+        internal = true;
+        type = types.str;
+      };
+    };
+  };
+
+  optionalPackage = opt:
+    optional (opt != null && opt.package != null) opt.package;
+in
+{
+  options = {
+    gtk = {
+      enable = mkEnableOption "Gtk theming configuration";
+
+      gtk2 = mkOption {
+        type = types.bool;
+        default = true;
+        description = ''
+          Whether to enable theming for obsolete GTK2 engine.
+        '';
+      };
+
+      font = mkOption {
+        type = types.nullOr fontType;
+        default = null;
+        example = literalExample ''
+          {
+            name = "Cantarell 11";
+            package = pkgs.cantarell-fonts;
+          };
+        '';
+        description = ''
+          The font to use in GTK+ applications.
+        '';
+      };
+
+      iconTheme = mkOption {
+        type = types.nullOr themeType;
+        default = null;
+        example = literalExample ''
+          {
+            name = "Adwaita";
+            package = pkgs.gnome3.adwaita-icon-theme;
+          };
+        '';
+        description = "The icon theme to use.";
+      };
+
+      cursorTheme = mkOption {
+        type = types.nullOr themeType;
+        default = null;
+        example = literalExample ''
+          {
+            name = "Adwaita";
+            package = pkgs.gnome3.adwaita-icon-theme;
+          };
+        '';
+        description = "The cursor theme to use.";
+      };
+
+      theme = mkOption {
+        type = types.nullOr themeType;
+        default = null;
+        example = literalExample ''
+          {
+            name = "Adwaita";
+            package = pkgs.gnome-themes-extra;
+          };
+        '';
+        description = "The GTK+ theme to use.";
+      };
+    };
+  };
+
+  config = mkMerge [
+
+    (mkIf gtk2 {
+      environment.etc."xdg/gtk-2.0/gtkrc".text =
+        concatStringsSep "\n" (
+          mapAttrsToList toGtk2File settings
+        );
+    })
+
+    (mkIf cfg.enable {
+      environment.systemPackages =
+        optionalPackage cfg.font
+        ++ optionalPackage cfg.theme
+        ++ optionalPackage cfg.iconTheme
+        ++ optionalPackage cfg.cursorTheme;
+
+      environment.etc."xdg/gtk-3.0/settings.ini".text =
+        toGtk3File { Settings = settings; };
+
+      # TODO: support Wayland/XSettings
+      # once https://github.com/NixOS/nixpkgs/issues/54150 is fixed
+    })
+  ];
+
+  meta.maintainers = [ maintainers.gnidorah ];
+}
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index 878b77969af1..101c235e63f4 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -13,6 +13,7 @@
   ./config/appstream.nix
   ./config/console.nix
   ./config/xdg/sounds.nix
+  ./config/gtk/gtk.nix
   ./config/gtk/gtk-icon-cache.nix
   ./config/gnu.nix
   ./config/i18n.nix