Nix packaging basics

I am learning how to package the apache mod_tls module for nix and have run into various roadblocks.

I am noting my specific gaps in knowledge here.
I hope to formalize these into questions and answers for packaging 101 or to keep as wiki-style example of how to packaging something in nix without being an expert.

how do I generate the sha256 value expected by stdenv.mkDerivation?

how do I test the package I’m adding locally?

I’m unsure how to do this for things like apache modules which seem more internal to another package.

The documentation says nix-build -A packageName.
But I am packaging an apache module which doesn’t appear to work with nix-build -A mod_tls.
My current workaround is to run nix-build --show-trace -A apacheHttpdPackages_2_4 in my modified source tree.

Hi @efx,

I’ll assume you’re running on NixOS and interested in using apache on NixOS.

There are a number of ways to test packages, but apache specifically is pretty tightly tied to the NixOS module unless you want to write your own configs. I like to use NixOS containers to do simple apache tests. Since you’re dealing with mod_tls that might present a few obstacles, but should be fine.

~> cat ~/apache.nix
{ config, pkgs, lib, ... }:
  services.httpd.enable = true;
  services.httpd.extraModules = [
    { name = "tls"; path = "${pkgs.apacheHttpdPackages.mod_tls}/modules/"; }
  # etc...

~> sudo nixos-container create apache --nixos-path ~/nixpkgs-local-branch --config-file ~/apache.nix

I like to use git worktrees to have a separate instance for each NixOS container I work on.

How does that sound?

1 Like

I did a video, starting from nothing, and adding a package to nixpkgs. You can view it here: Nixpkgs - Adding a package to unstable/master branch - YouTube


This sounds great!
Thank you for sharing your workflow and core snippets. That will save me hours of trial and error learning. I hope to bring mod_tls to the nixpkgs ecosystem. I figured working on packaging from a nixOS instance makes the most sense.

Using git worktree here seems quite compelling. Have you written up or know of any posts that describe the nixos-container and git worktree workflow?

My git paradigm just shifted because worktrees let you “check out more than one branch at a time”!

@jonringer thanks for the video tutorial link! I’m sure that addresses the topic perfectly for a clueless beginner like me. :grinning_face_with_smiling_eyes: