doc: format and polish Nix code according to our formatter (#1025)

Link: https://github.com/danth/stylix/pull/1025

Reviewed-by: Daniel Thwaites <danth@danth.me>
This commit is contained in:
NAHO 2025-03-26 14:58:03 +01:00 committed by GitHub
parent 61a5f77f22
commit daef51e920
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 100 additions and 58 deletions

View file

@ -206,16 +206,19 @@ extension of it.
For example:
```nix
{ inputs, config, pkgs, ... }:
{
inputs,
config,
pkgs,
...
}:
let
inherit (pkgs.stdenv.hostPlatform) system;
nixvim-package = inputs.nixvim-config.packages.${system}.default;
extended-nixvim = nixvim-package.extend config.lib.stylix.nixvim.config;
in
{
environment.systemPackages = [
extended-nixvim
];
environment.systemPackages = [ extended-nixvim ];
}
```

View file

@ -13,12 +13,17 @@ screens, and display managers.
stylix.url = "github:danth/stylix";
};
outputs = { nixpkgs, stylix, ... }: {
nixosConfigurations."«hostname»" = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [ stylix.nixosModules.stylix ./configuration.nix ];
outputs =
{ nixpkgs, stylix, ... }:
{
nixosConfigurations."«hostname»" = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
stylix.nixosModules.stylix
./configuration.nix
];
};
};
};
}
```
<small>Minimal `flake.nix` for a NixOS configuration.</small>
@ -64,12 +69,21 @@ to NixOS via [Flakes][nix-flakes].
stylix.url = "github:danth/stylix";
};
outputs = { darwin, nixpkgs, stylix, ... }: {
darwinConfigurations."«hostname»" = darwin.lib.darwinSystem {
system = "aarch64-darwin";
modules = [ stylix.darwinModules.stylix ./configuration.nix ];
outputs =
{
darwin,
stylix,
...
}:
{
darwinConfigurations."«hostname»" = darwin.lib.darwinSystem {
system = "aarch64-darwin";
modules = [
stylix.darwinModules.stylix
./configuration.nix
];
};
};
};
}
```
<small>Minimal `flake.nix` for a nix-darwin configuration.</small>
@ -95,12 +109,22 @@ a similar fashion to NixOS via [Flakes][nix-flakes].
stylix.url = "github:danth/stylix";
};
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 ];
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
];
};
};
};
}
```
<small>Minimal `flake.nix` for a Nix-on-Droid configuration.</small>
@ -127,12 +151,22 @@ is managed by someone else.
stylix.url = "github:danth/stylix";
};
outputs = { nixpkgs, home-manager, stylix, ... }: {
homeConfigurations."«username»" = home-manager.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages.x86_64-linux;
modules = [ stylix.homeManagerModules.stylix ./home.nix ];
outputs =
{
nixpkgs,
home-manager,
stylix,
...
}:
{
homeConfigurations."«username»" = home-manager.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages.x86_64-linux;
modules = [
stylix.homeManagerModules.stylix
./home.nix
];
};
};
};
}
```
<small>Minimal `flake.nix` for a Home Manager configuration.</small>
@ -164,20 +198,20 @@ module as the `homeManagerModules.stylix` attribute.
```nix
let
stylix = pkgs.fetchFromGitHub {
owner = "danth";
repo = "stylix";
rev = "...";
sha256 = "...";
owner = "danth";
repo = "stylix";
rev = "...";
sha256 = "...";
};
in {
imports = [ (import stylix).homeManagerModules.stylix ];
in
{
imports = [ (import stylix).homeManagerModules.stylix ];
stylix = {
enable = true;
image = ./wallpaper.jpg;
};
stylix = {
enable = true;
image = ./wallpaper.jpg;
};
}
```
<small>Example usage of the Home Manager module without flakes.</small>

View file

@ -46,14 +46,15 @@ A general format for modules is shown below.
```nix
{ config, lib, ... }:
{
options.stylix.targets.«name».enable =
config.lib.stylix.mkEnableTarget "«human readable name»" true;
config = lib.mkIf (config.stylix.enable && config.stylix.targets.«name».enable) {
programs.«name».backgroundColor = config.lib.stylix.colors.base00;
};
config =
lib.mkIf (config.stylix.enable && config.stylix.targets.«name».enable)
{
programs.«name».backgroundColor = config.lib.stylix.colors.base00;
};
}
```
@ -94,11 +95,13 @@ it as a function. This returns a derivation which builds the template.
```nix
{
environment.variables.MY_APPLICATION_CONFIG_FILE =
let configFile = config.lib.stylix.colors {
template = ./config.toml.mustache;
extension = ".toml";
};
in "${configFile}";
let
configFile = config.lib.stylix.colors {
template = ./config.toml.mustache;
extension = ".toml";
};
in
"${configFile}";
}
```

View file

@ -6,9 +6,11 @@ If you combined Home Manager with your NixOS configuration, write these
options within a Home Manager section, either for all users:
```nix
home-manager.sharedModules = [{
stylix.targets.xyz.enable = false;
}];
home-manager.sharedModules = [
{
stylix.targets.xyz.enable = false;
}
];
```
Or for a specific user:

View file

@ -27,9 +27,11 @@ Home Manager module within the NixOS module using the following format:
```nix
{
home-manager.sharedModules = [{
# Write Home Manager options here
}];
home-manager.sharedModules = [
{
# Write Home Manager options here
}
];
}
```

View file

@ -8,12 +8,11 @@ Here's an example Nix expression that takes an input image, applies a brightness
```nix
{ pkgs, ... }:
let
inputImage = ./path/to/image.jpg;
brightness = -30;
contrast = 0;
fillColor = "black"
fillColor = "black";
in
{
stylix.image = pkgs.runCommand "dimmed-background.png" { } ''
@ -29,14 +28,14 @@ Similarly, you can use a template image and repaint it for the current theme.
```nix
{ pkgs, ... }:
let
theme = "${pkgs.base16-schemes}/share/themes/catppuccin-latte.yaml";
wallpaper = pkgs.runCommand "image.png" {} ''
COLOR=$(${pkgs.yq}/bin/yq -r .palette.base00 ${theme})
${pkgs.imagemagick}/bin/magick -size 1920x1080 xc:$COLOR $out
wallpaper = pkgs.runCommand "image.png" { } ''
COLOR=$(${pkgs.yq}/bin/yq -r .palette.base00 ${theme})
${pkgs.imagemagick}/bin/magick -size 1920x1080 xc:$COLOR $out
'';
in {
in
{
stylix = {
image = wallpaper;
base16Scheme = theme;
@ -48,7 +47,6 @@ Which is neatly implemented as a single function in `lib.stylix.pixel`:
```nix
{ pkgs, config, ... }:
{
stylix = {
image = config.lib.stylix.pixel "base0A";