From 747ec7785076141f78ac4559a5ea82cc1b8d8446 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Wed, 4 Sep 2024 22:13:38 +0200 Subject: [PATCH] smaller wallpaper size --- modules/gnome-wallpaper.nix | 2 +- modules/wallpaper-test.nix | 22 ++++++++++++++++++++++ modules/wallpaper.nix | 19 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 modules/wallpaper-test.nix create mode 100644 modules/wallpaper.nix diff --git a/modules/gnome-wallpaper.nix b/modules/gnome-wallpaper.nix index 0e4d0c4..ac309b2 100644 --- a/modules/gnome-wallpaper.nix +++ b/modules/gnome-wallpaper.nix @@ -11,6 +11,6 @@ "picture-uri-dark" = "/home/yoda/.config/background"; }; }; - home.file.".config/background".source = "${../assets/img/wallpaper.jpg}"; + home.file.".config/background".source = "${(pkgs.callPackage ./wallpaper.nix { })}/img.jpg"; }; } diff --git a/modules/wallpaper-test.nix b/modules/wallpaper-test.nix new file mode 100644 index 0000000..555217e --- /dev/null +++ b/modules/wallpaper-test.nix @@ -0,0 +1,22 @@ +# To inspect ./wallpaper.nix, adjust the `expr` of the two tests below and then run the following command: +# nix --extra-experimental-features nix-command eval --show-trace --impure --expr 'import ./modules/wallpaper-test.nix {}' +# +# Source: https://www.tweag.io/blog/2022-09-01-unit-test-your-nix-code/ + +{ pkgs ? import {} }: +let + inherit (pkgs) lib; + inherit (lib) runTests; + math = import ./wallpaper.nix {inherit lib pkgs;}; +in + runTests { + test1 = { + expr = pkgs.lib.attrNames math; + expected = true; + }; + + test2 = { + expr = "${math.out}/img.jpg"; + expected = true; + }; + } \ No newline at end of file diff --git a/modules/wallpaper.nix b/modules/wallpaper.nix new file mode 100644 index 0000000..9cfcc07 --- /dev/null +++ b/modules/wallpaper.nix @@ -0,0 +1,19 @@ +{ pkgs, lib }: +let + # Width of our display. + max-width = "1080"; +in + pkgs.stdenv.mkDerivation rec{ + name = "yoda-wallpaper"; + src = "${../assets/img/wallpaper.jpg}"; + nativeBuildInputs = with pkgs; [ imagemagick ]; + phases = "installPhase"; + # magick limit width: https://stackoverflow.com/a/38415211/6334421 + # magick jpg options: quality, progressive, strip metadata. https://stackoverflow.com/a/7262050/6334421 + installPhase = '' + set -eu -o pipefail + mkdir -p $out + ${pkgs.imagemagick}/bin/magick $src -resize '${max-width}>' -quality 85% -interlace Plane -strip $out/img.jpg + ${pkgs.imagemagick}/bin/magick $src -resize '${max-width}>' $out/img.png + ''; + }