{pkgs}: {palette}: let
  rendersvg = pkgs.runCommand "rendersvg" {} ''
    mkdir -p $out/bin
    ln -s ${pkgs.resvg}/bin/resvg $out/bin/rendersvg
  '';
in
  pkgs.stdenv.mkDerivation rec {
    name = "generated-gtk-theme-nix-rice";
    src = pkgs.fetchFromGitHub {
      owner = "nana-4";
      repo = "materia-theme";
      rev = "6e5850388a25f424b8193fe4523504d1dc364175";
      sha256 = "sha256-I6hpH0VTmftU4+/pRbztuTQcBKcOFBFbNZXJL/2bcgU=";
    };
    buildInputs = with pkgs; [
      sassc
      bc
      which
      rendersvg
      meson
      ninja
      nodePackages.sass
      gtk4.dev
      optipng
    ];
    phases = ["unpackPhase" "installPhase"];
    installPhase = ''
      HOME=/build
      chmod 777 -R .
      patchShebangs .
      mkdir -p $out/share/themes
      mkdir bin
      sed -e 's/handle-horz-.*//' -e 's/handle-vert-.*//' -i ./src/gtk-2.0/assets.txt

      cat > /build/gtk-colors << EOF
        BTN_BG=${palette.util.bg}
        BTN_FG=${palette.bright.yellow}
        FG=${palette.util.fg}
        BG=${palette.util.bg}
        HDR_BTN_BG=${palette.util.bg}
        HDR_BTN_FG=${palette.util.fg}
        ACCENT_BG=${palette.normal.cyan}
        ACCENT_FG=${palette.normal.yellow}
        HDR_FG=${palette.bright.yellow}
        HDR_BG=${palette.util.bg}
        MATERIA_SURFACE=${palette.normal.black}
        MATERIA_VIEW=${palette.bright.black}
        MENU_BG=${palette.util.bg}
        MENU_FG=${palette.util.fg}
        SEL_BG=${palette.normal.yellow}
        SEL_FG=${palette.normal.cyan}
        TXT_BG=${palette.util.bg}
        TXT_FG=${palette.util.fg}
        WM_BORDER_FOCUS=${palette.normal.yellow}
        WM_BORDER_UNFOCUS=${palette.normal.black}
        UNITY_DEFAULT_LAUNCHER_STYLE=False
        NAME="nix-rice"
        MATERIA_STYLE_COMPACT=False
      EOF

      echo "Changing colours:"
      ./change_color.sh -o nix-rice /build/gtk-colors -i False -t "$out/share/themes"
      chmod 555 -R .
    '';
  }
