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 15, 2024
1 parent b99977a commit d0a1637
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
6 changes: 6 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
};

outputs = {
self,
nixpkgs,
rust-overlay,
...
Expand Down Expand Up @@ -40,5 +41,10 @@
timewall = pkgs.callPackage ./package.nix {};
default = timewall;
});

homeManagerModules = rec {
timewall = import ./hm-module.nix self;
default = timewall;
};
};
}
107 changes: 107 additions & 0 deletions hm-module.nix
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];
};
};
}

0 comments on commit d0a1637

Please sign in to comment.