Drupal

Revision as of 02:33, 26 January 2026 by Abmurrow (talk | contribs) (Created a simple set of configuration for the NixOS Drupal service.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Drupal is a self-hosted content management system with an eye towards enterprise usage, custom development, internationalization, accessibility, and open source software. It has a large ecosystem of user-contributed plugins and themes that can be used to extend its capabilities, the vast majority of of which are free to use and do not feature any standing subscription costs.

Installation

A simple installation can be implemented with the following setup

services.drupal.enable = true;

This will spin up a simple 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

Configuration Using settings.php

Drupal uses a file called settings.php to configure the application at a general level. If you use the NixOS-provided Drupal package instead of a custom package, you may want to change some of these settings.

You can do this by writing pure PHP into the `services.drupal.sites.<name>.extraSettings` key

services.drupal = {
  enable = true;
  sites = {
    "localhost" = {
      enable = true;
      extraConfig = ''
        // These settings will be printed as pure PHP into a file visible to settings.php.
        // These settings will be appended to, and thus override, any existing settings
        // at the same namespace.
        $config['user.settings']['anonymous'] = 'Visitor';
        $settings['entity_update_backup'] = TRUE;
      '';
    };
  };
};

Webserver Configuration

You can use either nginx or caddy as the webserver, but only one may be used at a time. All Drupal installations on NixOS will use the same configured webserver, though configuration may be customized for each installation.

Nginx is the default webserver, though you can use caddy by writing this configuration

services.drupal.webserver = "caddy";

How To Access Files In The State Directory As A Regular User

At install time, a small set of user-editable files get copied to `/var/lib/drupal/<sitname>` and are free to be changed by system users so long as they have been added to the webserver group. If the user has not been added to the webserver group, they will be denied access to any resources.

The group name you must use depends on your currently configured webserver settings. Once you make your changes, you must log in and back out again, or change your current group using `newgrp`.

For Nginx
users.users.<user>.extraGroups = ["nginx"];
For Caddy
users.users.<user>.extraGroups = ["caddy"];

Database Configuration

The NixOS implementation of Drupal uses MySQL as the primary database, however you can add other databases using settings.php. Refer to the Configuration Using settings.php section above for instructions on how to add extra settings to settings.php.

Using nix, you can configure the database that gets created in NixOS at install time by using this configuration interface:

services.drupal = {
  enable = true;
  sites = {
    "localhost" = {
      enable = true;
      database = {
        user = "database_user";                # Default is "drupal"
        tablePrefix = "tblprfx_";              # Not set by default
        socket = /path/to/mysqld/mysqld.sock;  # Default is /run/mysqld/mysqld.sock
        port = 3306;                           # Default is 3306  
        passwordFile = /path/to/password/file; # Not set by default
        name = "database_name";                # Default is "drupal"
        host = "database.host.local";          # Default is localhost
        createLocally = true;                  # Set to false if you want to use a remote DB
      };
    };
  };
};

State Directory

The state directory is a small set of user-editable files that gets installed into `/var/lib/drupal/<sitename>` when the Drupal service is first activated. It contains a truncated Drupal file tree where system users can upload and manage certain files that affect the state of the web application.

This is the file structure you can find at a typical installation

$ ls
config  modules  private  sites  themes

Files in this directory, because of their tendency to change during run time, cannot live inside of `/nix/store`, so they are placed here instead.

The webserver is the default owner of all files in the state directory and regular users are not permitted to access this directory by default. However, users who belong to the webserver group may edit or upload files as needed. Refer to "How To Access Files In The State Directory As A Regular User" for more information on how to add users to the webserver group.

Uploading Modules and Themes

The `modules` and `themes` directories of the state directory are symlinked directly to the Drupal installation in the nix store. Users can upload both modules and themes to these directories and Drupal will detect them.

This is not the officially recommended method for installing contributed modules and themes, or modules and themes that have third-party dependencies. However, this functionality has been preserved both as an escape hatch, and to provide an easy way to manage a simple Drupal install that doesn't rely on composer.