Drupal
Drupal is a self-hosted content management system web application. Its focus is on scalability, customization, and accessibility. Many large-scale institutions including those in government, higher-ed, and the non-profit sector use Drupal for running their website, but Drupal can also be used for running a humble blog, homepage, or turnkey web app.
Installation
A simple local set of Drupal can be enabled with the following configuration:
services.drupal.enable = true;
This will spin up a Drupal installation at http://localhost using nginx and MYSQL.
This configuration is functionally identical to writing:
services.drupal = {
enable = true;
sites = {
"localhost" = {
enable = true;
};
};
};
Configuration
It is possible to configure a number of different site settings using the settings.php
file that comes installed with every Drupal instance.
The settings.php
file is located at /var/lib/drupal/<hostname>/sites/default/settings.php
for each website you install. So if your website is installed at http://localhost, the path to the settings would be /var/lib/drupal/localhost/sites/default/settings.php
See the official documentation for more information on how to use settings.php
.
Using Caddy
The Drupal service uses the nginx webserver by default, but you can switch to the Caddy webserver by writing:
services.drupal.webserver = "caddy";
Note: there is currently no API for changing the webserver on individual projects. The webserver you pick will be used for every instance of Drupal you run on NixOS.
State Directory
Every website you run in NixOS will install a state directory at /var/lib/drupal/<hostname>
. This directory contains a simple file tree with some Drupal files you can edit.
Note: at the time of writing this, not every file in this directory will be symlinked to the Drupal package in /nix/store
.
In order to edit anything in the state directory, your user must be a part of the webserver group.
If you want to use nginx, you would add:
users.users.<user>.extraGroups = ["nginx"];
If you want to use caddy, you would add:
users.users.<user>.extraGroups = ["caddy"];
Alternatively, you can log in as root and edit any file in the state directory you like.
Installing Modules & Themes Using The State Directory
You can copy/paste modules and themes directly from drupal.org into the state directory and Drupal will detect them.
Modules can be copied into /var/lib/drupal/<hostname>/modules
and themes can be copied into /var/lib/drupal/<hostname>/themes
.
Pinning Drupal & Rolling A Custom Package
If you don't want to follow the package that comes from nixpkgs, you are free to define your own package or pin the version of Drupal to a specific release.
Override pkgs.drupal
Use this pattern to override the package that comes from nixpkgs. The advantage of doing this is that you can still use the passthru updater script to update your package version, and you can still use the tests that come with nixpkgs.
However, overrides are sometimes a more fragile solution as breaking upstream updates in nixpkgs can disrupt your local package.
nixpkgs.overlays = [
(self: super: {
myDrupal = super.drupal.overrideAttrs (oldAttrs: {
version = "11.0.0";
src = super.fetchFromGitLab {
domain = "git.drupalcode.org";
owner = "project";
repo = "drupal";
tag = "11.0.0";
hash = "...";
};
vendorHash = "...";
});
})
];
...
services.drupal = {
enable = true;
sites."localhost" = {
enable = true;
package = pkgs.myDrupal;
};
};
Rolling A Custom Package
Making your own package outside of nixpkgs can be done in a few different ways. The advantage of this method is that you get much more controll over the base package, but you need to be more explicit in defining your own tests, options, and other config since you won't be pulling them directly from nixpgs.
Here's an example using the let/in pattern:
{ config, lib, pkgs, ... }:
let
myDrupal = pkgs.php.buildComposerProject2 {
pname = "drupal";
version = "11.2.0";
src = pkgs.fetchFromGitLab {
domain = "git.drupalcode.org";
owner = "project";
repo = "drupal";
tag = "11.2.0";
hash = "sha256-xUo8aRjL7XN7yuIU/7WvBt6mL4TEK3VZFQSU9gfkzkY=";
};
vendorHash = "sha256-BWmuR7SRef5D+wSoDezzmBRgWZPDKgpKvdJv/NGtlTw=";
composerNoPlugins = false;
};
in
services.drupal = {
enable = true;
sites."localhost" = {
enable = true;
package = myDrupal;
};
};
You could also define your own drupal.nix
file and use callPackage
to load it.
drupal.nix
{ config, pkgs, ... }:
pkgs.php.buildComposerProject2 {
pname = "drupal";
version = "11.2.0";
src = pkgs.fetchFromGitLab {
domain = "git.drupalcode.org";
owner = "project";
repo = "drupal";
tag = "11.2.0";
hash = "sha256-xUo8aRjL7XN7yuIU/7WvBt6mL4TEK3VZFQSU9gfkzkY=";
};
vendorHash = "sha256-BWmuR7SRef5D+wSoDezzmBRgWZPDKgpKvdJv/NGtlTw=";
composerNoPlugins = false;
};
configuration.nix
{ config, pkgs, ... }:
let
myDrupal = callPackage ./drupal.nix;
in
services.drupal = {
enable = true;
sites."localhost" = {
enable = true;
package = myDrupal;
};
};