I would like to limit usage of a system on a per user basis. Since Systemd has native support for cgroups, I think using user slices is the way to go.
The problem is: I can't figure out how to set individual limits. I can edit the user.slice unit file to set limits that collectively apply to all user slices, but I don't see a way to template these user slices.
I can override these settings for individual users by creating a user-(uid).slice unit file, but I would prefer to apply limits by default to all users.
Is it possible to set default limits?
Edit: After poking around some more, I found the unit files for the user slices are created in /run/systemd/system/.
[foo@bar Downloads]$ systemctl cat user-1000.slice
# /run/systemd/system/user-1000.slice
# Transient stub
# /run/systemd/system/user-1000.slice.d/50-After-systemd-logind\x2eservice.conf
[Unit]
After=systemd-logind.service
# /run/systemd/system/user-1000.slice.d/50-After-systemd-user-sessions\x2eservice.conf
[Unit]
After=systemd-user-sessions.service
# /run/systemd/system/user-1000.slice.d/50-Description.conf
[Unit]
Description=User Slice of foo
# /run/systemd/system/user-1000.slice.d/50-TasksMax.conf
[Slice]
TasksMax=infinity
These files are constructed by this segment of code in systemd: https://github.com/systemd/systemd/blob/401e33ed56f3cd3736bbab02ca6eb31aa592cf53/src/login/logind-dbus.c#L2928-L2998
The creation of this file seems to be hard coded into the systemd source and doesn't allow for templates.