Jump to content

Swaylock: Difference between revisions

From NixOS Wiki
34j (talk | contribs)
Configuration: Add Adding Background
34j (talk | contribs)
 
Line 33: Line 33:
=== Adding background ===
=== Adding background ===


You can add background declaratively using {{Nixpkgs Manual|name=fetchurl|anchor=#sec-pkgs-fetchers-fetchurl}} similar to [[Wallpapers for Wayland]]. In this example, a wallpaper in [https://github.com/NixOS/nixos-artwork/tree/master/wallpapers nixos-artwork] is used.
You can add background declaratively using {{Nixpkgs Manual|name=fetchurl|anchor=#sec-pkgs-fetchers-fetchurl}} similar to [[Wallpapers for Wayland]]. In this example, a wallpaper in [https://github.com/NixOS/nixos-artwork/tree/master/wallpapers nixos-artwork] is set to {{ic|image}} attribute and the remaining configuration from {{ic|./swaylock}} are merged.


{{file|~/.config/home-manager/home.nix|nix|3=
{{file|~/.config/home-manager/home.nix|nix|3=

Latest revision as of 03:06, 5 July 2025

swaylock is a screen locking utility for Wayland compositors.

Installation

Install via Home Manager:

❄︎ ~/.config/home-manager/home.nix
programs.swaylock.enable = true;

The following settings may be required.

❄︎ /etc/nixos/configuration.nix
security.pam.services.swaylock = {};

Configuration

swaylock can be configured using Home Manager:

❄︎ ~/.config/home-manager/home.nix
programs.swaylock.settings = { color = "808080"; };

Alternatively, you may write configuration without using Nix language:

❄︎ ~/.config/home-manager/home.nix
xdg.configFile."swaylock/config".source = ./swaylock-theme;

You may find "Swaylock theme"s shared on the web.

Adding background

You can add background declaratively using fetchurl similar to Wallpapers for Wayland. In this example, a wallpaper in nixos-artwork is set to image attribute and the remaining configuration from ./swaylock are merged.

❄︎ ~/.config/home-manager/home.nix
xdg.configFile."swaylock/config".text =
  let
    src = pkgs.fetchurl {
      url = "https://raw.githubusercontent.com/NixOS/nixos-artwork/8957e93c95867faafec7f9988cedddd6837859fa/wallpapers/nix-wallpaper-binary-black.png";
      sha256 = "0v3111a1ihsh4ajijbjh6y7a8p5cb5g3rdxqjbzx37pn1k9s254s";
    };
  in
  ''
    image=${src}
  ''
  + builtins.readFile ./swaylock;

Forks

swaylock-effects allows built-in screenshots and image manipulation effects like blurring.

❄︎ ~/.config/home-manager/home.nix
programs.swaylock.package = pkgs.swaylock-effects;