Skip to content

Commit

Permalink
stylix: clean up fromOs
Browse files Browse the repository at this point in the history
  • Loading branch information
danth committed May 31, 2024
1 parent 5234b3d commit ba978e5
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 122 deletions.
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.

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

let
alwaysCopy = path: {
inherit path;
condition = lib.const true;
};

copyModules = builtins.map
(
{ path, condition ? lib.const true }:
{ config, osConfig, ... }:
lib.mkIf (condition config)
(lib.setAttrByPath path (lib.mkDefault (lib.getAttrFromPath path osConfig)))
)
[
(alwaysCopy [ "stylix" "autoEnable" ])
{
path = [ "stylix" "base16Scheme" ];
condition = homeConfig: config.stylix.image == homeConfig.stylix.image;
}
(alwaysCopy [ "stylix" "cursor" "name" ])
(alwaysCopy [ "stylix" "cursor" "package" ])
(alwaysCopy [ "stylix" "cursor" "size" ])
(alwaysCopy [ "stylix" "fonts" "serif" ])
(alwaysCopy [ "stylix" "fonts" "sansSerif" ])
(alwaysCopy [ "stylix" "fonts" "monospace" ])
(alwaysCopy [ "stylix" "fonts" "emoji" ])
(alwaysCopy [ "stylix" "fonts" "sizes" "desktop" ])
(alwaysCopy [ "stylix" "fonts" "sizes" "applications" ])
(alwaysCopy [ "stylix" "fonts" "sizes" "terminal" ])
(alwaysCopy [ "stylix" "fonts" "sizes" "popups" ])
(alwaysCopy [ "stylix" "image" ])
(alwaysCopy [ "stylix" "opacity" "desktop" ])
(alwaysCopy [ "stylix" "opacity" "applications" ])
(alwaysCopy [ "stylix" "opacity" "terminal" ])
(alwaysCopy [ "stylix" "opacity" "popups" ])
{
path = [ "stylix" "override" ];
condition = homeConfig: config.stylix.base16Scheme == homeConfig.stylix.base16Scheme;
}
(alwaysCopy [ "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;
};

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;
});
}
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;
};
};
}
Loading

0 comments on commit ba978e5

Please sign in to comment.