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¶
Create a file called hello-service.nix in your ~/.config/system-manager/ folder:
Let's break down what each part does:
systemd.services.say-hello: Creates a service named "say-hello".enable = true: Activates the service.wantedBy = [ "system-manager.target" ]: Starts the service when System Manager activates.Type = "oneshot": Runs once and exits.RemainAfterExit = true: Keeps the service marked as "active" after the script finishes.script: 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 if 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.