Title: Making systemd services run idle: Automatic Updates in NixOS Laptop
In this article, we will discuss how to make systemd services run idle and set up automatic updates on a NixOS laptop.
Introduction
Automatic updates are crucial for maintaining the security and functionality of your system. In this guide, we will show you how to configure systemd services to run idle and set up automatic updates on your NixOS laptop.
Prerequisites
- A NixOS laptop with systemd installed
- Basic understanding of NixOS and systemd
Configuring systemd services to run idle
To make a systemd service run idle, we need to modify its service file.
- Open the service file in your preferred text editor:
sudo nano /etc/systemd/system/<service_name>.service
Replace <service_name> with the name of your service.
- Add the
IdleSec=directive to the[Service]section:
[Service]
IdleSec=infinity
The IdleSec= directive sets the maximum time a service can stay idle before systemd starts sending SIGCONT signals to the service to check if it's still needed. Setting it to infinity makes the service idle indefinitely.
-
Save and close the file.
-
Reload systemd manager configuration:
sudo systemctl daemon-reload
- Restart the service:
sudo systemctl restart <service_name>
Setting up automatic updates
To set up automatic updates, we will use the nix-channel-refresh and nix-upgrade commands.
- Open your NixOS configuration file:
nano /etc/nixos/configuration.nix
- Add the following lines to the
systemsection:
services.systemd.systemdServices.autoUpgrade = true;
services.systemd.systemdServices.autoUpgradeDelay = 3h;
The autoUpgrade directive enables automatic updates for systemd services, and the autoUpgradeDelay directive sets the delay between each update check.
-
Save and close the file.
-
Run
nixos-rebuild switchto apply the changes:
sudo nixos-rebuild switch
After rebooting your system, your systemd services should now run idle, and automatic updates should be enabled.
Summary
- To make a systemd service run idle, modify its service file and add the
IdleSec=directive. - To set up automatic updates, enable the
autoUpgradedirective in your NixOS configuration file and adjust theautoUpgradeDelay.