Jump to content

Swaylock

From NixOS Wiki

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;