From 70824bb5c790b820b189f62f643f795b1d2ade2e Mon Sep 17 00:00:00 2001 From: rcerc <88944439+rcerc@users.noreply.github.com> Date: Tue, 7 Jun 2022 15:01:14 -0400 Subject: [PATCH] swaylock: Add module (#3003) --- .github/CODEOWNERS | 3 ++ modules/lib/maintainers.nix | 10 ++++++ modules/modules.nix | 1 + modules/programs/swaylock.nix | 32 ++++++++++++++++++++ tests/default.nix | 1 + tests/modules/programs/swaylock/config | 5 +++ tests/modules/programs/swaylock/default.nix | 4 +++ tests/modules/programs/swaylock/disabled.nix | 7 +++++ tests/modules/programs/swaylock/settings.nix | 16 ++++++++++ 9 files changed, 79 insertions(+) create mode 100644 modules/programs/swaylock.nix create mode 100644 tests/modules/programs/swaylock/config create mode 100644 tests/modules/programs/swaylock/default.nix create mode 100644 tests/modules/programs/swaylock/disabled.nix create mode 100644 tests/modules/programs/swaylock/settings.nix diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 9a2ee5931..463671241 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -247,6 +247,9 @@ /modules/programs/starship.nix @marsam +/modules/programs/swaylock.nix @rcerc +/tests/modules/programs/swaylock @rcerc + /modules/programs/tealdeer.nix @marsam /modules/programs/terminator.nix @chisui diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index a485d6cdd..17fc44076 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -271,4 +271,14 @@ github = "rszamszur"; githubId = 10353018; }; + rcerc = { + name = "rcerc"; + email = "88944439+rcerc@users.noreply.github.com"; + github = "rcerc"; + githubId = 88944439; + keys = [{ + longkeyid = "ed25519/0x3F98EC7EC2B87ED1"; + fingerprint = "D5D6 FD1F 0D9A 3284 FB9B C26D 3F98 EC7E C2B8 7ED1"; + }]; + }; } diff --git a/modules/modules.nix b/modules/modules.nix index 22eedc5a9..99b1b756a 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -150,6 +150,7 @@ let ./programs/sqls.nix ./programs/ssh.nix ./programs/starship.nix + ./programs/swaylock.nix ./programs/taskwarrior.nix ./programs/tealdeer.nix ./programs/terminator.nix diff --git a/modules/programs/swaylock.nix b/modules/programs/swaylock.nix new file mode 100644 index 000000000..187ff9d61 --- /dev/null +++ b/modules/programs/swaylock.nix @@ -0,0 +1,32 @@ +{ config, lib, ... }: + +let cfg = config.programs.swaylock; +in { + meta.maintainers = [ lib.hm.maintainers.rcerc ]; + + options.programs.swaylock.settings = lib.mkOption { + type = with lib.types; attrsOf (oneOf [ bool float int str ]); + default = { }; + description = '' + Default arguments to swaylock. An empty set + disables configuration generation. + ''; + example = { + color = "808080"; + font-size = 24; + indicator-idle-visible = false; + indicator-radius = 100; + line-color = "ffffff"; + show-failed-attempts = true; + }; + }; + + config.xdg.configFile."swaylock/config" = lib.mkIf (cfg.settings != { }) { + text = lib.concatStrings (lib.mapAttrsToList (n: v: + if v == false then + "" + else + (if v == true then n else n + "=" + builtins.toString v) + "\n") + cfg.settings); + }; +} diff --git a/tests/default.nix b/tests/default.nix index 0af284ddc..ada8c40f2 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -130,6 +130,7 @@ import nmt { ./modules/programs/rbw ./modules/programs/rofi ./modules/programs/rofi-pass + ./modules/programs/swaylock ./modules/programs/terminator ./modules/programs/waybar ./modules/programs/xmobar diff --git a/tests/modules/programs/swaylock/config b/tests/modules/programs/swaylock/config new file mode 100644 index 000000000..fdda03ea0 --- /dev/null +++ b/tests/modules/programs/swaylock/config @@ -0,0 +1,5 @@ +color=808080 +font-size=24 +indicator-radius=100 +line-color=ffffff +show-failed-attempts diff --git a/tests/modules/programs/swaylock/default.nix b/tests/modules/programs/swaylock/default.nix new file mode 100644 index 000000000..a8a33fd69 --- /dev/null +++ b/tests/modules/programs/swaylock/default.nix @@ -0,0 +1,4 @@ +{ + swaylock-disabled = import ./disabled.nix; + swaylock-settings = import ./settings.nix; +} diff --git a/tests/modules/programs/swaylock/disabled.nix b/tests/modules/programs/swaylock/disabled.nix new file mode 100644 index 000000000..94dd14dc7 --- /dev/null +++ b/tests/modules/programs/swaylock/disabled.nix @@ -0,0 +1,7 @@ +{ ... }: { + programs.swaylock.settings = { }; + + nmt.script = '' + assertPathNotExists home-files/.config/swaylock/config + ''; +} diff --git a/tests/modules/programs/swaylock/settings.nix b/tests/modules/programs/swaylock/settings.nix new file mode 100644 index 000000000..9ad46ba5a --- /dev/null +++ b/tests/modules/programs/swaylock/settings.nix @@ -0,0 +1,16 @@ +{ ... }: { + programs.swaylock.settings = { + color = "808080"; + font-size = 24; + indicator-idle-visible = false; # Test that this does nothing + indicator-radius = 100; + line-color = "ffffff"; + show-failed-attempts = true; + }; + + nmt.script = let homeConfig = "home-files/.config/swaylock/config"; + in '' + assertFileExists ${homeConfig} + assertFileContent ${homeConfig} ${./config} + ''; +}