{
  description = "Artemis RGB (Avalonia + SkiaSharp, NixOS compatible)";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
  };

  outputs = { nixpkgs, ... }:
  let
    system = "x86_64-linux";

    pkgs = import nixpkgs {
      inherit system;
      config.allowUnfree = true;
    };

    artemis = pkgs.stdenvNoCC.mkDerivation rec {
      pname = "artemis-rgb";
      version = "latest-master";

      src = pkgs.fetchurl {
        url = "https://updating.artemis-rgb.com/api/artifacts/latest/master/linux";
        sha256 = "sha256-YzgkzfVZbxSesrVTZTvUXWm8K2TBA6pQbiN9ErDGzeA=";
      };

      nativeBuildInputs = [
        pkgs.unzip
        pkgs.makeWrapper
      ];

      buildInputs = [
        # .NET runtime deps
        pkgs.icu
        pkgs.zlib
        pkgs.openssl

        # Skia / fonts
        pkgs.fontconfig
        pkgs.freetype

        # X11 (required even on Wayland for Avalonia)
        pkgs.xorg.libX11
        pkgs.xorg.libXcursor
        pkgs.xorg.libXrandr
        pkgs.xorg.libXi
        pkgs.xorg.libXinerama
        pkgs.xorg.libxcb
        pkgs.xorg.libICE
        pkgs.xorg.libSM

        # Graphics / display
        pkgs.mesa
        pkgs.wayland
      ];

      unpackPhase = ''
        unzip $src
      '';

      installPhase = ''
        mkdir -p $out/lib/artemis
        cp -r ./* $out/lib/artemis
        chmod +x $out/lib/artemis/Artemis.UI.Linux

        mkdir -p $out/bin
        makeWrapper $out/lib/artemis/Artemis.UI.Linux \
          $out/bin/Artemis.UI.Linux \
          --set LD_LIBRARY_PATH "${pkgs.lib.makeLibraryPath buildInputs}"

        mkdir -p $out/share/applications
        cat > $out/share/applications/artemis.desktop <<EOF
[Desktop Entry]
Name=Artemis
Exec=Artemis.UI.Linux
Icon=artemis
Terminal=false
Type=Application
Categories=Utility;
EOF

        if [ -d $out/lib/artemis/Icons ]; then
          mkdir -p $out/share/icons/hicolor
          cp -r $out/lib/artemis/Icons/* $out/share/icons/hicolor/
        fi
      '';

      meta = with pkgs.lib; {
        description = "Artemis RGB lighting controller";
        homepage = "https://artemis-rgb.com";
        license = licenses.unfreeRedistributable;
        platforms = [ "x86_64-linux" ];
      };
    };

  in {
    packages.${system}.default = artemis;
  };
}
