Import a pkgs list or set as variable from external file


i would like to be flexible with the use of nixos and home-manager regarding the installed packages.

So I would like to import one or multiple variables -each are list or set - from an external file.
But it should be clean and simple / usable in configuration.nix and home.nix (so without parameter like “home.packages = with pkgs; [” or “environment.systemPackages = with pkgs; [”)
To change the channel from nixos to unstable it is needed to not specify the prefix/source.

I thought that I could import the pkgs list if I would define variables in the “let part” of the external script but that doesnt work yet .


{ config, pkgs, ... }:
  os_pkgs = with pkgs; [ htop ]; 
  os_pkgs_file = import ./pkgs_test.nix pkgs ; 
  #os_pkgs_file_read= builtins.readFile ./pkgs_test.nix ;    
  imports = [     ./pkgs_test.nix   ] ;  # Imports a set NOT a list 
  nixpkgs.config.allowUnfree = true;

  programs.home-manager.enable = true;

  home.packages = with pkgs; [
  ++ os_pkgs
  ++ pkgs_gr_named # variable defined in external file 


{ config, pkgs, ... }:
let     pkgs_gr_named = with pkgs; [jp        git-backup    ]; 
in {}

I get undefined variable ‘pkgs_gr_named’

You can not access let bindings from another file. Just move that variable to the returned set, and from the importing file use a qualified access to that value.

++ (import ./file.nix pkgs).pkgs_gr_named