SlideShare a Scribd company logo
nix-processmgmt: An experimental Nix-based
process manager-agnostic framework
Sander van der Burg
October 17, 2020
Sander van der Burg nix-processmgmt
Nix package manager: a powerful solution
Conveniently construct packages from source code and all its
required build-time dependencies
Build determinism.
Same hash code → (nearly) bit-identical build
Transparent binary deployments (by using substitutes)
Store multiple versions and variants safely next to each other
Thanks to the hash prefixes and the Nix store
Unprivileged user deployments
Multiple operating systems: Linux, macOS, FreeBSD, others
Sander van der Burg nix-processmgmt
Nix: development environments
We can conveniently install and use all kinds of packages without
interfering with the host system’s packages.
nix-shell example
$ python --version
Python 2.7.15
$ node --version
node: command not found
$ nix-shell -p python3 nodejs
$ python --version
Python 3.8.5
$ which python
/nix/store/z65l1jqvxa58zzwwa3bvglb6asj4y8cv-python3-3.8.5/bin/python
$ node --version
v12.18.4
$ which node
/nix/store/2w6ilfh7zmbz9zqvphgxinmbn3wdqa1b-nodejs-12.18.4/bin/node
Sander van der Burg nix-processmgmt
Nix package manager: deploying services?
Sander van der Burg nix-processmgmt
Nix package manager: not a service manager
Nix does not manage application services/processes’ life-cycles.
Sander van der Burg nix-processmgmt
Nix: service deployment integrations
There are sister projects that complement Nix with process manage-
ment:
NixOS. Generates systemd unit files to manage services.
Requires you to switch to a fully Nix-managed Linux
distribution.
nix-darwin. Generates launchd daemon configuration files.
Only works on macOS.
Sander van der Burg nix-processmgmt
Nix: service deployment integrations
Nix can also be used to augment other process management solu-
tions:
Docker. Docker uses a package manager in Dockerfiles for
the construction of images.
Nix can be used as a replacement for conventional package
managers.
Nix can be used to fully build Docker images.
Not always not a compelling use case for Nix beginners →
they typically download prebuilt images from Docker Hub.
Docker is built around Linux technologies (e.g. namespaces)
and deploys Linux software
Sander van der Burg nix-processmgmt
nix-processmgmt: A general solution complementing Nix
with process management
Sander van der Burg nix-processmgmt
nix-processmgmt: A general solution complementing Nix
with process management
Driven by Nix and the Nix expression language
Based on simple conventions: function definitions and an
attribute set with function invocations
Similar to how packages are organized in Nixpkgs
Works with process dependencies as well: the framework
arranges the ordering, if needed
Process-manager agnostic: Integrates with sysvinit scripts,
supervisord, systemd, launchd, bsdrc scripts, cygrunsrv
Even with systems that are not qualified as process managers:
disnix, docker
Sander van der Burg nix-processmgmt
nix-processmgmt: A general solution complementing Nix
with process management
Operating system agnostic: Works on NixOS, but it is not a
requirement
Conventional Linux distros, macOS, FreeBSD, Cygwin
Unprivileged user installations
A switch to disable creation of users, and changing user
permissions
No advanced concepts required, such as namespaces and
cgroups
The solution relies on conflict avoidance, rather than isolation
Sander van der Burg nix-processmgmt
Example: a simple web application system
Sander van der Burg nix-processmgmt
Packaging the webapp process (sysvinit, verbose)
{createSystemVInitScript, webapp, port ? 5000}:
createSystemVInitScript {
name = "webapp";
description = "Example web application";
environment.PORT = port;
activities = {
start = ’’
log_info_msg "Starting Example web application..."
loadproc ${webapp}/bin/webapp -D
evaluate_retval
’’;
stop = ’’
log_info_msg "Stopping Example web application..."
killproc ${webapp}/bin/webapp
evaluate_retval
’’;
restart = "$0 stop; sleep 1; $0 start";
status = "statusproc ${webapp}/bin/webapp";
};
runlevels = [ 3 4 5 ];
}
Sander van der Burg nix-processmgmt
Packaging the webapp process (sysvinit, declarative)
{createSystemVInitScript, webapp, port ? 5000}:
createSystemVInitScript {
name = "webapp";
process = "${webapp}/bin/webapp";
args = [ "-D" ];
runlevels = [ 3 4 5 ];
environment.PORT = port;
}
We can also specify the daemon that we want to manage, instead of
the activity implementations. Most sysvinit activities (start, stop,
restart, reload, status) can be inferred.
Sander van der Burg nix-processmgmt
Packaging the webapp process (systemd)
The following function composes a systemd unit instead of a
sysvinit script:
{createSystemdService, webapp, port ? 5000}:
createSystemdService {
name = "webapp";
Unit = {
Description = "Example web application";
};
Service = {
ExecStart = "${webapp}/bin/webapp";
Environment.PORT = port;
Type = "simple";
};
}
The framework contains many other process manager-
specific abstraction functions: createSupervisordProgram,
createLaunchdDaemon, createBSDRCScript etc.
Sander van der Burg nix-processmgmt
Packaging the webapp process (agnostic)
Process manager-agnostic abstraction of the webapp service:
{createManagedProcess, webapp, port ? 5000}:
createManagedProcess {
name = "webapp";
description = "Example web application";
process = "${webapp}/bin/webapp";
daemonArgs = [ "-D" ]; # For process managers that prefer daemons
environment.PORT = port;
overrides = {
sysvinit.runlevels = [ 3 4 5 ];
};
}
Invokes the required target-specific abstraction function, e.g.
createSystemVInitScript, createSystemdService
overrides override/augment process manager-specific
parameters
You can treat foreground processes and daemons separately,
for optimal user experience
Sander van der Burg nix-processmgmt
Instantiatable webapp processes
{createManagedProcess, webapp}:
{instanceSuffix ? "", instanceName ? "webapp${instanceSuffix}", port ? 5000}:
createManagedProcess {
name = instanceName;
inherit instanceName; # To ensure a unique PID file name
description = "Example web application";
process = "${webapp}/bin/webapp";
daemonArgs = [ "-D" ]; # For process managers that prefer daemons
environment.PORT = port;
overrides = {
sysvinit.runlevels = [ 3 4 5 ];
};
}
instanceName: ensures that the daemon command generates
unique PID file
Outer-function header: parameters that apply to all instances.
Inner-function header: instance parameters. A unique
combination ensures that multiple instances can co-exist.
Sander van der Burg nix-processmgmt
Composing process instances
{ pkgs ? import <nixpkgs> {}
, stateDir ? "/var" , forceDisableUserChange ? false, processManager}:
let constructors = import ./constructors.nix {
inherit pkgs stateDir forceDisableUserChange processManager;
}; in
rec {
webapp1 = rec { # First webapp instance
port = 5000;
dnsName = "webapp1.local";
pkg = constructors.webapp {
inherit port; instanceSuffix = "1";
};
};
webapp2 = rec { # Second webapp instance
port = 5001;
dnsName = "webapp2.local";
pkg = constructors.webapp {
inherit port; instanceSuffix = "2";
};
};
...
}
Sander van der Burg nix-processmgmt
Composing process instances
{ pkgs ? import <nixpkgs> {}
, stateDir ? "/var" , forceDisableUserChange ? false, processManager}:
let constructors = import ./constructors.nix {
inherit pkgs stateDir forceDisableUserChange processManager;
}; in
rec {
...
# Nginx with a config that redirects users to the appropriate webapp
# instance based on the virtual host header
nginx = {
pkg = constructors.nginxReverseProxyHostBased {
# Process dependencies used to set up redirections in nginx.conf
webapps = [ webapp1 webapp2 ];
port = 8080;
} {};
};
}
Sander van der Burg nix-processmgmt
Demo: deploying the system and using it
Deploy the process instances as sysvinit scripts:
$ nixproc-sysvinit-switch processes.nix
Open the first webapp instance (via the Nginx reverse proxy):
$ curl -H ’Host: webapp1.local’ http://localhost:8080
Open the second webapp instance (via the Nginx reverse proxy):
$ curl -H ’Host: webapp2.local’ http://localhost:8080
Sander van der Burg nix-processmgmt
Demo: all kinds of process manager integrations
Deploy as systemd units (in a user session):
$ nixproc-systemd-switch --user processes.nix
Deploy as supervisord programs (stateless):
$ nixproc-supervisord-deploy-stateless processes.nix
Deploy on FreeBSD as BSD rc scripts:
$ nixproc-bsdrc-switch processes.nix
Deploy as Docker containers per service (with shared Nix store and
host networking):
$ nixproc-docker-switch processes.nix
Sander van der Burg nix-processmgmt
Demo: screenshots
Sander van der Burg nix-processmgmt
Other features of nix-processmgmt
Automatic creation of users and groups (createCredentials
function)
nixproc-id-assign: Automated assignment of unique IDs
for TCP/UDP ports, UIDs, GIDs to process instances
Using Disnix as a process orchestrator (works on all platforms
where Nix/Disnix is supported)
Sander van der Burg nix-processmgmt
Combining nix-processmgmt with Disnix
We can use any process manager, do distributed deployment and
combine processes with non-process based services (e.g. Java web
applications in an Apache Tomcat container):
Sander van der Burg nix-processmgmt
Example services packaged for nix-processmgmt
HTTP/application servers:
Apache HTTP server
Nginx
Apache Tomcat
Database:
PostgreSQL
MariaDB/MySQL
MongoDB
InfluxDB
Misc:
Docker
Supervisord
svnserve
Sander van der Burg nix-processmgmt
Future work
Deploy containers with multiple processes (WIP)
Mutable service containers (WIP)
s6 / s6-rc backend
Work on a test strategy for services
Maybe write an RFC?
Sander van der Burg nix-processmgmt
Availability
https://github.com/svanderburg/nix-processmgmt
The implementation is still a work in progress and relies on devel-
opment versions of dependencies!
Sander van der Burg nix-processmgmt
References
Blog posts:
A Nix-based functional organization for managing processes,
https://sandervanderburg.blogspot.com/2019/11/
a-nix-based-functional-organization-for.html
A declarative process manager-agnostic deployment
framework based on Nix tooling,
https://sandervanderburg.blogspot.com/2020/02/
a-declarative-process-manager-agnostic.html
Deploying container and application services with Disnix,
https://sandervanderburg.blogspot.com/2020/04/
deploying-container-and-application.html
Sander van der Burg nix-processmgmt
References
Blog posts:
Using Disnix as a simple and minimalistic dependency-based
process manager,
https://sandervanderburg.blogspot.com/2020/06/
using-disnix-as-simple-and-minimalistic.html
Experimenting with Nix and the service management
properties of Docker,
https://sandervanderburg.blogspot.com/2020/08/
experimenting-with-nix-and-service.html
Assigning unique IDs to services in Disnix deployment models,
https://sandervanderburg.blogspot.com/2020/09/
assigning-unique-ids-to-services-in.html
Sander van der Burg nix-processmgmt
References
E. Dolstra, The Purely Functional Software Deployment
Model, PhD thesis, Chapter 9,
https://edolstra.github.io/pubs/phd-thesis.pdf
Sander van der Burg nix-processmgmt
Questions
Sander van der Burg nix-processmgmt

More Related Content

PDF
Using Nix and Docker as automated deployment solutions
PDF
Automating Mendix application deployments with Nix
PDF
Deploying NPM packages with the Nix package manager
ODP
Testing Wi-Fi with OSS Tools
PDF
Small, Simple, and Secure: Alpine Linux under the Microscope
PDF
Nix for Python developers
PDF
Docker 原理與實作
PDF
Docker command
Using Nix and Docker as automated deployment solutions
Automating Mendix application deployments with Nix
Deploying NPM packages with the Nix package manager
Testing Wi-Fi with OSS Tools
Small, Simple, and Secure: Alpine Linux under the Microscope
Nix for Python developers
Docker 原理與實作
Docker command

What's hot (20)

PDF
開放運算&GPU技術研究班
PDF
Using NixOS for declarative deployment and testing
PDF
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
PDF
Advanced Task Scheduling with Amazon ECS (June 2017)
PDF
CoreOS + Kubernetes @ All Things Open 2015
PDF
Dockerを利用したローカル環境から本番環境までの構築設計
PDF
Networking and Go: An Engineer's Journey (Strangeloop 2019)
PDF
Docker remote-api
PDF
Ansible docker
PDF
What Have Syscalls Done for you Lately?
PPTX
CoreOS in a Nutshell
PDF
LXC on Ganeti
PDF
Declare your infrastructure: InfraKit, LinuxKit and Moby
PDF
Docker and friends at Linux Days 2014 in Prague
PDF
Containers: What are they, Really?
PDF
高レイテンシwebサーバのGKE構築と beta機能アレコレのハナシ
PDF
Deploying MongoDB sharded clusters easily with Terraform and Ansible
PDF
Paris container day june17
PDF
Wordpress y Docker, de desarrollo a produccion
PDF
Nomad, l'orchestration made in Hashicorp - Bastien Cadiot
開放運算&GPU技術研究班
Using NixOS for declarative deployment and testing
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
Advanced Task Scheduling with Amazon ECS (June 2017)
CoreOS + Kubernetes @ All Things Open 2015
Dockerを利用したローカル環境から本番環境までの構築設計
Networking and Go: An Engineer's Journey (Strangeloop 2019)
Docker remote-api
Ansible docker
What Have Syscalls Done for you Lately?
CoreOS in a Nutshell
LXC on Ganeti
Declare your infrastructure: InfraKit, LinuxKit and Moby
Docker and friends at Linux Days 2014 in Prague
Containers: What are they, Really?
高レイテンシwebサーバのGKE構築と beta機能アレコレのハナシ
Deploying MongoDB sharded clusters easily with Terraform and Ansible
Paris container day june17
Wordpress y Docker, de desarrollo a produccion
Nomad, l'orchestration made in Hashicorp - Bastien Cadiot
Ad

Similar to nix-processmgmt: An experimental Nix-based process manager-agnostic framework (20)

PDF
The Nix project
PDF
The Nix project
PDF
Deploying .NET applications with the Nix package manager
PDF
Automating complex infrastructures with Puppet
PDF
The NixOS project and deploying systems declaratively
PPTX
Docker Security workshop slides
PDF
The Fairy Tale of the One Command Build Script
PDF
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
PPTX
Docker for Web Developers: A Sneak Peek
PDF
Postgres the hardway
PDF
Scaling docker with kubernetes
PDF
Automating Complex Setups with Puppet
PDF
Drone CI/CD 自動化測試及部署
PDF
Docker, the Future of DevOps
PPTX
Running Docker in Development & Production (DevSum 2015)
PDF
Dysnomia: complementing Nix deployments with state deployment
PPTX
Deploying Windows Containers on Windows Server 2016
PDF
桃園市教育局Docker技術入門與實作
PPTX
Running Docker in Development & Production (#ndcoslo 2015)
PDF
Deploying .NET services with Disnix
The Nix project
The Nix project
Deploying .NET applications with the Nix package manager
Automating complex infrastructures with Puppet
The NixOS project and deploying systems declaratively
Docker Security workshop slides
The Fairy Tale of the One Command Build Script
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
Docker for Web Developers: A Sneak Peek
Postgres the hardway
Scaling docker with kubernetes
Automating Complex Setups with Puppet
Drone CI/CD 自動化測試及部署
Docker, the Future of DevOps
Running Docker in Development & Production (DevSum 2015)
Dysnomia: complementing Nix deployments with state deployment
Deploying Windows Containers on Windows Server 2016
桃園市教育局Docker技術入門與實作
Running Docker in Development & Production (#ndcoslo 2015)
Deploying .NET services with Disnix
Ad

More from Sander van der Burg (18)

PDF
The Monitoring Playground
PDF
Deploying (micro)services with Disnix
PDF
Hydra: Continuous Integration and Testing for Demanding People: The Details
PDF
Hydra: Continuous Integration and Testing for Demanding People: The Basics
PDF
A Reference Architecture for Distributed Software Deployment
PDF
A Reference Architecture for Distributed Software Deployment
PDF
Techniques and lessons for improvement of deployment processes
PDF
A Generic Approach for Deploying and Upgrading Mutable Software Components
PDF
A Self-Adaptive Deployment Framework for Service-Oriented Systems
PDF
Pull Deployment of Services
PDF
Disnix: A toolset for distributed deployment
PDF
Automated Deployment of Hetergeneous Service-Oriented System
PDF
Pull Deployment of Services: Introduction, Progress and Challenges
PDF
Software Deployment in a Dynamic Cloud
PDF
Atomic Upgrading of Distributed Systems
PDF
Model-driven Distributed Software Deployment
PDF
Model-driven Distributed Software Deployment
PDF
Model-driven Distributed Software Deployment laymen's talk
The Monitoring Playground
Deploying (micro)services with Disnix
Hydra: Continuous Integration and Testing for Demanding People: The Details
Hydra: Continuous Integration and Testing for Demanding People: The Basics
A Reference Architecture for Distributed Software Deployment
A Reference Architecture for Distributed Software Deployment
Techniques and lessons for improvement of deployment processes
A Generic Approach for Deploying and Upgrading Mutable Software Components
A Self-Adaptive Deployment Framework for Service-Oriented Systems
Pull Deployment of Services
Disnix: A toolset for distributed deployment
Automated Deployment of Hetergeneous Service-Oriented System
Pull Deployment of Services: Introduction, Progress and Challenges
Software Deployment in a Dynamic Cloud
Atomic Upgrading of Distributed Systems
Model-driven Distributed Software Deployment
Model-driven Distributed Software Deployment
Model-driven Distributed Software Deployment laymen's talk

Recently uploaded (20)

PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
Introduction to Artificial Intelligence
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
System and Network Administraation Chapter 3
PDF
Nekopoi APK 2025 free lastest update
PPTX
Transform Your Business with a Software ERP System
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
ai tools demonstartion for schools and inter college
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Introduction to Artificial Intelligence
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
System and Network Administraation Chapter 3
Nekopoi APK 2025 free lastest update
Transform Your Business with a Software ERP System
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
CHAPTER 2 - PM Management and IT Context
How Creative Agencies Leverage Project Management Software.pdf
Understanding Forklifts - TECH EHS Solution
VVF-Customer-Presentation2025-Ver1.9.pptx
2025 Textile ERP Trends: SAP, Odoo & Oracle
wealthsignaloriginal-com-DS-text-... (1).pdf
Odoo POS Development Services by CandidRoot Solutions
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Odoo Companies in India – Driving Business Transformation.pdf
ai tools demonstartion for schools and inter college

nix-processmgmt: An experimental Nix-based process manager-agnostic framework

  • 1. nix-processmgmt: An experimental Nix-based process manager-agnostic framework Sander van der Burg October 17, 2020 Sander van der Burg nix-processmgmt
  • 2. Nix package manager: a powerful solution Conveniently construct packages from source code and all its required build-time dependencies Build determinism. Same hash code → (nearly) bit-identical build Transparent binary deployments (by using substitutes) Store multiple versions and variants safely next to each other Thanks to the hash prefixes and the Nix store Unprivileged user deployments Multiple operating systems: Linux, macOS, FreeBSD, others Sander van der Burg nix-processmgmt
  • 3. Nix: development environments We can conveniently install and use all kinds of packages without interfering with the host system’s packages. nix-shell example $ python --version Python 2.7.15 $ node --version node: command not found $ nix-shell -p python3 nodejs $ python --version Python 3.8.5 $ which python /nix/store/z65l1jqvxa58zzwwa3bvglb6asj4y8cv-python3-3.8.5/bin/python $ node --version v12.18.4 $ which node /nix/store/2w6ilfh7zmbz9zqvphgxinmbn3wdqa1b-nodejs-12.18.4/bin/node Sander van der Burg nix-processmgmt
  • 4. Nix package manager: deploying services? Sander van der Burg nix-processmgmt
  • 5. Nix package manager: not a service manager Nix does not manage application services/processes’ life-cycles. Sander van der Burg nix-processmgmt
  • 6. Nix: service deployment integrations There are sister projects that complement Nix with process manage- ment: NixOS. Generates systemd unit files to manage services. Requires you to switch to a fully Nix-managed Linux distribution. nix-darwin. Generates launchd daemon configuration files. Only works on macOS. Sander van der Burg nix-processmgmt
  • 7. Nix: service deployment integrations Nix can also be used to augment other process management solu- tions: Docker. Docker uses a package manager in Dockerfiles for the construction of images. Nix can be used as a replacement for conventional package managers. Nix can be used to fully build Docker images. Not always not a compelling use case for Nix beginners → they typically download prebuilt images from Docker Hub. Docker is built around Linux technologies (e.g. namespaces) and deploys Linux software Sander van der Burg nix-processmgmt
  • 8. nix-processmgmt: A general solution complementing Nix with process management Sander van der Burg nix-processmgmt
  • 9. nix-processmgmt: A general solution complementing Nix with process management Driven by Nix and the Nix expression language Based on simple conventions: function definitions and an attribute set with function invocations Similar to how packages are organized in Nixpkgs Works with process dependencies as well: the framework arranges the ordering, if needed Process-manager agnostic: Integrates with sysvinit scripts, supervisord, systemd, launchd, bsdrc scripts, cygrunsrv Even with systems that are not qualified as process managers: disnix, docker Sander van der Burg nix-processmgmt
  • 10. nix-processmgmt: A general solution complementing Nix with process management Operating system agnostic: Works on NixOS, but it is not a requirement Conventional Linux distros, macOS, FreeBSD, Cygwin Unprivileged user installations A switch to disable creation of users, and changing user permissions No advanced concepts required, such as namespaces and cgroups The solution relies on conflict avoidance, rather than isolation Sander van der Burg nix-processmgmt
  • 11. Example: a simple web application system Sander van der Burg nix-processmgmt
  • 12. Packaging the webapp process (sysvinit, verbose) {createSystemVInitScript, webapp, port ? 5000}: createSystemVInitScript { name = "webapp"; description = "Example web application"; environment.PORT = port; activities = { start = ’’ log_info_msg "Starting Example web application..." loadproc ${webapp}/bin/webapp -D evaluate_retval ’’; stop = ’’ log_info_msg "Stopping Example web application..." killproc ${webapp}/bin/webapp evaluate_retval ’’; restart = "$0 stop; sleep 1; $0 start"; status = "statusproc ${webapp}/bin/webapp"; }; runlevels = [ 3 4 5 ]; } Sander van der Burg nix-processmgmt
  • 13. Packaging the webapp process (sysvinit, declarative) {createSystemVInitScript, webapp, port ? 5000}: createSystemVInitScript { name = "webapp"; process = "${webapp}/bin/webapp"; args = [ "-D" ]; runlevels = [ 3 4 5 ]; environment.PORT = port; } We can also specify the daemon that we want to manage, instead of the activity implementations. Most sysvinit activities (start, stop, restart, reload, status) can be inferred. Sander van der Burg nix-processmgmt
  • 14. Packaging the webapp process (systemd) The following function composes a systemd unit instead of a sysvinit script: {createSystemdService, webapp, port ? 5000}: createSystemdService { name = "webapp"; Unit = { Description = "Example web application"; }; Service = { ExecStart = "${webapp}/bin/webapp"; Environment.PORT = port; Type = "simple"; }; } The framework contains many other process manager- specific abstraction functions: createSupervisordProgram, createLaunchdDaemon, createBSDRCScript etc. Sander van der Burg nix-processmgmt
  • 15. Packaging the webapp process (agnostic) Process manager-agnostic abstraction of the webapp service: {createManagedProcess, webapp, port ? 5000}: createManagedProcess { name = "webapp"; description = "Example web application"; process = "${webapp}/bin/webapp"; daemonArgs = [ "-D" ]; # For process managers that prefer daemons environment.PORT = port; overrides = { sysvinit.runlevels = [ 3 4 5 ]; }; } Invokes the required target-specific abstraction function, e.g. createSystemVInitScript, createSystemdService overrides override/augment process manager-specific parameters You can treat foreground processes and daemons separately, for optimal user experience Sander van der Burg nix-processmgmt
  • 16. Instantiatable webapp processes {createManagedProcess, webapp}: {instanceSuffix ? "", instanceName ? "webapp${instanceSuffix}", port ? 5000}: createManagedProcess { name = instanceName; inherit instanceName; # To ensure a unique PID file name description = "Example web application"; process = "${webapp}/bin/webapp"; daemonArgs = [ "-D" ]; # For process managers that prefer daemons environment.PORT = port; overrides = { sysvinit.runlevels = [ 3 4 5 ]; }; } instanceName: ensures that the daemon command generates unique PID file Outer-function header: parameters that apply to all instances. Inner-function header: instance parameters. A unique combination ensures that multiple instances can co-exist. Sander van der Burg nix-processmgmt
  • 17. Composing process instances { pkgs ? import <nixpkgs> {} , stateDir ? "/var" , forceDisableUserChange ? false, processManager}: let constructors = import ./constructors.nix { inherit pkgs stateDir forceDisableUserChange processManager; }; in rec { webapp1 = rec { # First webapp instance port = 5000; dnsName = "webapp1.local"; pkg = constructors.webapp { inherit port; instanceSuffix = "1"; }; }; webapp2 = rec { # Second webapp instance port = 5001; dnsName = "webapp2.local"; pkg = constructors.webapp { inherit port; instanceSuffix = "2"; }; }; ... } Sander van der Burg nix-processmgmt
  • 18. Composing process instances { pkgs ? import <nixpkgs> {} , stateDir ? "/var" , forceDisableUserChange ? false, processManager}: let constructors = import ./constructors.nix { inherit pkgs stateDir forceDisableUserChange processManager; }; in rec { ... # Nginx with a config that redirects users to the appropriate webapp # instance based on the virtual host header nginx = { pkg = constructors.nginxReverseProxyHostBased { # Process dependencies used to set up redirections in nginx.conf webapps = [ webapp1 webapp2 ]; port = 8080; } {}; }; } Sander van der Burg nix-processmgmt
  • 19. Demo: deploying the system and using it Deploy the process instances as sysvinit scripts: $ nixproc-sysvinit-switch processes.nix Open the first webapp instance (via the Nginx reverse proxy): $ curl -H ’Host: webapp1.local’ http://localhost:8080 Open the second webapp instance (via the Nginx reverse proxy): $ curl -H ’Host: webapp2.local’ http://localhost:8080 Sander van der Burg nix-processmgmt
  • 20. Demo: all kinds of process manager integrations Deploy as systemd units (in a user session): $ nixproc-systemd-switch --user processes.nix Deploy as supervisord programs (stateless): $ nixproc-supervisord-deploy-stateless processes.nix Deploy on FreeBSD as BSD rc scripts: $ nixproc-bsdrc-switch processes.nix Deploy as Docker containers per service (with shared Nix store and host networking): $ nixproc-docker-switch processes.nix Sander van der Burg nix-processmgmt
  • 21. Demo: screenshots Sander van der Burg nix-processmgmt
  • 22. Other features of nix-processmgmt Automatic creation of users and groups (createCredentials function) nixproc-id-assign: Automated assignment of unique IDs for TCP/UDP ports, UIDs, GIDs to process instances Using Disnix as a process orchestrator (works on all platforms where Nix/Disnix is supported) Sander van der Burg nix-processmgmt
  • 23. Combining nix-processmgmt with Disnix We can use any process manager, do distributed deployment and combine processes with non-process based services (e.g. Java web applications in an Apache Tomcat container): Sander van der Burg nix-processmgmt
  • 24. Example services packaged for nix-processmgmt HTTP/application servers: Apache HTTP server Nginx Apache Tomcat Database: PostgreSQL MariaDB/MySQL MongoDB InfluxDB Misc: Docker Supervisord svnserve Sander van der Burg nix-processmgmt
  • 25. Future work Deploy containers with multiple processes (WIP) Mutable service containers (WIP) s6 / s6-rc backend Work on a test strategy for services Maybe write an RFC? Sander van der Burg nix-processmgmt
  • 26. Availability https://github.com/svanderburg/nix-processmgmt The implementation is still a work in progress and relies on devel- opment versions of dependencies! Sander van der Burg nix-processmgmt
  • 27. References Blog posts: A Nix-based functional organization for managing processes, https://sandervanderburg.blogspot.com/2019/11/ a-nix-based-functional-organization-for.html A declarative process manager-agnostic deployment framework based on Nix tooling, https://sandervanderburg.blogspot.com/2020/02/ a-declarative-process-manager-agnostic.html Deploying container and application services with Disnix, https://sandervanderburg.blogspot.com/2020/04/ deploying-container-and-application.html Sander van der Burg nix-processmgmt
  • 28. References Blog posts: Using Disnix as a simple and minimalistic dependency-based process manager, https://sandervanderburg.blogspot.com/2020/06/ using-disnix-as-simple-and-minimalistic.html Experimenting with Nix and the service management properties of Docker, https://sandervanderburg.blogspot.com/2020/08/ experimenting-with-nix-and-service.html Assigning unique IDs to services in Disnix deployment models, https://sandervanderburg.blogspot.com/2020/09/ assigning-unique-ids-to-services-in.html Sander van der Burg nix-processmgmt
  • 29. References E. Dolstra, The Purely Functional Software Deployment Model, PhD thesis, Chapter 9, https://edolstra.github.io/pubs/phd-thesis.pdf Sander van der Burg nix-processmgmt
  • 30. Questions Sander van der Burg nix-processmgmt