<commit_before>{ config, pkgs, lib, ... }:

with lib;

let
  cfg = config.programs.sway;
  sway = pkgs.sway;

  swayWrapped = pkgs.writeShellScriptBin "sway" ''
    if [ "$1" != "" ]; then
      sway-setcap "$@"
      exit
    fi
    ${cfg.extraSessionCommands}
    exec ${pkgs.dbus.dbus-launch} --exit-with-session sway-setcap
  '';
  swayJoined = pkgs.symlinkJoin {
    name = "sway-wrapped";
    paths = [ swayWrapped sway ];
  };
in
{
  options.programs.sway = {
    enable = mkEnableOption "sway";

    extraSessionCommands = mkOption {
      default     = "";
      type        = types.lines;
      example = ''
        export XKB_DEFAULT_LAYOUT=us,de
        export XKB_DEFAULT_VARIANT=,nodeadkeys
        export XKB_DEFAULT_OPTIONS=grp:alt_shift_toggle,
      '';
      description = ''
        Shell commands executed just before sway is started.
      '';
    };

    extraPackages = mkOption {
      type = with types; listOf package;
      default = with pkgs; [
        i3status xwayland rxvt_unicode dmenu
      ];
      example = literalExample ''
        with pkgs; [
          i3status xwayland rxvt_unicode dmenu
        ]
      '';
      description = ''
        Extra packages to be installed system wide.
      '';
    };
  };

  config = mkIf cfg.enable {
    environment.systemPackages = [ swayJoined ] ++ cfg.extraPackages;
    security.wrappers.sway = {
      program = "sway-setcap";
      source = "${sway}/bin/sway";
      capabilities = "cap_sys_ptrace,cap_sys_tty_config=eip";
      owner = "root";
      group = "sway";
      permissions = "u+rx,g+rx";
    };

    users.extraGroups.sway = {};
    security.pam.services.swaylock = {};

    hardware.opengl.enable = mkDefault true;
    fonts.enableDefaultFonts = mkDefault true;
    programs.dconf.enable = mkDefault true;
  };
}<commit_msg>nixos/sway: Extend the descriptions and examples<commit_after>{ config, pkgs, lib, ... }:

with lib;

let
  cfg = config.programs.sway;
  swayPackage = pkgs.sway;

  swayWrapped = pkgs.writeShellScriptBin "sway" ''
    if [[ "$#" -ge 1 ]]; then
      exec sway-setcap "$@"
    else
      ${cfg.extraSessionCommands}
      exec ${pkgs.dbus.dbus-launch} --exit-with-session sway-setcap
    fi
  '';
  swayJoined = pkgs.symlinkJoin {
    name = "sway-joined";
    paths = [ swayWrapped swayPackage ];
  };
in {
  options.programs.sway = {
    enable = mkEnableOption ''
      the tiling Wayland compositor Sway. After adding yourself to the "sway"
      group you can manually launch Sway by executing "sway" from a terminal.
      If you call "sway" with any parameters the extraSessionCommands won't be
      executed and Sway won't be launched with dbus-launch'';

    extraSessionCommands = mkOption {
      type = types.lines;
      default = "";
      example = ''
        # Define a keymap (US QWERTY is the default)
        export XKB_DEFAULT_LAYOUT=de,us
        export XKB_DEFAULT_VARIANT=nodeadkeys
        export XKB_DEFAULT_OPTIONS=grp:alt_shift_toggle,caps:escape
        # Change the Keyboard repeat delay and rate
        export WLC_REPEAT_DELAY=660
        export WLC_REPEAT_RATE=25
      '';
      description = ''
        Shell commands executed just before Sway is started.
      '';
    };

    extraPackages = mkOption {
      type = with types; listOf package;
      default = with pkgs; [
        i3status xwayland rxvt_unicode dmenu
      ];
      defaultText = literalExample ''
        with pkgs; [ i3status xwayland rxvt_unicode dmenu ];
      '';
      example = literalExample ''
        with pkgs; [
          i3lock light termite
        ]
      '';
      description = ''
        Extra packages to be installed system wide.
      '';
    };
  };

  config = mkIf cfg.enable {
    environment.systemPackages = [ swayJoined ] ++ cfg.extraPackages;
    security.wrappers.sway = {
      program = "sway-setcap";
      source = "${swayPackage}/bin/sway";
      capabilities = "cap_sys_ptrace,cap_sys_tty_config=eip";
      owner = "root";
      group = "sway";
      permissions = "u+rx,g+rx";
    };

    users.extraGroups.sway = {};
    security.pam.services.swaylock = {};

    hardware.opengl.enable = mkDefault true;
    fonts.enableDefaultFonts = mkDefault true;
    programs.dconf.enable = mkDefault true;
  };

  meta.maintainers = with lib.maintainers; [ gnidorah primeos ];
}
{'fraction_non_alphanumeric': 0.11129069498960979, 'fraction_numerical': 0.002770722696836758, 'mean_word_length': 2.424505928853755, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1859212', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1399, 'n_words': 315}