Hi ya’ll, I’m trying to run a service that executes a script as root. Having no luck.
I’m trying to make a test script to blink the builtin LED on a Raspberry Pi 4. Only root has access to these kinds of devices.
This is my sd-image.nix, root-ssh.nix just has some mDNS and SSH keys inside.
{ config, pkgs, ... }:{
imports = [
<nixpkgs/nixos/modules/installer/cd-dvd/sd-image-raspberrypi4.nix>
./root-ssh.nix
];
config.networking.hostName = "mo";
config.users.users.sprout = {
isNormalUser = true;
extraGroups = [ "wheel" ];
};
config.networking.wireless.enable = false;
config.systemd.services.led-test = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target.service" ];
description = "Test LED";
serviceConfig = {
Type = "simple";
User = "root";
Group = "root";
PermissionsStartOnly = true;
DynamicUser = true;
ExecStart = pkgs.writeScriptBin "blink" ''
#!${pkgs.stdenv.shell}
echo none > /sys/class/leds/led0/trigger
while true; do
echo 1 > /sys/class/leds/led0/brightness
sleep 0.5
echo 0 > /sys/class/leds/led0/brightness
sleep 0.5
done
'';
};
};
}
Pretty sleep deprived, so I’ve just slapped a bunch of things into my service - though it sounds like there isn’t actually a way to do this? (I event tried to sneak in the ExecStart ‘+’ → ExecStart=+/nix/store/z7455b2injbwy3l6kjqq5kw00fpl56fw-blink)
Any thoughts? I just want some blinkin lights ![]()