Skip to content

Commit

Permalink
WIP: feat(flake): Add home-manager module
Browse files Browse the repository at this point in the history
  • Loading branch information
bcyran committed Dec 18, 2024
1 parent b655e22 commit 58e0bb7
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
5 changes: 5 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@
timewall = pkgs.callPackage ./nix/package.nix {inherit rev;};
default = timewall;
});

homeManagerModules = rec {
timewall = import ./nix/hm-module.nix self;
default = timewall;
};
};
}
114 changes: 114 additions & 0 deletions nix/hm-module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
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"
(
if cfg.wallpaperPath != null
then builtins.toString cfg.wallpaperPath
else ""
)
];
Restat = "on-failure";
};
Install.WantedBy = [cfg.systemdTarget];
};
};
}

0 comments on commit 58e0bb7

Please sign in to comment.