oliverdavies.uk/content/node.c7e013f4-a712-4566-9e6e-6a4b1f580e30.yml

103 lines
4.3 KiB
YAML

uuid:
- value: c7e013f4-a712-4566-9e6e-6a4b1f580e30
langcode:
- value: en
type:
- target_id: daily_email
target_type: node_type
target_uuid: 8bde1f2f-eef9-4f2d-ae9c-96921f8193d7
revision_timestamp:
- value: '2025-07-02T19:14:30+00:00'
revision_uid:
- target_type: user
target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849
revision_log: { }
status:
- value: true
uid:
- target_type: user
target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849
title:
- value: 'Managing services without NixOS'
created:
- value: '2025-06-30T19:10:50+00:00'
changed:
- value: '2025-07-02T19:14:30+00:00'
promote:
- value: false
sticky:
- value: false
default_langcode:
- value: true
revision_translation_affected:
- value: true
path:
- alias: /daily/2025/06/30/managing-services-without-nixos
langcode: en
body:
- value: |-
If you're working on a simple PHP application, [a simple development shell][0] with PHP and Composer may be enough.
But what if you're building a more complex application, like a Drupal website?
As well as PHP, it needs services like a database server.
Installing `mysql` or `mariadb` isn't enough - it needs to be running so your application can connect to it.
If you use NixOS - the operating system based on the Nix package manager - configuring a database server is as simple as `services.mysql.enable = true;`.
It will start automatically when the computer starts and you can add more Nix code to create databases and manage permissions.
But what if you're not using NixOS?
The Nix package manager can't manage services.
But, there is a solution - [services-flake][1].
It can be added to a flake.nix file and adds a tool called Process Compose to manage processes and services.
Then, I can add code like this to start a database server and create the database with `nix run`:
```nix
services.mysql."mysql1" = {
enable = true;
initialDatabases = [
{ name = "drupal_nix_flake_example"; }
];
};
```
If you have other processes, such as running Tailwind CSS to build your CSS files, it can do that too.
To see a full Drupal example using services-flake, see [my drupal-nix-flake-example][2] repository.
[0]: /daily/2025/06/27/ready-go-devshells
[1]: https://github.com/juspay/services-flake
[2]: https://code.oliverdavies.uk/opdavies/drupal-nix-flake-example
format: markdown
processed: |
<p>If you're working on a simple PHP application, <a href="/daily/2025/06/27/ready-go-devshells">a simple development shell</a> with PHP and Composer may be enough.</p>
<p>But what if you're building a more complex application, like a Drupal website?</p>
<p>As well as PHP, it needs services like a database server.</p>
<p>Installing <code>mysql</code> or <code>mariadb</code> isn't enough - it needs to be running so your application can connect to it.</p>
<p>If you use NixOS - the operating system based on the Nix package manager - configuring a database server is as simple as <code>services.mysql.enable = true;</code>.</p>
<p>It will start automatically when the computer starts and you can add more Nix code to create databases and manage permissions.</p>
<p>But what if you're not using NixOS?</p>
<p>The Nix package manager can't manage services.</p>
<p>But, there is a solution - <a href="https://github.com/juspay/services-flake">services-flake</a>.</p>
<p>It can be added to a flake.nix file and adds a tool called Process Compose to manage processes and services.</p>
<p>Then, I can add code like this to start a database server and create the database with <code>nix run</code>:</p>
<pre><code>services.mysql."mysql1" = {
enable = true;
initialDatabases = [
{ name = "drupal_nix_flake_example"; }
];
};
</code></pre><p>If you have other processes, such as running Tailwind CSS to build your CSS files, it can do that too.</p>
<p>To see a full Drupal example using services-flake, see <a href="https://code.oliverdavies.uk/opdavies/drupal-nix-flake-example">my drupal-nix-flake-example</a> repository.</p>
summary: ''
field_daily_email_cta:
- target_type: node
target_uuid: c74de3cf-5362-4d08-935a-a9d0d22fcb94