How to create Folders directly with the config.nix?

I’m normally a robotics software developer, where ros2 is very important. However, most of the ros2 stuff only works on ubuntu, so I need to use a dev container if I’m going to use it everywhere.
So I’ve created a gitlab repository with bash scripts to prepare the environment for my container and start it. I thought maybe some parts of these scripts could be included in my config.nix.

do you know for example, how to include the following into the config.nix?

mkdir -p ~/ros2_ws/src
mkdir -p ~/microros_ws/src
mkdir -p ~/ros2_debug/src

I’ve tried the following, but it doesn’t work:

config.system.activationScripts.makeVaultWardenDir = lib.stringAfter [ "~" ] ''
    mkdir -p ~/ros2_ws/src
    mkdir -p ~/microros_ws/src
    mkdir -p ~/ros2_debug/src

systemd-tmpfiles is the way to do this, and can be configured with systemd.tmpfiles.settings: NixOS Search

Despite the name, it can be (and often is) used to create files/directories that are intended to be permanent.

Note that in you need to should use absolute paths (activation happens as root, so if I’m not mistaken, ~ might not resolve to what you expect) and might also need to chown afterwards.
Other option: Pull in the home-manager module and use home-manager to generate the dirs for the desired user.

Seems to work. At least recompiling my operating system with sudo nixos-rebuild switch did not throw any errors. It looks like this for me now:

    tmpfiles.settings = {
      "ros2_docker_folders" = {
        "${config.users.users.azrael.home}/ros2_ws/src" = {d.mode = "0777";};
        "${config.users.users.azrael.home}/microros_ws/src" = {d.mode = "0777";};
        "${config.users.users.azrael.home}/ros2_debug/src"= {d.mode = "0777";};
    }; = {
      description = "polkit-gnome-authentication-agent-1";
      wantedBy = [ "" ];
      wants = [ "" ];
      after = [ "" ];
      serviceConfig = {
        Type = "simple";
        ExecStart =
        Restart = "on-failure";
        RestartSec = 1;
        TimeoutStopSec = 10;