diff --git a/modules/programs/swaylock.nix b/modules/programs/swaylock.nix
index 187ff9d6..cb68d976 100644
--- a/modules/programs/swaylock.nix
+++ b/modules/programs/swaylock.nix
@@ -1,32 +1,54 @@
-{ config, lib, ... }:
+{ pkgs, config, lib, ... }:
+
+with lib;
let cfg = config.programs.swaylock;
in {
- meta.maintainers = [ lib.hm.maintainers.rcerc ];
+ meta.maintainers = [ 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;
+ options.programs.swaylock = {
+ enable = mkOption {
+ type = lib.types.bool;
+ default = versionOlder config.home.stateVersion "23.05"
+ && (cfg.settings != { });
+ defaultText = literalExpression ''
+ true if state version < 23.05 and settings ≠ { },
+ false otherwise
+ '';
+ example = true;
+ description = "Whether to enable swaylock.";
+ };
+
+ package = mkPackageOption pkgs "swaylock" { };
+
+ settings = mkOption {
+ type = with 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);
+ config = mkIf cfg.enable {
+ home.packages = [ cfg.package ];
+
+ xdg.configFile."swaylock/config" = mkIf (cfg.settings != { }) {
+ text = concatStrings (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/modules/programs/swaylock/default.nix b/tests/modules/programs/swaylock/default.nix
index a8a33fd6..65434be2 100644
--- a/tests/modules/programs/swaylock/default.nix
+++ b/tests/modules/programs/swaylock/default.nix
@@ -1,4 +1,6 @@
{
swaylock-disabled = import ./disabled.nix;
swaylock-settings = import ./settings.nix;
+ swaylock-enabled = import ./enabled.nix;
+ swaylock-legacy = import ./legacy.nix;
}
diff --git a/tests/modules/programs/swaylock/enabled.nix b/tests/modules/programs/swaylock/enabled.nix
new file mode 100644
index 00000000..27bea281
--- /dev/null
+++ b/tests/modules/programs/swaylock/enabled.nix
@@ -0,0 +1,10 @@
+{ config, ... }: {
+ programs.swaylock = {
+ enable = true;
+ package = config.lib.test.mkStubPackage { };
+ };
+
+ nmt.script = ''
+ assertPathNotExists home-files/.config/swaylock/config
+ '';
+}
diff --git a/tests/modules/programs/swaylock/legacy.nix b/tests/modules/programs/swaylock/legacy.nix
new file mode 100644
index 00000000..daee2aa0
--- /dev/null
+++ b/tests/modules/programs/swaylock/legacy.nix
@@ -0,0 +1,19 @@
+{
+ home.stateVersion = "20.09";
+ 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}
+ '';
+}
diff --git a/tests/modules/programs/swaylock/settings.nix b/tests/modules/programs/swaylock/settings.nix
index 9ad46ba5..3dd9c68d 100644
--- a/tests/modules/programs/swaylock/settings.nix
+++ b/tests/modules/programs/swaylock/settings.nix
@@ -1,11 +1,14 @@
-{ ... }: {
- 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;
+{
+ programs.swaylock = {
+ enable = true;
+ 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";