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.
ros2_main_dev_container

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:

systemd={
    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";};
      };
    };
    user.services.polkit-gnome-authentication-agent-1 = {
      description = "polkit-gnome-authentication-agent-1";
      wantedBy = [ "graphical-session.target" ];
      wants = [ "graphical-session.target" ];
      after = [ "graphical-session.target" ];
      serviceConfig = {
        Type = "simple";
        ExecStart =
          "${pkgs.polkit_gnome}/libexec/polkit-gnome-authentication-agent-1";
        Restart = "on-failure";
        RestartSec = 1;
        TimeoutStopSec = 10;
      };
  };};