Import "packages.nix" file inside user declaration

I’m new to nix and trying to create my own custom nix configuration in a modular way so that I can easily copy/paste/delete things as needed. The issue I’m facing at this point is somehow relocating the ‘packages’ portion of my user declaration (in a username.nix file) to a separate file called “username_packages.nix”. Is this even possible? Thanks for the help in advance :slight_smile:

that sounds like it should be doable, but I don’t exactly understand what you mean, so maybe you could provide the code snippets from the relevant files?

I have a file structure like this:

/etc/nixos/
configuration.nix
nixos/users/
users.nix
users/joshua/
user.nix
packages.nix

my configuration.nix includes an import section (There are a lot of imports for the sake of modularity):

  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
      #Configure system.
      ./system/system.nix
      #Configure users.
      ./users/users.nix
    ];

and users.nix has

{ config, ... }:

{
  imports =
    [ #Configure users.
      ./joshua/user.nix
    ];
}

And user.nix looks like this:

{ config, pkgs, ... }:
{
  users.users.joshua = {
    isNormalUser = true;
    description = "Joshua";
    extraGroups = [ "networkmanager" "wheel" ];
    packages = with pkgs; [
      kate
    ];
  };
}

What I’d like to do is strip out the packages portion and import ./packages.nix and declare user packages there.

Sorry if the formatting isn’t great

sorry if I am just not reading this correctly, but do you want to define custom packages or just move users.users.joshua.packages into a different file than users.users.joshua?

because the latter one would be very easy

# user.nix
{ config, pkgs, ... }:
{
  users.users.joshua = {
    isNormalUser = true;
    description = "Joshua";
    extraGroups = [ "networkmanager" "wheel" ];
  };
}
# packages.nix
{ config, pkgs, ... }:
users.users.joshua.packages = with pkgs; [
   kate
];

should do the trick

Ok, that makes sense. Sorry for posting such a noob question :sweat_smile: , I appreciate the help

no worries, that’s why I am here
just mark the answer as the solution, so the question is closed and others can find the answer