Use DDEV on Nix and NixOS

10 Aug 2023

NixOS on the Desktop

NixOS on the server is a thing of beauty (check out my last blog post about Hosting Websites on NixOS), but after my Arch installation crapped out, I decided to take it further and also use it on my laptop as a daily driver.

Even though I was aware of the vast number of packages in the Nix repositories, I was still pleasantly surprised to find that almost all of my daily tools were available directly in the stable repository. Even Steam is just one line of configuration away!

However, a crucial work tool of mine, DDEV, was missing from the repositories. DDEV is a tool designed for launching local web development environments for PHP, Node.js and Python projects.

DDEV in the Nix User Repository

With a bit of help from a savvy individual named kraftnix in the Jupiter Broadcasting Nix Nerds matrix group, I was able to create a buildable package of ddev on Nix.

The NUR (Nix User Repository) is a neat community and GitHub driven project, evidently inspired by the AUR (Arch user repository). While the NUR is smaller by several orders of magnitude, it can now be used to get ddev working on Nix / NixOS.

Below are the steps required to run DDEV on Nix / NixOS:

/etc/nixos/configuration.nix

  1. { config, pkgs, ... }:
  2. {
  3. # ...
  4.  
  5. # Install & enable docker.
  6. virtualisation.docker.enable = true;
  7.  
  8. # Add your user to the 'docker' group. Change 'MYUSER' to your Linux username.
  9. users.users.MYUSER.extraGroups = [ "docker" ];
  10.  
  11. # Enable the NUR.
  12.   nixpkgs.config.packageOverrides = pkgs: {
  13. nur = import (builtins.fetchTarball "https://github.com/nix-community/NUR/archive/master.tar.gz") {
  14. inherit pkgs;
  15. };
  16. };
  17.  
  18. # Install dddev from the NUR.
  19. environment.systemPackages = with pkgs; [
  20. nur.repos.gbytedev.ddev
  21. ];
  22.  
  23. # Allow Xdebug to use port 9003.
  24. networking.firewall.allowedTCPPorts = [ 9003 ];
  25.  
  26. # Make it possible for ddev to modify the /etc/hosts file.
  27. # Otherwise you'll have to manually change the
  28. # hosts configuration after creating a new ddev project.
  29. environment.etc.hosts.mode = "0644";
  30. }

Please test and let me know if anything is broken / missing, as I intend to create a merge request on Nixpkgs to ensure this becomes a properly maintained package.

Links:

Add new comment

The content of this field is kept private and will not be shown publicly.

Restricted HTML

  • Allowed HTML tags: <a href hreflang target> <em> <strong> <cite> <blockquote cite> <pre> <ul type> <ol start type> <li> <dl> <dt> <dd> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

Get a quote in 24 hours

Wether a huge commerce system, or a small business website, we will quote the project within 24h of you pressing the following button: Get quote