Pass `mkDerivation` to `home.packages`

Hi,

I’m fairly new to NixOS and tried to create a package which is missing in the NixOS repository:

# modules/reapack/reapack.nix
{
  lib,
  stdenv,
  fetchurl,
  ...
}:

stdenv.mkDerivation {
  name = "reapack";
  version = "1.2.4.5";

  src = fetchurl {
    url = "https://github.com/cfillion/reapack/releases/download/v1.2.4.5/reaper_reapack-x86_64.so";
    hash = "sha256-h3r3tF3XRjqY3Xy57Uaypg3pdJbyZ/zTyzF2DFmEJEA=";
  };

  dontUnpack = true;

  installPhase = ''
    cp $src $out
  '';
}

and added it to home-manager like so:

let
  reapack = import ../../../../modules/reapack/reapack.nix;
in
{
# ...
  home.packages = with pkgs; [
    reapack
  ];
}

This results in

A definition for option home-manager.users.recording.home.packages."[definition 7-entry 9]"' is not of type package’. Definition values: In `/nix/store/nhw2ldm65018sxzbnpx6b01mzslg3p5g-source/hosts/laptop/configuration.nix’: <function, args: {fetchurl, lib, stdenv}>

I also tried using (callPackage ../../../../modules/reapack/reapack.nix { }) directly which results in

The store path /nix/store/kh6vyycvp9fnac7d9pm7cvb36f9zwqbk-reapack is a file and can’t be merged into an environment using pkgs.buildEnv! at /nix/store/63ixj2jvy6svgqga8ah0nbda283wfarv-builder.pl line 122

I’m a bit lost right now. Since I don’t find a lot of docs regarding this topic: Is this so unusual? How are you solving such situations? And also: What’s wrong with my code?

Thanks!

And while reading my own question again I found the solution:

  installPhase = ''
    mkdir -p $out/lib
    cp $src $out/lib
  '';

It seems that the resulting build must contain a directory structure.