How to build / test a package and options?

Hello,

To give some context I would like to add plugins to roundcube. In order to do so I’ll have to add them in here: nixpkgs/pkgs/servers/roundcube/plugins at nixos-25.05 · NixOS/nixpkgs · GitHub

There are two scenarios:

  1. I make a pull request to get them added to Nixpkgs
  2. I only add them to my flake

What I’m wondering is how to test this in each case. I mean in case 1., how can I check if my contrib is working, especially, how can I check that using this option will lead me to the expected result ?

And if I’m going case 2. then I have the same issue plus the question of how I can add roundcube plugins to nixpkgs directly from my flake ?

Thanks in advance for any pointer.

It looks like you can extend the set of plugins by configuring services.roundcube.package:

  services.roundcube.package =
    pkgs.roundcube.withPlugins
      (plugins: [ (plugins.callPackage path/to/your-plugin { }) ]);

You should be able to test that your plugin definition works correctly that way. When you’re ready to make the PR, add the directory with your plugin to Nixpkgs, and add a corresponding line to pkgs/servers/roundcube/plugins/plugins.nix.

1 Like

I don’t think I can help answer your questions entirely. I have GitHub - alexandregz/twofactor_gauthenticator: This RoundCube plugin adds the 2-step verification(OTP) to the login proccess working in a flake. Relevant config:

services.roundcube = {
  package = pkgs.roundcube.withPlugins (plugins: [
    (plugins.callPackage ./roundcube_twofactor { })
  ]);
  extraConfig = ''
    ...
    $config['plugins'] = [ "twofactor_gauthenticator" ];
  '';
};

roundcube_twofactor/default.nix (the patches are minor and not relevant to your questions):

{
  stdenv,
  fetchFromGitHub,
}:
let
  pname = "twofactor_gauthenticator";
  version = "unstable-2025-08-10";
in
stdenv.mkDerivation {
  inherit pname version;

  src = fetchFromGitHub {
    owner = "alexandregz";
    repo = pname;
    rev = "cf4103e56ca3f53a58f390c061a2c313bd7da73a";
    sha256 = "sha256-IgddPFKfSN1OhYy25kXnEOa+ZxD0i2HJ3NEhQ8HjUU0=";
  };

  patches = [
    # Make sure the preferences are encrypted by default.
    ./encrypt-preferences.patch
    # Increase the 2fa secret length to 40 chars.
    ./increase-secret-length.patch
  ];

  installPhase = ''
    runHook preInstall

    mkdir -p $out/plugins/${pname}
    cp -r . $out/plugins/${pname}/

    runHook postInstall
  '';
}
1 Like

Well that does answer at least part of my question, thanks for that. I guess what I was wondering is also how to have a test environment to try that before deploying it somewhere: what is the process for a maintainer to test its contribs without polluting his own env.

There are different levels of testing. Being a lazy boy (in this specific instance) I’d probably just dump my current database, spin up a new one with an import then run the service pointing at the new database, and take it for a spin. If I did that more than twice I’d probably make a script for it. If I ended up doing it a bunch I’d probably make a vm variant that I could test using nixos-rebuild build-vm. Then if I were doing it all the time, I’d probably finally learn how the nixos testing harnesses worked and / or learn how the automatic testing for the specific service worked.

1 Like

Thanks for your answer, that gives me food for thought. I think I have enough material now to start exploring this.

Thank you all!

PS: for moderators coming here, I flagged the whole thread as off-topic as it shoud have been in “Help”, this is a mistake on my side, I’m sorry.

You can simply move the topic (scroll to top, pencil icon by the title). If you don’t have access, I’ve moved it in any case.

Offtopic flags are for things that have nothing to do with nix* or replies that derail a topic.

1 Like