Stylix

repository·master·Indexed 25 days ago

https://github.com/nix-community/stylix

A tool for applying consistent styling and themes across various NixOS, nix-darwin, and Nix-on-Droid configurations and applications. It supports theme configuration via NixOS or Home Manager, handmade color schemes using base16, automatic palette generation from wallpapers, and system-wide font management.

Tokens
8.4K
Snippets
32
Records
46
Agent score
81%

What's inside stylix

  1. How Stylix styling concepts work

    master

    Stylix uses specific semantic terms to describe how colors should be applied to UI elements to maintain a cohesive theme:

    • Alternate: Used for elements that need to look separate but not drastically different from the main UI (e.g., section backgrounds in a settings menu). Use the alternate color for the smaller or less common element.
    • On/Off: Used for toggles or status indicators with binary states.
    • Lists and Selections: Used for selectable items (like browser tabs). The selection color identifies the active or selected item(s).
  2. Understand Home Manager inheritance from NixOS

    master

    If Home Manager is used as part of NixOS, Stylix is automatically installed for all users, inheriting the NixOS theme.

    Key Behaviors:

    • Multi-user systems: You can override settings in Home Manager to provide unique themes per user.
    • Breaking inheritance: If you change stylix.base16Scheme or stylix.override in a Home Manager configuration, it will stop inheriting those specific values from NixOS.
    • Wallpaper exception: If you change the wallpaper in Home Manager, it will stop inheriting the color scheme from NixOS, allowing the automatic palette generator to run independently.
    • Customization: Use stylix.homeManagerIntegration.autoImport and stylix.homeManagerIntegration.followSystem to control this behavior.
  3. Naming and structure for Stylix modules

    master

    Stylix uses an autoload system based on file naming conventions. Modules must follow the pattern modules/«name»/«platform».nix to be imported automatically.

    Supported platforms:

    • nixos (NixOS)
    • hm (Home Manager)
    • darwin (Nix-Darwin)
    • droid (Nix-on-Droid)

    Example: modules/avizo/hm.nix is a Home Manager module for Avizo. Other files related to the module can reside in the modules/«name» directory as long as they don't match the platform names.

  4. Enable or disable styling for specific targets

    master

    A 'target' is any application or component that can be styled (e.g., Firefox, Alacritty).

    • Automatic Enabling: By default, Stylix automatically enables styling for a target whenever that target is installed.
    • Manual Control: You can disable this automatic behavior globally by setting stylix.autoEnable = false. In this case, you must manually enable each target using stylix.targets.<target>.enable = true;.
    • NixOS vs Home Manager: Targets may differ between platforms. If a target is available in both NixOS and Home Manager, it is recommended to enable it in both.
  5. What are Stylix Testbeds?

    master
    Stylix provides a suite of virtual machines (testbeds) that allow you to test and preview themes without installing them on your live system. This is useful for previewing themes before the login screen, developing for different desktop environments, or testing pull requests without risking system stability.
  6. Understand how testbed themes are calculated

    master

    In Stylix, the total number of testbeds is determined by the product of the number of targets and the number of themes.

    Specifically, the calculation is: target × theme.

    • target: The number of files located at modules/«target»/testbeds/«target».nix.
    • theme: The number of files located at stylix/testbed/themes/«theme».nix.

    Caution: Adding new theme modules to stylix/testbed/themes/ will exponentially increase the size of the test suite. Only add themes if necessary.

  7. Install Stylix on nix-darwin

    master

    You can install Stylix into a nix-darwin configuration via Flakes by adding stylix.darwinModules.stylix to your modules.

    While Stylix will not theme macOS itself (as macOS lacks the necessary controls), it will automatically set up the Home Manager modules for you if Home Manager is present.

    {
      inputs = {
        nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
        darwin = {
          url = "github:nix-darwin/nix-darwin";
          inputs.nixpkgs.follows = "nixpkgs";
        };
        stylix = {
          url = "github:nix-community/stylix";
          inputs.nixpkgs.follows = "nixpkgs";
        };
      };
    
      outputs =
        {
          darwin,
          stylix,
          ...
        }:
        {
          darwinConfigurations."«hostname»" = darwin.lib.darwinSystem {
            system = "aarch64-darwin";
            modules = [
              stylix.darwinModules.stylix
              ./configuration.nix
            ];
          };
        };
    }
  8. Add yourself as a module maintainer

    master

    Every module requires at least one maintainer. If you are not in the Nixpkgs maintainer list, add yourself to /stylix/maintainers.nix.

    After adding yourself, you must update the generated maintainers file by running: nix run .#all-maintainers

    # Single maintainer
    { lib, ... }:
    {
      maintainers = [ lib.maintainers.danth ];
    }
    
    # Multiple maintainers
    { lib, ... }:
    {
      maintainers = with lib.maintainers; [ danth da157 noahbiewesch ];
    }
  9. Install Stylix in standalone Home Manager

    master

    If you use Home Manager as a standalone configuration (e.g., on a non-NixOS OS or a managed machine), you can install Stylix directly into your Home Manager configuration using stylix.homeModules.stylix.

    Note: If you manage NixOS and Home Manager separately (not as a NixOS module), you must manually copy your theme settings into both configurations, as they will not automatically sync.

    {
      inputs = {
        nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
        home-manager = {
          url = "github:nix-community/home-manager";
          inputs.nixpkgs.follows = "nixpkgs";
        };
        stylix = {
          url = "github:nix-community/stylix";
          inputs.nixpkgs.follows = "nixpkgs";
        };
      };
    
      outputs =
        {
          nixpkgs,
          home-manager,
          stylix,
          ...
        }:
        {
          homeConfigurations."«username»" = home-manager.lib.homeManagerConfiguration {
            pkgs = nixpkgs.legacyPackages.x86_64-linux;
            modules = [
              stylix.homeModules.stylix
              ./home.nix
            ];
          };
        };
    }
  10. Install Stylix on Nix-on-Droid

    master

    To use Stylix on Nix-on-Droid via Flakes, add stylix.nixOnDroidModules.stylix to your modules. This applies your configured color scheme and monospace font to the Nix-on-Droid terminal. If Home Manager integration for Nix-on-Droid is used, Stylix will automatically set up the Home Manager modules.

    {
      inputs = {
        nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
        nix-on-droid = {
          url = "github:nix-community/nix-on-droid";
          inputs.nixpkgs.follows = "nixpkgs";
        };
        stylix = {
          url = "github:nix-community/stylix";
          inputs.nixpkgs.follows = "nixpkgs";
        };
      };
    
      outputs =
        {
          nix-on-droid,
          nixpkgs,
          stylix,
          ...
        }:
        {
          nixOnDroidConfigurations.default = nix-on-droid.lib.nixOnDroidConfiguration {
            pkgs = nixpkgs.legacyPackages."aarch64-linux";
            modules = [
              stylix.nixOnDroidModules.stylix
              ./nix-on-droid.nix
            ];
          };
        };
    }
  11. Build and view Stylix documentation

    master

    Stylix automatically generates documentation for options. To improve quality, ensure mkOption calls include a proper type and a detailed description (Markdown is supported). For general module documentation, use the description field in modules/«module»/meta.nix.

    To build and view the documentation locally, run: nix run .#doc

    nix run .#doc