stylix: clean up fromOs (#407)
This commit is contained in:
parent
daac8f591f
commit
f060e4059b
10 changed files with 134 additions and 139 deletions
|
|
@ -169,28 +169,36 @@ Or even choose monospace for everything:
|
|||
}
|
||||
```
|
||||
|
||||
## Multi-user configurations
|
||||
## Home Manager inheritance
|
||||
|
||||
For those apps which are configured through Home Manager, Stylix allows you to
|
||||
choose a different theme for each user. This can be done by setting the theme
|
||||
within Home Manager for that user rather than at the system level.
|
||||
By default, if Home Manager is used as part of NixOS, then Stylix will be
|
||||
automatically installed for all users, and the NixOS theme will become their
|
||||
default settings.
|
||||
|
||||
By default, all users follow the system theme. This can be turned off by
|
||||
setting `stylix.homeManagerIntegration.followSystem = false`, in which case you
|
||||
must explicitly set a theme for each user. Setting that option is not required
|
||||
just to be able to override an individual theme.
|
||||
This is convenient for single-user systems, since you can configure everything
|
||||
once at the system level and it will automatically carry over. For multi-user
|
||||
systems, you can override the settings within Home Manager to select a different
|
||||
theme for each user.
|
||||
|
||||
If you would like to disable all Home Manager activity for a user, you can set
|
||||
`stylix.homeManagerIntegration.autoImport = false`, then manually import the
|
||||
Home Manager module for the users for which it should be enabled.
|
||||
You may prefer to disable inheritance entirely, and set up the Home Manager
|
||||
version of Stylix yourself if required. Refer to the options
|
||||
[`stylix.homeManagerIntegration.autoImport`](options/nixos.md#stylixhomemanagerintegrationautoimport)
|
||||
and
|
||||
[`stylix.homeManagerIntegration.followSystem`](options/nixos.md#stylixhomemanagerintegrationfollowsystem)
|
||||
to customize this.
|
||||
|
||||
Note that if the wallpaper image for a user is different to the rest of the
|
||||
system, a separate theme will always be generated for them, even though their
|
||||
`base16Scheme` option has not been overridden. If you want that user to follow
|
||||
the system theme while having a different wallpaper, you will need to manually
|
||||
copy the system theme into their configuration. (This behaviour is necessary as
|
||||
otherwise it would be impossible to use a generated theme for a user while
|
||||
having a manually created theme for the rest of the system.)
|
||||
> [!NOTE]
|
||||
>
|
||||
> There is a special case involving the
|
||||
> [`stylix.base16Scheme`](options/nixos.md#stylixbase16scheme)
|
||||
> option:
|
||||
>
|
||||
> If the wallpaper in a Home Manager configuration is changed, then Home Manager
|
||||
> will stop inheriting the color scheme from NixOS. This allows Home Manager
|
||||
> configurations to use the automatic palette generator without being overridden.
|
||||
>
|
||||
> Similarly, [`stylix.override`](options/nixos.md#stylixoverride) is not inherited
|
||||
> if the color scheme is different.
|
||||
|
||||
## Turning targets on and off
|
||||
|
||||
|
|
|
|||
|
|
@ -1,26 +1,23 @@
|
|||
{ pkgs, config, lib, ... } @ args:
|
||||
{ pkgs, lib, ... } @ args:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.stylix.cursor;
|
||||
fromOs = import ./fromos.nix { inherit lib args; };
|
||||
in {
|
||||
{
|
||||
options.stylix.cursor = {
|
||||
name = mkOption {
|
||||
description = "The cursor name within the package.";
|
||||
type = types.str;
|
||||
default = fromOs [ "cursor" "name" ] "Vanilla-DMZ";
|
||||
default = "Vanilla-DMZ";
|
||||
};
|
||||
package = mkOption {
|
||||
description = "Package providing the cursor theme.";
|
||||
type = types.package;
|
||||
default = fromOs [ "cursor" "package" ] pkgs.vanilla-dmz;
|
||||
default = pkgs.vanilla-dmz;
|
||||
};
|
||||
size = mkOption {
|
||||
description = "The cursor size.";
|
||||
type = types.int;
|
||||
default = fromOs [ "cursor" "size" ] 32;
|
||||
default = 32;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
inputs:
|
||||
{ palette-generator, base16, homeManagerModule }:
|
||||
{ options, config, lib, ... }:
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
hm = config.stylix.homeManagerIntegration;
|
||||
autoload = import ../autoload.nix { inherit lib; } "darwin";
|
||||
in {
|
||||
imports = [
|
||||
|
|
@ -12,37 +11,6 @@ in {
|
|||
./fonts.nix
|
||||
(import ./palette.nix { inherit palette-generator base16; })
|
||||
(import ../templates.nix inputs)
|
||||
(import ../home-manager-integration.nix homeManagerModule)
|
||||
] ++ autoload;
|
||||
|
||||
options.stylix.homeManagerIntegration = {
|
||||
followSystem = lib.mkOption {
|
||||
description = ''
|
||||
When this option is `true`, Home Manager will follow
|
||||
the system theme by default, rather than requiring a theme to be set.
|
||||
|
||||
This will only affect Home Manager configurations which are built
|
||||
within the nix-darwin configuration.
|
||||
'';
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
};
|
||||
|
||||
autoImport = lib.mkOption {
|
||||
description = ''
|
||||
Whether to enable Stylix automatically for every user.
|
||||
|
||||
This only applies to users for which Home Manager is set up within the
|
||||
nix-darwin configuration.
|
||||
'';
|
||||
type = lib.types.bool;
|
||||
default = options ? home-manager;
|
||||
defaultText = lib.literalMD ''
|
||||
`true` when Home Manager is present.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf hm.autoImport {
|
||||
home-manager.sharedModules = [ homeManagerModule ];
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@ with lib;
|
|||
let
|
||||
cfg = config.stylix.fonts;
|
||||
|
||||
fromOs = import ./fromos.nix { inherit lib args; };
|
||||
|
||||
fontType = types.submodule {
|
||||
options = {
|
||||
package = mkOption {
|
||||
|
|
@ -26,7 +24,7 @@ in {
|
|||
serif = mkOption {
|
||||
description = "Serif font.";
|
||||
type = fontType;
|
||||
default = fromOs [ "fonts" "serif" ] {
|
||||
default = {
|
||||
package = pkgs.dejavu_fonts;
|
||||
name = "DejaVu Serif";
|
||||
};
|
||||
|
|
@ -35,7 +33,7 @@ in {
|
|||
sansSerif = mkOption {
|
||||
description = "Sans-serif font.";
|
||||
type = fontType;
|
||||
default = fromOs [ "fonts" "sansSerif" ] {
|
||||
default = {
|
||||
package = pkgs.dejavu_fonts;
|
||||
name = "DejaVu Sans";
|
||||
};
|
||||
|
|
@ -44,7 +42,7 @@ in {
|
|||
monospace = mkOption {
|
||||
description = "Monospace font.";
|
||||
type = fontType;
|
||||
default = fromOs [ "fonts" "monospace" ] {
|
||||
default = {
|
||||
package = pkgs.dejavu_fonts;
|
||||
name = "DejaVu Sans Mono";
|
||||
};
|
||||
|
|
@ -53,7 +51,7 @@ in {
|
|||
emoji = mkOption {
|
||||
description = "Emoji font.";
|
||||
type = fontType;
|
||||
default = fromOs [ "fonts" "emoji" ] {
|
||||
default = {
|
||||
package = pkgs.noto-fonts-emoji;
|
||||
name = "Noto Color Emoji";
|
||||
};
|
||||
|
|
@ -66,7 +64,7 @@ in {
|
|||
the desktop.
|
||||
'';
|
||||
type = types.ints.unsigned;
|
||||
default = fromOs [ "fonts" "sizes" "desktop" ] 10;
|
||||
default = 10;
|
||||
};
|
||||
|
||||
applications = mkOption {
|
||||
|
|
@ -74,7 +72,7 @@ in {
|
|||
The font size used by applications.
|
||||
'';
|
||||
type = types.ints.unsigned;
|
||||
default = fromOs [ "fonts" "sizes" "applications" ] 12;
|
||||
default = 12;
|
||||
};
|
||||
|
||||
terminal = mkOption {
|
||||
|
|
@ -82,7 +80,7 @@ in {
|
|||
The font size for terminals/text editors.
|
||||
'';
|
||||
type = types.ints.unsigned;
|
||||
default = fromOs [ "fonts" "sizes" "terminal" ] cfg.sizes.applications;
|
||||
default = cfg.sizes.applications;
|
||||
};
|
||||
|
||||
popups = mkOption {
|
||||
|
|
@ -91,7 +89,7 @@ in {
|
|||
elements of the desktop.
|
||||
'';
|
||||
type = types.ints.unsigned;
|
||||
default = fromOs [ "fonts" "sizes" "popups" ] cfg.sizes.desktop;
|
||||
default = cfg.sizes.desktop;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
{ lib, args }:
|
||||
|
||||
path: default:
|
||||
if ( args ? "osConfig"
|
||||
&& args.osConfig ? "stylix"
|
||||
&& args.osConfig.stylix.homeManagerIntegration.followSystem)
|
||||
then lib.attrByPath path default args.osConfig.stylix
|
||||
else default
|
||||
79
stylix/home-manager-integration.nix
Normal file
79
stylix/home-manager-integration.nix
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
homeManagerModule:
|
||||
{ lib, config, options, ... }:
|
||||
|
||||
let
|
||||
copyModules = builtins.map
|
||||
(
|
||||
{ path, condition ? lib.const true }:
|
||||
{ config, osConfig, ... }:
|
||||
lib.mkIf (condition config)
|
||||
(lib.setAttrByPath path (lib.mkDefault (lib.getAttrFromPath path osConfig)))
|
||||
)
|
||||
[
|
||||
{ path = [ "stylix" "autoEnable" ]; }
|
||||
{
|
||||
path = [ "stylix" "base16Scheme" ];
|
||||
condition = homeConfig: config.stylix.image == homeConfig.stylix.image;
|
||||
}
|
||||
{ path = [ "stylix" "cursor" "name" ]; }
|
||||
{ path = [ "stylix" "cursor" "package" ]; }
|
||||
{ path = [ "stylix" "cursor" "size" ]; }
|
||||
{ path = [ "stylix" "enable" ]; }
|
||||
{ path = [ "stylix" "fonts" "serif" ]; }
|
||||
{ path = [ "stylix" "fonts" "sansSerif" ]; }
|
||||
{ path = [ "stylix" "fonts" "monospace" ]; }
|
||||
{ path = [ "stylix" "fonts" "emoji" ]; }
|
||||
{ path = [ "stylix" "fonts" "sizes" "desktop" ]; }
|
||||
{ path = [ "stylix" "fonts" "sizes" "applications" ]; }
|
||||
{ path = [ "stylix" "fonts" "sizes" "terminal" ]; }
|
||||
{ path = [ "stylix" "fonts" "sizes" "popups" ]; }
|
||||
{ path = [ "stylix" "image" ]; }
|
||||
{ path = [ "stylix" "imageScalingMode" ]; }
|
||||
{ path = [ "stylix" "opacity" "desktop" ]; }
|
||||
{ path = [ "stylix" "opacity" "applications" ]; }
|
||||
{ path = [ "stylix" "opacity" "terminal" ]; }
|
||||
{ path = [ "stylix" "opacity" "popups" ]; }
|
||||
{
|
||||
path = [ "stylix" "override" ];
|
||||
condition = homeConfig: config.stylix.base16Scheme == homeConfig.stylix.base16Scheme;
|
||||
}
|
||||
{ path = [ "stylix" "polarity" ]; }
|
||||
];
|
||||
|
||||
in {
|
||||
options.stylix.homeManagerIntegration = {
|
||||
followSystem = lib.mkOption {
|
||||
description = ''
|
||||
When this option is `true`, Home Manager configurations will follow
|
||||
the NixOS configuration by default, rather than using the standard
|
||||
default settings.
|
||||
|
||||
This only applies to Home Manager configurations managed by
|
||||
[`stylix.homeManagerIntegration.autoImport`](#stylixhomemanagerintegrationautoimport).
|
||||
'';
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
example = false;
|
||||
};
|
||||
|
||||
autoImport = lib.mkOption {
|
||||
description = ''
|
||||
Whether to import Stylix automatically for every Home Manager user.
|
||||
|
||||
This only works if you are using `home-manager.users.«name»` within
|
||||
your NixOS configuration, rather than running Home Manager independently.
|
||||
'';
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
example = false;
|
||||
};
|
||||
};
|
||||
|
||||
config =
|
||||
lib.optionalAttrs (options ? home-manager)
|
||||
(lib.mkIf config.stylix.homeManagerIntegration.autoImport {
|
||||
home-manager.sharedModules =
|
||||
[ homeManagerModule ] ++
|
||||
(lib.optionals config.stylix.homeManagerIntegration.followSystem copyModules);
|
||||
});
|
||||
}
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
inputs:
|
||||
{ palette-generator, base16, homeManagerModule }:
|
||||
{ options, config, lib, ... }:
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
hm = config.stylix.homeManagerIntegration;
|
||||
autoload = import ../autoload.nix { inherit lib; } "nixos";
|
||||
in {
|
||||
imports = [
|
||||
|
|
@ -14,37 +13,6 @@ in {
|
|||
./fonts.nix
|
||||
(import ./palette.nix { inherit palette-generator base16; })
|
||||
(import ../templates.nix inputs)
|
||||
(import ../home-manager-integration.nix homeManagerModule)
|
||||
] ++ autoload;
|
||||
|
||||
options.stylix.homeManagerIntegration = {
|
||||
followSystem = lib.mkOption {
|
||||
description = ''
|
||||
When this option is `true`, Home Manager will follow
|
||||
the system theme by default, rather than requiring a theme to be set.
|
||||
|
||||
This will only affect Home Manager configurations which are built
|
||||
within the NixOS configuration.
|
||||
'';
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
};
|
||||
|
||||
autoImport = lib.mkOption {
|
||||
description = ''
|
||||
Whether to enable Stylix automatically for every user.
|
||||
|
||||
This only applies to users for which Home Manager is set up within the
|
||||
NixOS configuration.
|
||||
'';
|
||||
type = lib.types.bool;
|
||||
default = options ? home-manager;
|
||||
defaultText = lib.literalMD ''
|
||||
`true` when Home Manager is present.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.optionalAttrs (options ? home-manager) (lib.mkIf hm.autoImport {
|
||||
home-manager.sharedModules = [ homeManagerModule ];
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,28 @@
|
|||
{ pkgs, config, lib, ... } @ args:
|
||||
{ lib, ... } @ args:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.stylix.opacity;
|
||||
fromOs = import ./fromos.nix { inherit lib args; };
|
||||
in {
|
||||
{
|
||||
options.stylix.opacity = {
|
||||
desktop = mkOption {
|
||||
description = "The opacity of the windows of bars/widgets, the amount of applications supported is currently limited";
|
||||
type = types.float;
|
||||
default = fromOs [ "opacity" "desktop" ] 1.0;
|
||||
default = 1.0;
|
||||
};
|
||||
applications = mkOption {
|
||||
description = "The opacity of the windows of applications, the amount of applications supported is currently limited";
|
||||
type = types.float;
|
||||
default = fromOs [ "opacity" "applications" ] 1.0;
|
||||
default = 1.0;
|
||||
};
|
||||
terminal = mkOption {
|
||||
description = "The opacity of the windows of terminals, this works across all terminals supported by stylix";
|
||||
type = types.float;
|
||||
default = fromOs [ "opacity" "terminal" ] 1.0;
|
||||
default = 1.0;
|
||||
};
|
||||
popups = mkOption {
|
||||
description = "The opacity of the windows of notifications/popups, the amount of applications supported is currently limited";
|
||||
type = types.float;
|
||||
default = fromOs [ "opacity" "popups" ] 1.0;
|
||||
default = 1.0;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@
|
|||
with lib;
|
||||
|
||||
let
|
||||
fromOs = import ./fromos.nix { inherit lib args; };
|
||||
|
||||
cfg = config.stylix;
|
||||
|
||||
paletteJSON = let
|
||||
|
|
@ -24,12 +22,6 @@ let
|
|||
in json;
|
||||
generatedScheme = importJSON paletteJSON;
|
||||
|
||||
override =
|
||||
(if cfg.base16Scheme == fromOs [ "base16Scheme" ] {}
|
||||
then fromOs [ "override" ] {}
|
||||
else {})
|
||||
// cfg.override;
|
||||
|
||||
in {
|
||||
# TODO link to doc on how to do instead
|
||||
imports = [
|
||||
|
|
@ -54,7 +46,7 @@ in {
|
|||
options.stylix = {
|
||||
polarity = mkOption {
|
||||
type = types.enum [ "either" "light" "dark" ];
|
||||
default = fromOs [ "polarity" ] "either";
|
||||
default = "either";
|
||||
description = ''
|
||||
Use this option to force a light or dark theme.
|
||||
|
||||
|
|
@ -72,12 +64,11 @@ 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;
|
||||
};
|
||||
|
||||
imageScalingMode = mkOption {
|
||||
type = types.enum [ "stretch" "fill" "fit" "center" "tile" ];
|
||||
default = fromOs [ "imageScalingMode" ] "fill";
|
||||
default = "fill";
|
||||
description = ''
|
||||
Wallpaper scaling mode;
|
||||
|
||||
|
|
@ -118,10 +109,7 @@ 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 =
|
||||
if cfg.image != fromOs [ "image" ] null
|
||||
then generatedScheme
|
||||
else fromOs [ "base16Scheme" ] generatedScheme;
|
||||
default = generatedScheme;
|
||||
defaultText = literalMD ''
|
||||
The colors used in the theming.
|
||||
|
||||
|
|
@ -146,7 +134,7 @@ in {
|
|||
config = {
|
||||
# This attrset can be used like a function too, see
|
||||
# https://github.com/SenchoPens/base16.nix/blob/b390e87cd404e65ab4d786666351f1292e89162a/README.md#theme-step-22
|
||||
lib.stylix.colors = (base16.mkSchemeAttrs cfg.base16Scheme).override override;
|
||||
lib.stylix.colors = (base16.mkSchemeAttrs cfg.base16Scheme).override cfg.override;
|
||||
lib.stylix.scheme = base16.mkSchemeAttrs cfg.base16Scheme;
|
||||
|
||||
stylix.generated.fileTree = {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ with lib;
|
|||
are ignored.
|
||||
'';
|
||||
type = types.bool;
|
||||
default = import ./fromos.nix { inherit lib args; } [ "enable" ] false;
|
||||
default = false;
|
||||
example = true;
|
||||
};
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ with lib;
|
|||
detected automatically.
|
||||
'';
|
||||
type = types.bool;
|
||||
default = import ./fromos.nix { inherit lib args; } [ "autoEnable" ] true;
|
||||
default = true;
|
||||
example = false;
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue