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.

Set up ddev

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.

Update: I am soon going to phase out the NUR package, as ddev is now part of nixpkgs. I updated the below configuration for setting up ddev either way.

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 and install dddev.
  12. # Not needed anymore if you are on the unstable branch of nixpkgs.
  13. # nixpkgs.config.packageOverrides = pkgs: {
  14. # nur = import (builtins.fetchTarball "https://github.com/nix-community/NUR/archive/master.tar.gz") {
  15. # inherit pkgs;
  16. # };
  17. # };
  18. #
  19. # Install dddev from the NUR.
  20. # environment.systemPackages = with pkgs; [
  21. # nur.repos.gbytedev.ddev
  22. # ];
  23.  
  24. # Install ddev.
  25.   environment.systemPackages = with pkgs; [ ddev ];
  26.  
  27.  
  28. # Allow Xdebug to use port 9003.
  29. networking.firewall.allowedTCPPorts = [ 9003 ];
  30.  
  31. # Make it possible for ddev to modify the /etc/hosts file.
  32. # Otherwise you'll have to manually change the
  33. # hosts configuration after creating a new ddev project.
  34. environment.etc.hosts.mode = "0644";
  35. }

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:

Comments

I'm pretty new on NixOs and for my beginning i wanted to stay on stable branch. I try your trick to use ddev and it works perfectly so thanks for the job :)

Neuen Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.

Restricted HTML

  • Erlaubte 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>
  • Zeilenumbrüche und Absätze werden automatisch erzeugt.
  • Website- und E-Mail-Adressen werden automatisch in Links umgewandelt.

Angebot innerhalb von 24 Stunden

Ob ein großes kommerzielles System, oder eine kleine Business Seite, wir schicken ein Angebot ab innerhalb von 24 Stunden nachdem Sie diese Taste drücken: Angebot anfordern