Are these uses of mkDerivation necessary?

Confession time: I’ve been using ChatGPT. It scratches the itch in the moment, but now I’m going through my code and trying to understand and clean up the werid things that it has done.

The two expressions below are used to pin specific versions to my project’s devshell like so:

devShells.default = pkgs.mkShell {
  packages = [
    (import ./.deps/yarn.nix { inherit pkgs system; })
    (import ./.deps/kustomize.nix { inherit pkgs system; })

They work, but they both have the same kind of wart:

{ pkgs, system }:

let
  kustomize-tar = {
    "x86_64-linux" = {
      file = "kustomize_v4.5.5_linux_amd64.tar.gz";
      checksum = "0h6nhrz4yavgsca350684zi2nz7mf6n03rnaiic278alkbqq76aj";
    };
    "aarch64-linux" = {
      file = "kustomize_v4.5.5_linux_arm64.tar.gz";
      checksum = "1d3apml7z628yi6zchy4ybl19l82xsl6rxc8iz50q3hqcj5dxy3j";
    };
    "x86_64-darwin" = {
      file = "kustomize_v4.5.5_darwin_amd64.tar.gz";
      checksum = "062p0gd68qlk2ry179kqmzg7zw6dhalzhsqwgza8m6fgmwaymkiw";
    };
    "aarch64-darwin" = {
      file = "kustomize_v4.5.5_darwin_arm64.tar.gz";
      checksum = "0yrshmlrmf6vbgqmi9gspyffjs9k1nslzsblsyk468sy7ji2dsx6";
    };
  }.${system};

  kustomize-bin = fetchTarball{
    name = "kustomize";
    url = "https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv4.5.5/${kustomize-tar.file}";
    sha256 = kustomize-tar.checksum;
  };
in
  pkgs.stdenv.mkDerivation {
      pname = "kustomize";
      version = "4.5.5";
      src = kustomize-bin;
      phases = "installPhase";
      installPhase = ''
        install -D $src $out/bin/kustomize
      '';
  }
{ pkgs, system }:

let
  nodejs-src = {
    "x86_64-linux" = {
      url = "https://nodejs.org/dist/v16.13.2/node-v16.13.2-linux-x64.tar.gz";
      sha256 = pkgs.lib.fakeSha256;
    };
    "aarch64-linux" = {
      url = "https://nodejs.org/dist/v16.13.2/node-v16.13.2-linux-arm64.tar.gz";
      sha256 = pkgs.lib.fakeSha256;
    };
    "x86_64-darwin" = {
      url = "https://nodejs.org/dist/v16.13.2/node-v16.13.2-darwin-x64.tar.gz";
      sha256 = pkgs.lib.fakeSha256;
    };
    "aarch64-darwin" = {
      url =
        "https://nodejs.org/dist/v16.13.2/node-v16.13.2-darwin-arm64.tar.gz";
      sha256 = "sha256-CdMAAIrVh5LBJiKl6v2xTJMVh7uIcT3032TN9P8hiNE=";
    };
  }.${system} or (throw "Unsupported system: ${system}");

  nodejs = pkgs.stdenv.mkDerivation {
    name = "nodejs-16.13.2";
    src = pkgs.fetchurl { inherit (nodejs-src) url sha256; };
    installPhase = ''
      mkdir -p $out
      cp -r ./* $out/
    '';
    meta = { platforms = pkgs.lib.platforms.all; };
  };
in
  pkgs.yarn.override { nodejs = nodejs; }

I’m looking at those calls to mkDerivation, and they seem kind of silly. We’re just taking the bits which we already have and wrapping them in something that runs a command to put them somewhere.

Is there a canonical way to do this, maybe some wrapper in nixpkgs that one would use rather than copying bits around in the installPhase?

runCommandLocal or in general just look in trivial-builders to see the lay of the land.