Skip to content

Commit

Permalink
Add daily wallpaper module for macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
carlthome committed Jan 2, 2025
1 parent 1feb3ff commit 24bcc26
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
6 changes: 6 additions & 0 deletions hosts/mba/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,11 @@
max-free = ${toString (1024 * 1024 * 1024)}
'';

services.wallpaper = {
enable = true;
interval = "daily";
category = "nature";
};

system.stateVersion = 5;
}
1 change: 1 addition & 0 deletions hosts/mba/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ nix-darwin.lib.darwinSystem {
({ lib, ... }: { nix.settings.auto-optimise-store = lib.mkForce false; }) # TODO https://github.com/NixOS/nix/issues/7273
self.darwinModules.auto-upgrade
self.darwinModules.default
self.darwinModules.wallpaper
self.modules.default
];
}
1 change: 1 addition & 0 deletions modules/nix-darwin/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{ ... }: {
auto-upgrade = import ./auto-upgrade.nix;
wallpaper = import ./wallpaper.nix;
default = import ./configuration.nix;
}
48 changes: 48 additions & 0 deletions modules/nix-darwin/wallpaper.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{ config, lib, pkgs, ... }:

with lib;

{
options.services.wallpaper = {
enable = mkEnableOption "Automatic wallpaper changing service";

interval = mkOption {
type = types.str;
default = "daily";
description = "How often to change the wallpaper (daily, hourly)";
};

category = mkOption {
type = types.str;
default = "nature";
description = "Category of images to fetch from Unsplash";
};
};

config = mkIf config.services.wallpaper.enable {
environment.systemPackages = with pkgs; [
darwin.apple_sdk.frameworks.CoreServices
];

launchd.agents.change-wallpaper = {
serviceConfig = {
ProgramArguments = [
"/bin/sh"
"-c"
''
WALLPAPER_URL="https://source.unsplash.com/random/3840x2160/?${config.services.wallpaper.category}"
WALLPAPER_PATH="/tmp/wallpaper.jpg"
curl -L "$WALLPAPER_URL" -o "$WALLPAPER_PATH"
osascript -e "tell application \"Finder\" to set desktop picture to POSIX file \"$WALLPAPER_PATH\""
''
];
StartCalendarInterval = (if config.services.wallpaper.interval == "hourly"
then [{ Minute = 0; }]
else [{ Hour = 0; Minute = 0; }]);
RunAtLoad = true;
StandardErrorPath = "/tmp/change-wallpaper.err";
StandardOutPath = "/tmp/change-wallpaper.out";
};
};
};
}

0 comments on commit 24bcc26

Please sign in to comment.