From 1c71f3bde228f7b17c1aad75f2b97276daf8db42 Mon Sep 17 00:00:00 2001 From: awwpotato Date: Sat, 10 May 2025 04:07:43 -0700 Subject: [PATCH] treewide: use lib.getExe (#1241) --- docs/src/tricks.md | 10 +++++----- modules/feh/hm.nix | 2 +- modules/feh/nixos.nix | 2 +- modules/grub/nixos.nix | 4 ++-- modules/kde/hm.nix | 2 +- modules/plymouth/nixos.nix | 2 +- modules/regreet/nixos.nix | 2 +- palette-generator/default.nix | 2 ++ stylix/palette.nix | 2 +- stylix/pixel.nix | 10 +++++++--- 10 files changed, 22 insertions(+), 16 deletions(-) diff --git a/docs/src/tricks.md b/docs/src/tricks.md index cf3d3d35..86e48d12 100644 --- a/docs/src/tricks.md +++ b/docs/src/tricks.md @@ -7,7 +7,7 @@ If you want to use a background image for your desktop but find it too bright or Here's an example Nix expression that takes an input image, applies a brightness/contrast adjustment to it, and saves the result as a new image file: ```nix -{ pkgs, ... }: +{ pkgs, lib, ... }: let inputImage = ./path/to/image.jpg; brightness = -30; @@ -16,7 +16,7 @@ let in { stylix.image = pkgs.runCommand "dimmed-background.png" { } '' - ${pkgs.imagemagick}/bin/convert "${inputImage}" -brightness-contrast ${brightness},${contrast} -fill ${fillColor} $out + ${lib.getExe' pkgs.imagemagick "convert"} "${inputImage}" -brightness-contrast ${brightness},${contrast} -fill ${fillColor} $out ''; } ``` @@ -27,12 +27,12 @@ With imagemagick, you can also dynamically generate wallpapers based on the sele Similarly, you can use a template image and repaint it for the current theme. ```nix -{ pkgs, ... }: +{ pkgs, lib, ... }: let theme = "${pkgs.base16-schemes}/share/themes/catppuccin-latte.yaml"; wallpaper = pkgs.runCommand "image.png" { } '' - COLOR=$(${pkgs.yq}/bin/yq -r .palette.base00 ${theme}) - ${pkgs.imagemagick}/bin/magick -size 1920x1080 xc:$COLOR $out + COLOR=$(${lib.getExe pkgs.yq} -r .palette.base00 ${theme}) + ${lib.getExe pkgs.imagemagick} -size 1920x1080 xc:$COLOR $out ''; in { diff --git a/modules/feh/hm.nix b/modules/feh/hm.nix index 989c0779..212bad35 100644 --- a/modules/feh/hm.nix +++ b/modules/feh/hm.nix @@ -44,6 +44,6 @@ in else "--bg-max"; in - "${pkgs.feh}/bin/feh --no-fehbg ${bg-arg} ${config.stylix.image}" + "${lib.getExe pkgs.feh} --no-fehbg ${bg-arg} ${config.stylix.image}" ); } diff --git a/modules/feh/nixos.nix b/modules/feh/nixos.nix index ca527511..f826a161 100644 --- a/modules/feh/nixos.nix +++ b/modules/feh/nixos.nix @@ -37,6 +37,6 @@ in else "--bg-max"; in - "${pkgs.feh}/bin/feh --no-fehbg ${bg-arg} ${config.stylix.image}" + "${lib.getExe pkgs.feh} --no-fehbg ${bg-arg} ${config.stylix.image}" ); } diff --git a/modules/grub/nixos.nix b/modules/grub/nixos.nix index b74095f3..4d451fa0 100644 --- a/modules/grub/nixos.nix +++ b/modules/grub/nixos.nix @@ -26,7 +26,7 @@ let ) # Convert to .pf2 - ${pkgs.grub2}/bin/grub-mkfont $font --output $out --size ${toString fonts.sizes.applications} + ${lib.getExe' pkgs.grub2 "grub-mkfont"} $font --output $out --size ${toString fonts.sizes.applications} ''; image-scale = @@ -135,7 +135,7 @@ in cfg.useWallpaper # Make sure the background image is .png by asking to convert it then - "${pkgs.imagemagick}/bin/convert ${config.stylix.image} png32:$out/background.png" + "${lib.getExe' pkgs.imagemagick "convert"} ${config.stylix.image} png32:$out/background.png" else "cp ${pixel "base00"} $out/background.png" } diff --git a/modules/kde/hm.nix b/modules/kde/hm.nix index 1db6cd94..f7d6a5c9 100644 --- a/modules/kde/hm.nix +++ b/modules/kde/hm.nix @@ -228,7 +228,7 @@ let write_text "$lookAndFeelDefaults" "$look_and_feel/contents/defaults" '' '' - PATH="${pkgs.imagemagick}/bin:$PATH" + PATH="${lib.getBin pkgs.imagemagick}/bin:$PATH" mkdir --parents "$wallpaper/contents/images" diff --git a/modules/plymouth/nixos.nix b/modules/plymouth/nixos.nix index c2bed116..5fd29d40 100644 --- a/modules/plymouth/nixos.nix +++ b/modules/plymouth/nixos.nix @@ -14,7 +14,7 @@ let themeDir="$out/share/plymouth/themes/stylix" mkdir -p $themeDir - ${pkgs.imagemagick}/bin/convert \ + ${lib.getExe' pkgs.imagemagick "convert"} \ -background transparent \ -bordercolor transparent \ ${ diff --git a/modules/regreet/nixos.nix b/modules/regreet/nixos.nix index 56e0e6fd..bf933362 100644 --- a/modules/regreet/nixos.nix +++ b/modules/regreet/nixos.nix @@ -27,7 +27,7 @@ in && # defined in https://github.com/NixOS/nixpkgs/blob/8f3e1f807051e32d8c95cd12b9b421623850a34d/nixos/modules/programs/regreet.nix#L153 config.services.greetd.settings.default_session.command - != "${pkgs.dbus}/bin/dbus-run-session ${lib.getExe pkgs.cage} ${lib.escapeShellArgs cfg.cageArgs} -- ${lib.getExe cfg.package}" + != "${lib.getExe' pkgs.dbus "dbus-run-session"} ${lib.getExe pkgs.cage} ${lib.escapeShellArgs cfg.cageArgs} -- ${lib.getExe cfg.package}" ) "stylix: regreet: custom services.greetd.settings.default_session.command value may not work: ${config.services.greetd.settings.default_session.command}"; programs.regreet = { diff --git a/palette-generator/default.nix b/palette-generator/default.nix index 99a7c248..02b6aca4 100644 --- a/palette-generator/default.nix +++ b/palette-generator/default.nix @@ -39,4 +39,6 @@ stdenvNoCC.mkDerivation { ''; passthru = { inherit docs; }; + + meta.mainProgram = "palette-generator"; } diff --git a/stylix/palette.nix b/stylix/palette.nix index 097b275d..afe12df0 100644 --- a/stylix/palette.nix +++ b/stylix/palette.nix @@ -79,7 +79,7 @@ in # the output of the palette generator will not be protected from # garbage collection. default = pkgs.runCommand "palette.json" { } '' - ${cfg.paletteGenerator}/bin/palette-generator \ + ${lib.getExe cfg.paletteGenerator} \ "${cfg.polarity}" \ ${lib.escapeShellArg "${cfg.image}"} \ "$out" diff --git a/stylix/pixel.nix b/stylix/pixel.nix index 212933fe..379c3c85 100644 --- a/stylix/pixel.nix +++ b/stylix/pixel.nix @@ -1,10 +1,14 @@ -{ pkgs, config, ... }: - +{ + pkgs, + config, + lib, + ... +}: { # Generate a PNG image containing a named color config.lib.stylix.pixel = color: pkgs.runCommand "${color}-pixel.png" { color = config.lib.stylix.colors.withHashtag.${color}; - } "${pkgs.imagemagick}/bin/convert xc:$color png32:$out"; + } "${lib.getExe' pkgs.imagemagick "convert"} xc:$color png32:$out"; }