Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stylix: clean up fromOs #407

Merged
merged 7 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions stylix/cursor.nix
Original file line number Diff line number Diff line change
@@ -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;
};
};
}
36 changes: 2 additions & 34 deletions stylix/darwin/default.nix
Original file line number Diff line number Diff line change
@@ -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 = [
Expand All @@ -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 ];
};
}
18 changes: 8 additions & 10 deletions stylix/fonts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ with lib;
let
cfg = config.stylix.fonts;

fromOs = import ./fromos.nix { inherit lib args; };

fontType = types.submodule {
options = {
package = mkOption {
Expand All @@ -26,7 +24,7 @@ in {
serif = mkOption {
description = "Serif font.";
type = fontType;
default = fromOs [ "fonts" "serif" ] {
default = {
package = pkgs.dejavu_fonts;
name = "DejaVu Serif";
};
Expand All @@ -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";
};
Expand All @@ -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";
};
Expand All @@ -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";
};
Expand All @@ -66,23 +64,23 @@ in {
the desktop.
'';
type = types.ints.unsigned;
default = fromOs [ "fonts" "sizes" "desktop" ] 10;
default = 10;
};

applications = mkOption {
description = ''
The font size used by applications.
'';
type = types.ints.unsigned;
default = fromOs [ "fonts" "sizes" "applications" ] 12;
default = 12;
};

terminal = mkOption {
description = ''
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 {
Expand All @@ -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;
};
};

Expand Down
8 changes: 0 additions & 8 deletions stylix/fromos.nix

This file was deleted.

75 changes: 75 additions & 0 deletions stylix/home-manager-integration.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
homeManagerModule:
{ lib, config, options, ... }:

let
copyModules = builtins.map
(
{ path, condition ? lib.const true }:
{ config, osConfig, ... }:
trueNAHO marked this conversation as resolved.
Show resolved Hide resolved
lib.mkIf (condition config)
danth marked this conversation as resolved.
Show resolved Hide resolved
(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" "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" "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 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;
};
danth marked this conversation as resolved.
Show resolved Hide resolved

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 config.stylix.homeManagerIntegration.autoImport {
home-manager.sharedModules = [ homeManagerModule ] ++ copyModules;
});
danth marked this conversation as resolved.
Show resolved Hide resolved
}
36 changes: 2 additions & 34 deletions stylix/nixos/default.nix
Original file line number Diff line number Diff line change
@@ -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 = [
Expand All @@ -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 ];
});
}
15 changes: 6 additions & 9 deletions stylix/opacity.nix
Original file line number Diff line number Diff line change
@@ -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;
};
};
}
18 changes: 3 additions & 15 deletions stylix/palette.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
with lib;

let
fromOs = import ./fromos.nix { inherit lib args; };

cfg = config.stylix;

paletteJSON = let
Expand All @@ -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 = [
Expand All @@ -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.

Expand All @@ -72,7 +64,6 @@ 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;
};

generated = {
Expand Down Expand Up @@ -107,10 +98,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.

Expand All @@ -135,7 +123,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 = {
Expand Down
Loading