-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: feat(flake): Add home-manager module
- Loading branch information
Showing
2 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
self: { | ||
config, | ||
lib, | ||
pkgs, | ||
... | ||
}: let | ||
inherit (pkgs.stdenv.hostPlatform) system; | ||
cfg = config.services.timewall; | ||
package = self.packages.${system}.default; | ||
configFormat = pkgs.formats.toml {}; | ||
in { | ||
options = { | ||
services.timewall = { | ||
enable = lib.mkEnableOption "timewall"; | ||
}; | ||
|
||
package = lib.mkPackageOption self.packages.${system} "timewall" { | ||
default = "default"; | ||
pkgsText = "timewall.packages.\${pkgs.system}"; | ||
}; | ||
|
||
systemdTarget = lib.mkOption { | ||
type = lib.types.str; | ||
default = "graphical-session.target"; | ||
description = "Systemd target to bind to."; | ||
}; | ||
|
||
wallpaperPath = lib.mkOption { | ||
type = with lib.types; nullOr path; | ||
default = null; | ||
description = "Path to the HEIF/HEIC dyncamic wallpaper file to set."; | ||
}; | ||
|
||
config = { | ||
location = { | ||
lat = lib.mkOption { | ||
type = with lib.types; nullOr (either float int); | ||
default = null; | ||
description = "Your geographical latitude."; | ||
}; | ||
lon = lib.mkOption { | ||
type = with lib.types; nullOr (either float int); | ||
default = null; | ||
description = "You geographical longitude."; | ||
}; | ||
}; | ||
|
||
setter = { | ||
command = lib.mkOption { | ||
type = with lib.types; nullOr listOf str; | ||
default = null; | ||
description = '' | ||
Command to set the wallpaper. Use "%f" as a placeholder for the file path. | ||
The command is NOT passed to a shell. | ||
''; | ||
example = ["sww" "img" "%f"]; | ||
}; | ||
}; | ||
|
||
daemon = { | ||
update_interval_seconds = lib.mkOption { | ||
type = with lib.types; nullOr int; | ||
default = null; | ||
description = "Interval between wallpaper updates in seconds."; | ||
}; | ||
}; | ||
}; | ||
}; | ||
|
||
config = lib.mkIf cfg.enable { | ||
assertions = [ | ||
{ | ||
assertion = (cfg.config.location.lat != null) == (cfg.config.location.lon != null); | ||
message = "Both `latitude and `longitude` must be set for timewall"; | ||
} | ||
]; | ||
|
||
home.packages = [cfg.package]; | ||
|
||
xdg.configFile."timewall/config.toml".source = configFormat.generate "config.toml" ( | ||
lib.optionalAttrs (cfg.config.location.lat != null && cfg.config.location.lon != null) { | ||
inherit (cfg.config) location; | ||
} | ||
// lib.optionalAttrs (cfg.config.setter.command != null) { | ||
inherit (cfg.config) setter; | ||
} | ||
// lib.optionalAttrs (cfg.config.daemon.update_interval_seconds != null) { | ||
inherit (cfg.config) daemon; | ||
} | ||
); | ||
|
||
systemd.user.services.timewall = { | ||
Unit = { | ||
Description = "Dynamic wallpapers daemon"; | ||
PartOf = ["graphical-session.target"]; | ||
X-Restart-Triggers = | ||
lib.mkIf (cfg.config != {}) | ||
["${config.xdg.configFile."timewall/config.toml".source}"]; | ||
}; | ||
Service.ExecStart = builtins.concatStringsSep " " [ | ||
"${lib.getExe package} set --daemon" | ||
(lib.optionalString cfg.wallpaperPath) | ||
]; | ||
Install.WantedBy = [cfg.systemdTarget]; | ||
}; | ||
}; | ||
} |