Your First Systemd Service¶
This tutorial walks you through creating and managing a systemd service with System Manager.
Prerequisites¶
- System Manager initialized (see Getting Started)
- Basic familiarity with Nix syntax
What You'll Build¶
A simple "hello world" systemd service that runs when System Manager activates your configuration.
Step 1: Create a Service Module¶
In your ~/.config/system-manager folder, create a file called hello-service.nix:
Let's break down what each part does:
systemd.services.say-hello- Creates a service named "say-hello"enable = true- Activates the servicewantedBy = [ "system-manager.target" ]- Starts the service when System Manager activatesType = "oneshot"- Runs once and exitsRemainAfterExit = true- Keeps the service marked as "active" after the script finishesscript- The actual command to run
Step 2: Add the Module to Your Flake¶
Edit your flake.nix and add the new module:
Step 3: Apply the Configuration¶
Run System Manager to activate your new service:
Step 4: Verify It Worked¶
Check the journal to see your service ran:
You should see output like:
Step 5: Check the Generated Service File¶
System Manager created a systemd unit file at /etc/systemd/system/say-hello.service. You can view it with:
Next Steps¶
- Learn about service configuration options in the reference
- See the timer example for scheduled services
- Explore the nginx example for a real-world service