Created
May 4, 2019 11:15
-
-
Save vikanezrimaya/5f6732376426190cb1379a0353c51071 to your computer and use it in GitHub Desktop.
theming.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ config, pkgs, lib, ... }: | |
with lib; | |
let | |
fontModule = types.submodule { | |
options = { | |
package = mkOption { | |
type = types.nullOr types.package; | |
default = null; | |
example = literalExample "pkgs.noto-fonts"; | |
description = "Font package to use. Leave unset if the font is already provided by system."; | |
}; | |
family = mkOption { | |
type = types.str; | |
example = "Fira Code"; | |
description = "Font family."; | |
}; | |
weight = mkOption { | |
type = types.str; | |
default = "Regular"; | |
example = "Bold"; | |
}; | |
size = mkOption { | |
type = types.str; | |
default = "10"; | |
example = "10"; | |
description = "Font weight to use."; | |
}; | |
name = mkOption { | |
type = types.str; | |
description = "Full Pango font name. Read-only."; | |
readOnly = true; | |
}; | |
}; | |
}; | |
themeModule = types.submodule { | |
options = { | |
package = mkOption { | |
type = types.nullOr types.package; | |
default = pkgs.gnome3.gnome_themes_standard; | |
example = literalExample "pkgs.gnome3.gnome_themes_standard"; | |
description = '' | |
Package providing the theme. This package will be installed | |
to your profile. If <literal>null</literal> then the theme | |
is assumed to already be available in your profile. | |
''; | |
}; | |
name = mkOption { | |
type = types.str; | |
default = "Adwaita"; | |
example = "Adwaita"; | |
description = "The name of the theme within the package."; | |
}; | |
}; | |
}; | |
optionalPackage = opt: optional (opt != null && opt.package != null) opt.package; | |
in { | |
options = { | |
theming = mkOption { | |
description = "Centralized theming configuration."; | |
type = types.submodule { | |
options = { | |
enable = mkEnableOption "Enable centralized theming config that universally works on all environments."; | |
fonts = mkOption { | |
description = "Font configuration."; | |
type = types.submodule { | |
options = { | |
monospace = fontModule; | |
sans = fontModule; | |
otherPackages = mkOption { | |
type = types.listOf types.package; | |
default = []; | |
example = "with pkgs; [ font-awesome_5 ]"; | |
description = "Additional font packages, if something in your configuration requires them."; | |
}; | |
}; | |
}; | |
}; | |
icons = mkOption { description = "Icon theme configuration."; type = themeModule; }; | |
theme = mkOption { description = "Toolkit theme configuration."; type = themeModule; }; | |
}; | |
}; | |
}; | |
}; | |
config = (mkIf config.theming.enable { | |
home.packages = map optionalPackage [theming.fonts.monospace theming.fonts.sans theming.fonts.otherPackages theming.icons theming.theme]; | |
theming.fonts = { | |
monospace.name = with theming.fonts.monospace; mkDefault "${family} ${weight} ${size}"; | |
sans.name = with theming.fonts.sans; mkDefault "${family} ${weight} ${size}"; | |
}; | |
gtk = { | |
font = { | |
name = config.theming.fonts.sans.name; | |
}; | |
theme = { | |
name = config.theming.theme.name; | |
}; | |
iconTheme = { | |
name = config.theming.icons.name; | |
}; | |
}; | |
qt.platformTheme = "gtk"; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment