This commit is contained in:
mjallen18
2025-08-22 21:11:13 -05:00
parent 999fbbf022
commit d6e7be7db1
12 changed files with 307 additions and 294 deletions

View File

@@ -8,18 +8,89 @@
let
cfg = config.${namespace}.desktop.hyprland;
# Create a persistent directory for wallpapers
wallpaperDir = "/var/lib/wallpapers";
# Default fallback wallpaper (included in the system)
defaultWallpaper = pkgs.runCommand "default-wallpaper" {} ''
mkdir -p $out
cp ${pkgs.nixos-artwork.wallpapers.nineish-dark-gray}/share/backgrounds/nixos/nix-wallpaper-nineish-dark-gray.png $out/default.jpg
'';
bing-wallpaper = pkgs.writeScriptBin "bing-wallpaper" ''
# Directory to store wallpapers
IMG_PATH="/run/wallpaper.jpg"
WALLPAPER_DIR="${wallpaperDir}"
IMG_PATH="$WALLPAPER_DIR/current.jpg"
FALLBACK_PATH="$WALLPAPER_DIR/fallback.jpg"
# Ensure directory exists
mkdir -p "$WALLPAPER_DIR"
# Copy to the standard location for other services
ln -sf "$IMG_PATH" /run/wallpaper.jpg
# Download if not already downloaded
URL=$(curl -s "https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1" | \
jq -r '.images[0].url')
FULL_URL="https://www.bing.com$URL"
curl -s -o "$IMG_PATH" "$FULL_URL"
echo "Downloaded $FULL_URL to $IMG_PATH successfully"
# Try to download new wallpaper
if curl -s --connect-timeout 5 --max-time 10 "https://www.bing.com" > /dev/null; then
URL=$(curl -s "https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1" | \
jq -r '.images[0].url')
FULL_URL="https://www.bing.com$URL"
if curl -s -o "$IMG_PATH.tmp" "$FULL_URL"; then
mv "$IMG_PATH.tmp" "$IMG_PATH"
echo "Downloaded $FULL_URL to $IMG_PATH successfully"
else
echo "Failed to download Bing wallpaper, using previous or fallback"
# If current doesn't exist, use fallback
if [ ! -f "$IMG_PATH" ] && [ -f "$FALLBACK_PATH" ]; then
cp "$FALLBACK_PATH" "$IMG_PATH"
fi
fi
else
echo "Network unavailable, using previous or fallback wallpaper"
# If current doesn't exist, use fallback
if [ ! -f "$IMG_PATH" ] && [ -f "$FALLBACK_PATH" ]; then
cp "$FALLBACK_PATH" "$IMG_PATH"
fi
fi
'';
nasa-wallpaper = pkgs.writeScriptBin "nasa-wallpaper" ''
# Directory to store wallpapers
WALLPAPER_DIR="${wallpaperDir}"
IMG_PATH="$WALLPAPER_DIR/current.jpg"
FALLBACK_PATH="$WALLPAPER_DIR/fallback.jpg"
# Ensure directory exists
mkdir -p "$WALLPAPER_DIR"
# Copy to the standard location for other services
ln -sf "$IMG_PATH" /run/wallpaper.jpg
# Try to download new wallpaper
if curl -s --connect-timeout 5 --max-time 10 "https://api.nasa.gov" > /dev/null; then
APOD_URL="https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY"
IMAGE_URL=$(curl -s "$APOD_URL" | jq -r '.hdurl // .url')
if curl -s -o "$IMG_PATH.tmp" "$IMAGE_URL"; then
mv "$IMG_PATH.tmp" "$IMG_PATH"
echo "Downloaded $IMAGE_URL to $IMG_PATH successfully"
else
echo "Failed to download NASA wallpaper, using previous or fallback"
# If current doesn't exist, use fallback
if [ ! -f "$IMG_PATH" ] && [ -f "$FALLBACK_PATH" ]; then
cp "$FALLBACK_PATH" "$IMG_PATH"
fi
fi
else
echo "Network unavailable, using previous or fallback wallpaper"
# If current doesn't exist, use fallback
if [ ! -f "$IMG_PATH" ] && [ -f "$FALLBACK_PATH" ]; then
cp "$FALLBACK_PATH" "$IMG_PATH"
fi
fi
'';
# Select the appropriate wallpaper script based on the configuration
wallpaper-script = if cfg.wallpaperSource == "nasa" then nasa-wallpaper else bing-wallpaper;
sddmThemeName = "sddm-astronaut-theme";
sddmThemePkg = pkgs.sddm-astronaut.override {
embeddedTheme = "astronaut";
@@ -27,15 +98,53 @@ let
Background = "/run/wallpaper.jpg";
};
};
# The script to use based on the selected wallpaper source
wallpaper-command = if cfg.wallpaperSource == "nasa" then "nasa-wallpaper" else "bing-wallpaper";
# System activation script to ensure wallpaper is available early in boot
wallpaper-activation-script = ''
# Create wallpaper directory if it doesn't exist
mkdir -p ${wallpaperDir}
# Copy default wallpaper as fallback if it doesn't exist
if [ ! -f ${wallpaperDir}/fallback.jpg ]; then
cp ${defaultWallpaper}/default.jpg ${wallpaperDir}/fallback.jpg
fi
# If no current wallpaper exists, use the fallback
if [ ! -f ${wallpaperDir}/current.jpg ]; then
cp ${wallpaperDir}/fallback.jpg ${wallpaperDir}/current.jpg
fi
# Create symlink for Plymouth and SDDM
ln -sf ${wallpaperDir}/current.jpg /run/wallpaper.jpg
'';
in
{
imports = [ ../../../home/desktop/hyprland/options.nix ];
imports = [ ./options.nix ];
config = lib.mkIf cfg.enable {
environment.systemPackages = [
bing-wallpaper
nasa-wallpaper
pkgs.jq
];
# Add system activation script to ensure wallpaper is available early
system.activationScripts.wallpaper = wallpaper-activation-script;
# Configure Plymouth to use the same wallpaper
boot.plymouth = {
enable = true;
themePackages = [ pkgs.plymouth-theme-breeze ];
theme = "breeze";
extraConfig = ''
ShowDelay=0
DeviceTimeout=5
DeviceScale=1
'';
};
services = {
displayManager = {
@@ -63,9 +172,7 @@ in
};
dbus.enable = true;
ddccontrol.enable = false;
blueman.enable = true;
};
@@ -81,7 +188,7 @@ in
systemd = {
services = {
preload-bing-wallpaper = {
preload-wallpaper = {
enable = true;
wants = [ "network-online.target" ];
after = [ "network-online.target" ];
@@ -96,18 +203,44 @@ in
pkgs.jq
pkgs.curl
bing-wallpaper
nasa-wallpaper
];
script = ''
bing-wallpaper
${wallpaper-command}
'';
serviceConfig = {
Type = "oneshot";
TimeoutSec = "10s"; # Limit how long we wait for network
};
};
# Create a service that runs very early in boot to ensure wallpaper is available
early-wallpaper-setup = {
enable = true;
description = "Setup wallpaper early in boot process";
wantedBy = [ "multi-user.target" "plymouth-start.service" ];
before = [ "plymouth-start.service" ];
script = ''
# Ensure wallpaper directory exists
mkdir -p ${wallpaperDir}
# If no current wallpaper exists, use the fallback
if [ ! -f ${wallpaperDir}/current.jpg ]; then
cp ${wallpaperDir}/fallback.jpg ${wallpaperDir}/current.jpg
fi
# Create symlink for Plymouth and SDDM
ln -sf ${wallpaperDir}/current.jpg /run/wallpaper.jpg
'';
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
};
};
user = {
services = {
reload-bing-wallpaper = {
reload-wallpaper = {
enable = true;
path = [
pkgs.bash
@@ -115,9 +248,10 @@ in
pkgs.curl
pkgs.hyprland
bing-wallpaper
nasa-wallpaper
];
script = ''
bing-wallpaper
${wallpaper-command}
${pkgs.hyprland}/bin/hyprctl hyprpaper reload ,/run/wallpaper.jpg
'';
serviceConfig = {
@@ -127,15 +261,15 @@ in
};
# Create a timer to run the service periodically
timers = {
reload-bing-wallpaper = {
description = "Timer for reload-bing-wallpaper";
reload-wallpaper = {
description = "Timer for reload-wallpaper";
wantedBy = [ "timers.target" ];
# Timer configuration
timerConfig = {
OnCalendar = "daily"; # Check every day
Persistent = true; # Run immediately if last run was missed
Unit = "reload-bing-wallpaper.service";
Unit = "reload-wallpaper.service";
};
};
};

View File

@@ -0,0 +1,13 @@
{ lib, ... }:
with lib;
{
options.mjallen.desktop.hyprland = {
enable = mkEnableOption "enable hyprland desktop environment";
wallpaperSource = mkOption {
type = types.enum [ "bing" "nasa" ];
default = "bing";
description = "Source for the wallpaper (bing or nasa)";
};
};
}