Clear list - nix syntax or?

I saw this code: https://github.com/NixOS/nixpkgs/blob/2d082d7f035bb47623f72cd5d8c08cf5b5435850/nixos/tests/gnome.nix#L37

      systemd.user.services = {
        "org.gnome.Shell@wayland" = {
          serviceConfig = {
            ExecStart = [
              # Clear the list before overriding it.
              ""
              # Eval API is now internal so Shell needs to run in unsafe mode.
              "${pkgs.gnome.gnome-shell}/bin/gnome-shell --unsafe-mode"
            ];
          };
        };
      };

What I don’t understand is how the empty string "" can have the ability to “Clear the list before overriding it”?

And related, where is or should this be documented?

1 Like

That is systemd specific.

All ExecStart lines in a unit will be ran one after the other, though by specifiying a single empty entry, all previous entry gets deleted from systemds internal unit representation.

Unless Type= is oneshot , exactly one command must be given. When Type=oneshot is used, zero or more commands may be specified. Commands may be specified by providing multiple command lines in the same directive, or alternatively, this directive may be specified more than once with the same effect. If the empty string is assigned to this option, the list of commands to start is reset, prior assignments of this option will have no effect. If no ExecStart= is specified, then the service must have RemainAfterExit=yes and at least one ExecStop= line set. (Services lacking both ExecStart= and ExecStop= are not valid.)

https://www.freedesktop.org/software/systemd/man/systemd.service.html

3 Likes

The nix way of doing it is probably to use lib.mkOverride so that you actually override the existing nixos module’s configuration. I think using this systemd detail instead of nix’ module composition is a hack.

That said, if this composes down to a systemd override specific for that @ rule, and there is no original systemd unit for this, obviously that’s not possible.

That said, if this composes down to a systemd override specific for that @ rule, and there is no original systemd unit for this, obviously that’s not possible.

I wonder where it gets defined. If i remove the empty sting it has more than one ExecStart, but I don’t know where it comes from

machine # [   29.276660] systemd[967]: org.gnome.Shell@wayland.service: Service has more than one ExecStart= setting, which is only allowed for Type=oneshot services. Refusing.
machine # [   29.650079] systemd[967]: org.gnome.Shell@wayland.service: Cannot add dependency job, ignoring: Unit org.gnome.Shell@wayland.service has a bad unit file setting.