diff --git a/README.md b/README.md
index 6d189cbf..9d569741 100644
--- a/README.md
+++ b/README.md
@@ -13,9 +13,9 @@ a library which processes themes created for
### NixOS
-You can install Stylix into your NixOS configuration using
-[Flakes](https://nixos.wiki/wiki/Flakes). This will provide theming for system
-level programs such as bootloaders, splash screens, and display managers.
+You can install Stylix into your NixOS configuration using [Flakes][nix-flakes].
+This will provide theming for system level programs such as bootloaders, splash
+screens, and display managers.
```nix
{
@@ -35,8 +35,8 @@ level programs such as bootloaders, splash screens, and display managers.
Minimal `flake.nix` for a NixOS configuration.
Many applications cannot be configured system wide, so Stylix will also need
-[Home Manager](https://github.com/nix-community/home-manager) to be able to
-change their settings within your home directory.
+[Home Manager][nix-hm] to be able to change their settings within your home
+directory.
[Installing Home Manager as a NixOS module](https://nix-community.github.io/home-manager/index.html#sec-install-nixos-module)
is highly recommended if you don't use it already. This will combine it with
@@ -49,6 +49,37 @@ its Home Manager modules if it detects that Home Manager is available. You can
theoretically use it without installing Home Manager, however most features
will be unavailable.
+### nix-darwin
+
+You can install Stylix intor your nix-darwin configuration in a similar fashion
+to NixOS via [Flakes][nix-flakes].
+
+```nix
+{
+ inputs = {
+ darwin = {
+ url = "github:LnL7/nix-darwin";
+ inputs.nixpkgs.follows = "nixpkgs";
+ };
+ nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
+ stylix.url = "github:danth/stylix";
+ };
+
+ outputs = { darwin, nixpkgs, stylix, ... }: {
+ darwinConfigurations."«hostname»" = darwin.lib.darwinSystem {
+ system = "aarch64-darwin";
+ modules = [ stylix.darwinModules.stylix ./configuration.nix ];
+ };
+ };
+}
+```
+
+While this won't have an effect on the looks of macOS, since we don't have the
+controls to theme it like we do NixOS, it will automatically set up its [Home
+Manager][nix-hm] modules if it detects that Home Manager is available. You can
+theoretically use it without installing Home Manager, however most features will
+be unavailable.
+
### Home Manager
If you would prefer to use the standalone version of Home Manager, you can
@@ -297,3 +328,6 @@ The Stylix website has a list of the available targets
and
[for Home Manager](https://danth.github.io/stylix/options-hm.html)
respectively.
+
+[nix-flakes]: https://nixos.wiki/wiki/Flakes
+[nix-hm]: https://github.com/nix-community/home-manager
diff --git a/flake.nix b/flake.nix
index 971473df..15d2b3b2 100644
--- a/flake.nix
+++ b/flake.nix
@@ -34,7 +34,7 @@
};
in recursiveUpdate docsOutputs {
- packages = genAttrs [ "aarch64-linux" "i686-linux" "x86_64-linux" ] (
+ packages = genAttrs [ "aarch64-darwin" "aarch64-linux" "i686-linux" "x86_64-darwin" "x86_64-linux" ] (
system:
let pkgs = nixpkgs.legacyPackages.${system};
in {
@@ -60,5 +60,15 @@
})
];
};
+
+ darwinModules.stylix = { pkgs, ... }@args: {
+ imports = [
+ (import ./stylix/darwin {
+ inherit (self.package.${pkgs.system}) palette-generator;
+ base16 = base16.lib args;
+ homeManagerModule = self.homeManagerModules.stylix;
+ })
+ ];
+ };
};
}
diff --git a/stylix/darwin/default.nix b/stylix/darwin/default.nix
new file mode 100644
index 00000000..2767559f
--- /dev/null
+++ b/stylix/darwin/default.nix
@@ -0,0 +1,46 @@
+{ palette-generator, base16, homeManagerModule }:
+{ options, config, lib, ... }:
+
+let
+ hm = config.stylix.homeManagerIntegration;
+ autoload = import ../autoload.nix { inherit lib; } "darwin";
+in {
+ imports = [
+ ../pixel.nix
+ ../target.nix
+ ./fonts.nix
+ (import ./palette.nix { inherit palette-generator base16; })
+ ] ++ 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.literalDocBook ''
+ true when Home Manager is present.
+ '';
+ };
+ };
+
+ config = lib.mkIf hm.autoImport {
+ home-manager.sharedModules = [ homeManagerModule ];
+ };
+}
diff --git a/stylix/darwin/fonts.nix b/stylix/darwin/fonts.nix
new file mode 100644
index 00000000..6a1a6532
--- /dev/null
+++ b/stylix/darwin/fonts.nix
@@ -0,0 +1,17 @@
+{ config, ... }:
+
+let
+ cfg = config.stylix.fonts;
+in {
+ imports = [ ../fonts.nix ];
+ config.fonts = {
+ fontDir.enable = true;
+
+ fonts = [
+ cfg.monospace.package
+ cfg.serif.package
+ cfg.sansSerif.package
+ cfg.emoji.package
+ ];
+ };
+}
diff --git a/stylix/darwin/palette.nix b/stylix/darwin/palette.nix
new file mode 100644
index 00000000..4694696b
--- /dev/null
+++ b/stylix/darwin/palette.nix
@@ -0,0 +1,34 @@
+args:
+{ config, ... }:
+
+{
+ imports = [ (import ../palette.nix args) ];
+
+ config = {
+ environment.etc = {
+ # Making palette.json part of the system closure will protect it from
+ # 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.
+ # The extra indirection should prevent the palette generator from running
+ # when the theme is manually specified. generated.json is necessary in
+ # the presence of overrides.
+ "stylix/generated.json".source = config.lib.stylix.scheme {
+ template = builtins.readFile ../palette.json.mustache;
+ extension = ".json";
+ };
+
+ "stylix/palette.json".source = config.lib.stylix.colors {
+ template = builtins.readFile ../palette.json.mustache;
+ extension = ".json";
+ };
+
+ # We also provide a HTML version which is useful for viewing the colors
+ # during development.
+ "stylix/palette.html".source = config.lib.stylix.colors {
+ template = builtins.readFile ../palette.html.mustache;
+ extension = ".html";
+ };
+ };
+ };
+}