Home-manager rofi cannot be launched from i3

Hi, I am using Home-manager on Ubuntu 20.04.

I am porting my config using nix and home-manager. Now my configs includes my WM which is i3 and my launcher which is rofi.

When I login for the first time rofi seem to not being able to launch with the keybinding, though other home-manager installed programs like vscode can be launched. Also, I can launch it manually via the terminal and it will work. What is weird is that if I logout and login, the keybinding to launch rofi will now work.

Here is the i3 nix file

{ config, lib, pkgs, ... }:

{
  home.packages = with pkgs; [
    # For shortcuts
    brightnessctl
    playerctl

  ];
  xsession = {
    enable = true;
    windowManager.i3 = { enable = true; };
  };

  xdg.configFile.i3.source = ./i3;
}

The i3 config

bindsym $mod+m exec code
bindsym $mod+n exec which rofi >> $HOME/wich-rofi

bindsym $mod+space exec --no-startup-id rofi -show >> $HOME/rofi-exec
bindsym $mod+w exec --no-startup-id rofi -show window -modi window 

The rofi one

  home.packages = with pkgs; [ fira-code ];
  xdg.configFile."rofi/themes".source = ./themes;

  programs.rofi = {
    enable = true;
    font = "FiraCode NF 12";
    theme = "slate";
    plugins = [
      pkgs.rofi-emoji
      pkgs.rofi-calc
      pkgs.rofi-power-menu
    ];

    extraConfig = {
      modi = "drun,filebrowser,window";
      show-icons = true;
      sort = true;
      matching = "fuzzy";
    };
  };

The $HOME/rofi-exec file is empty when mod+space key is pressed.
When mod+n is pressed, $HOME/wich-rofi contains the string “/home/user/.nix-profile/bin/rofi”, so the path to the rofi executable is found.

I know this is not that much of debugging information but I am a bit lost on how to debug this since I am new to the nix/home-manager ecosystem. I think it may be an Path or environment variable problem but I am not sure.

I am wondering why when I logout/login it works again? How to make it work on the first login? And finally, is it okay to manage your DE or WM via home-manager even if you are not on nixos?