Add environment.systemPackages to a flake

Just in general, how do you install packages from environment.systemPackages in a flake or module? These flakes would be imported into home-manager.

Can you clarify your question? What does it mean to install something “from” environment.systemPackages?

Like you do in your nixos configuration,

environment.systemPackages = [
  pkgs.wget
  pkgs.vim   
];

I’d like to be able to install packages inside a flake or module and import that in home-manager.

Modules seem like the right fit for this. You usually don’t want each small composable thing to be its own flake.

I think the home-manager equivalent is home.packages (I personally use only environment.systemPackages for this purpose).

home-manager modules are nothing special, they pretty much work the same as NixOS modules

# vim_module.nix
{ pkgs, ... }:
{
  home-manager.users.myusername.home.packages = [ pkgs.vim ];
}
# wget_module.nix
{ pkgs, ... }:
{
  home-manager.users.myusername.home.packages = [ pkgs.wget ];
}
# home.nix or whatever
{
  imports = [ ./vim_module.nix ./wget_module.nix ];
}

This should work.

It says the option home-manager does not exist.

You’ll need to show the complete code you’re using, otherwise this is going to take forever. How are you using home-manager (as in, which of the 3 ways defined here)?

NixOS module … this is a nixos setup.

home.nix

{ config, pkgs, nixpkgs, ... }:

{
  imports = [ ~/flakes/rice/rice.nix ];
  # Home Manager needs a bit of information about you and the
  # paths it should manage.
  home.username = "tibegato";
  home.homeDirectory = "/home/tibegato";  
  home.stateVersion = "23.11";

  # Let Home Manager install and manage itself.
  programs.home-manager.enable = true;
}

rice.nix: ~/flakes/rice/rice.nix ← copy of flake.nix

{ pkgs, ... }:
{
  home-manager.users.tibegato.home.packages = [ pkgs.wallust ];
}

You need to follow the setup manual, and import the home-manager module into your NixOS config. See here for channels and here if you are using flakes for your NixOS configuration.

Notably, you’re missing imports = [ <home-manager/nixos> ]; or the flakes equivalent.

Think, I got it working. I re-did all the channel stuff and such. I don’t know, if my system is fully configured like it’s supposed to be. But:

rice.nix ← ~/modules/rice.nix <— just a test module. I’ll need to make sure I can setup properties and everything. That’s next.

{ pkgs, ... }:

{
    home.packages = [
      pkgs.wallust
      pkgs.htop
    ];
}

home.nix

{ config, pkgs, nixpkgs, ... }:

{
  imports = [
    ~/modules/rice.nix
  ];

  # Home Manager needs a bit of information about you and the
  # paths it should manage.
  home.username = "tibegato";
  home.homeDirectory = "/home/tibegato";  
  home.stateVersion = "23.11";

  # Let Home Manager install and manage itself.
  programs.home-manager.enable = true;
}

and I guess you need to do home-manager switch and not home-manager build.