{
  pkgs,
  inputs,
  ...
}:
let
  avatar = pkgs.runCommand "kanade-avatar.jpg" { nativeBuildInputs = [ pkgs.imagemagick ]; } ''
    magick "${inputs.self}/assets/avatar.webp" -quality 92 "$out"
  '';
in
{
  system.activationScripts.postActivation.text = ''
    avatarPath="/Library/User Pictures/imnyang.jpg"
    importFile="$(/usr/bin/mktemp /tmp/imnyang-avatar.XXXXXX)"

    /usr/bin/install -d -m 0755 "/Library/User Pictures"
    /usr/bin/install -m 0644 "${avatar}" "$avatarPath"

    # Replace both account-picture representations. JPEGPhoto is embedded in
    # the directory record and is used by the login screen and System Settings.
    /usr/bin/dscl . -delete /Users/imnyang JPEGPhoto >/dev/null 2>&1 || true
    /usr/bin/dscl . -delete /Users/imnyang Picture >/dev/null 2>&1 || true
    /usr/bin/dscl . -create /Users/imnyang Picture "$avatarPath"

    /usr/bin/printf '%s\n%s:%s' \
      '0x0A 0x5C 0x3A 0x2C dsRecTypeStandard:Users 2 dsAttrTypeStandard:RecordName externalbinary:dsAttrTypeStandard:JPEGPhoto' \
      'imnyang' \
      "$avatarPath" > "$importFile"
    /usr/bin/dsimport "$importFile" /Local/Default M
    /bin/rm -f "$importFile"

    /usr/bin/dscacheutil -flushcache
  '';
}
