diff --git a/stylix/fonts.nix b/stylix/fonts.nix
index 5b15606..96cba91 100644
--- a/stylix/fonts.nix
+++ b/stylix/fonts.nix
@@ -1,8 +1,11 @@
-{ pkgs, config, lib, ... }:
+{ pkgs, config, lib, ... } @ args:
with lib;
let
+
+ fromOs = import ./fromos.nix { inherit lib args; };
+
fontType = types.submodule {
options = {
package = mkOption {
@@ -22,7 +25,7 @@ in {
serif = mkOption {
description = "Serif font.";
type = fontType;
- default = {
+ default = fromOs [ "fonts" "serif" ] {
package = pkgs.dejavu_fonts;
name = "DejaVu Serif";
};
@@ -31,7 +34,7 @@ in {
sansSerif = mkOption {
description = "Sans-serif font.";
type = fontType;
- default = {
+ default = fromOs [ "fonts" "sansSerif" ] {
package = pkgs.dejavu_fonts;
name = "DejaVu Sans";
};
@@ -40,7 +43,7 @@ in {
monospace = mkOption {
description = "Monospace font.";
type = fontType;
- default = {
+ default = fromOs [ "fonts" "monospace" ] {
package = pkgs.dejavu_fonts;
name = "DejaVu Sans Mono";
};
@@ -49,7 +52,7 @@ in {
emoji = mkOption {
description = "Emoji font.";
type = fontType;
- default = {
+ default = fromOs [ "fonts" "emoji" ] {
package = pkgs.noto-fonts-emoji;
name = "Noto Color Emoji";
};
diff --git a/stylix/fromos.nix b/stylix/fromos.nix
new file mode 100644
index 0000000..e7dc8c4
--- /dev/null
+++ b/stylix/fromos.nix
@@ -0,0 +1,6 @@
+{ lib, args }:
+
+path: default:
+if (args ? "osConfig" && args.osConfig.stylix.homeManagerIntegration.enable)
+ then lib.attrByPath path default args.osConfig.stylix
+ else default
diff --git a/stylix/hm/default.nix b/stylix/hm/default.nix
index 378dfb1..7ca95b4 100644
--- a/stylix/hm/default.nix
+++ b/stylix/hm/default.nix
@@ -1,10 +1,7 @@
{ palette-generator, base16 }:
-{ config, lib, ... }@mod-args:
+{ config, lib, ... }:
let
- inherit (lib) types;
- from-nixos = mod-args ? "osConfig";
- system-theme = config.stylix.useSystemTheme;
autoload = import ../autoload.nix { inherit lib; } "hm";
in {
imports = [
@@ -13,57 +10,4 @@ in {
./fonts.nix
(import ./palette.nix { inherit palette-generator base16; })
] ++ autoload;
-
- options.stylix = {
- useSystemTheme = lib.mkOption {
- type = types.bool;
- description = ''
- Use NixOS stylix theme for this user.
-
- Doesn't do anything if the home-manager configuration is not used
- from NixOS.
- '';
- default =
- if from-nixos
- then mod-args.osConfig.stylix.homeManagerIntegration.enable
- else false;
- };
- };
-
- config = lib.mkMerge [
- (lib.mkIf (system-theme && !from-nixos) {
- warnings = [
- "stylix.useSystemTheme is ignored if the config is not used from NixOS"
- ];
- })
- (lib.mkIf (system-theme && from-nixos) (let
- cfg = mod-args.osConfig.stylix;
- mk = lib.mkOverride 99;
- in {
- stylix.autoEnable = mk cfg.autoEnable;
- stylix.fonts.serif = mk cfg.fonts.serif;
- stylix.fonts.sansSerif = mk cfg.fonts.sansSerif;
- stylix.fonts.monospace = mk cfg.fonts.monospace;
- stylix.fonts.emoji = mk cfg.fonts.emoji;
- stylix.polarity = mk cfg.polarity;
- stylix.image = mk cfg.image;
- stylix.palette.base00 = cfg.palette.base00;
- stylix.palette.base01 = cfg.palette.base01;
- stylix.palette.base02 = cfg.palette.base02;
- stylix.palette.base03 = cfg.palette.base03;
- stylix.palette.base04 = cfg.palette.base04;
- stylix.palette.base05 = cfg.palette.base05;
- stylix.palette.base06 = cfg.palette.base06;
- stylix.palette.base07 = cfg.palette.base07;
- stylix.palette.base08 = cfg.palette.base08;
- stylix.palette.base09 = cfg.palette.base09;
- stylix.palette.base0A = cfg.palette.base0A;
- stylix.palette.base0B = cfg.palette.base0B;
- stylix.palette.base0C = cfg.palette.base0C;
- stylix.palette.base0D = cfg.palette.base0D;
- stylix.palette.base0E = cfg.palette.base0E;
- stylix.palette.base0F = cfg.palette.base0F;
- stylix.base16Scheme = cfg.base16Scheme;
- }))
- ];
}
diff --git a/stylix/hm/palette.nix b/stylix/hm/palette.nix
index b48970e..e6e0abd 100644
--- a/stylix/hm/palette.nix
+++ b/stylix/hm/palette.nix
@@ -7,7 +7,7 @@ args:
config = {
xdg.configFile = {
# See ../nixos/palette.nix for the rational behind these two options
- "stylix/palette.json".source = config.stylix.generatedJSON;
+ "stylix/palette.json".source = config.stylix.generated.json;
"stylix/palette.html".source = config.lib.stylix.colors {
template = builtins.readFile ../palette.html.mustache;
extension = ".html";
diff --git a/stylix/nixos/palette.nix b/stylix/nixos/palette.nix
index 1b40a59..b14bdcd 100644
--- a/stylix/nixos/palette.nix
+++ b/stylix/nixos/palette.nix
@@ -10,7 +10,7 @@ args:
# garbage collection, so future configurations can be evaluated without
# having to generate the palette again. The generator is not kept, only
# the palette which came from it, so this uses very little disk space.
- "stylix/palette.json".source = config.stylix.generatedJSON;
+ "stylix/palette.json".source = config.stylix.generated.json;
# We also provide a HTML version which is useful for viewing the colors
# during development.
diff --git a/stylix/palette.nix b/stylix/palette.nix
index 2464f64..80cef76 100644
--- a/stylix/palette.nix
+++ b/stylix/palette.nix
@@ -1,9 +1,11 @@
{ palette-generator, base16 }:
-{ pkgs, lib, config, ... }:
+{ pkgs, lib, config, ... }@args:
with lib;
let
+ fromOs = import ./fromos.nix { inherit lib args; };
+
cfg = config.stylix;
paletteJSON = pkgs.runCommand "palette.json" { } ''
@@ -11,7 +13,7 @@ let
'';
generatedPalette = importJSON paletteJSON;
- generatedScheme = cfg.palette // {
+ generatedScheme = generatedPalette // {
author = "Stylix";
scheme = "Stylix";
slug = "stylix";
@@ -21,7 +23,7 @@ in {
options.stylix = {
polarity = mkOption {
type = types.enum [ "either" "light" "dark" ];
- default = "either";
+ default = fromOs [ "polarity" ] "either";
description = ''
Use this option to force a light or dark theme.
@@ -39,36 +41,28 @@ in {
This is set as the background of your desktop environment, if possible,
and used to generate a colour scheme if you don't set one manually.
'';
+ default = fromOs [ "image" ] null;
};
- generatedJSON = mkOption {
- type = types.path;
- description = "The result of palette-generator.";
- readOnly = true;
- internal = true;
- default = paletteJSON;
+ generated = {
+ json = mkOption {
+ type = types.path;
+ description = "The result of palette-generator.";
+ readOnly = true;
+ internal = true;
+ default = paletteJSON;
+ };
+
+ palette = mkOption {
+ type = types.attrs;
+ description = "The imported json";
+ readOnly = true;
+ internal = true;
+ default = generatedPalette;
+ };
};
- palette = genAttrs [
- "base00" "base01" "base02" "base03" "base04" "base05" "base06" "base07"
- "base08" "base09" "base0A" "base0B" "base0C" "base0D" "base0E" "base0F"
- ] (base: mkOption {
- description = ''
- Hexadecimal color value for ${base}.
-
- You can use this option to override single colors.
- See stylix.base16Scheme if you want to import a
- whole base16 scheme from a file.
-
- You should not read from this option to access the chosen colors - use
- lib.stylix.colors instead.
- If stylix.base16Scheme is set to an external file,
- those colors won't appear here.
- '';
- type = types.strMatching "[0-9a-fA-F]{6}";
- default = generatedPalette.${base};
- defaultText = literalDocBook "Automatically selected from the background image.";
- });
+ # TODO proper removal of palette
base16Scheme = mkOption {
description = ''
@@ -77,9 +71,12 @@ in {
This can be a path to a file, a string of YAML, or an attribute set.
'';
type = with types; oneOf [ path lines attrs ];
- default = generatedScheme;
+ default =
+ if args ? "osConfig" && cfg.image != args.osConfig.stylix.image
+ then generatedScheme
+ else fromOs [ "base16Scheme" ] generatedScheme;
defaultText = literalDocBook ''
- The colors defined in stylix.palette.
+ The colors used in the theming.
Those are automatically selected from the background image by default,
but could be overridden manually.
diff --git a/stylix/target.nix b/stylix/target.nix
index ec2b568..46b7506 100644
--- a/stylix/target.nix
+++ b/stylix/target.nix
@@ -2,11 +2,13 @@
with lib;
-{
+let
+ fromOs = import ./fromos.nix { inherit lib args; };
+in {
options.stylix.autoEnable = mkOption {
description = "Whether to automatically enable styling for installed targets.";
type = types.bool;
- default = true;
+ default = fromOs [ "autoEnable" ] true;
};
config.lib.stylix.mkEnableTarget =