Nix expression for home packages

Sébastien M nixos1@discoursemail.com writes:

Sorry if this is a basic question, but I could not find the answer in
Nix documentation.

I would like to install a set of “home” packages with Nix on several
(Mac and Linux) computers. Instead of installing these packages with
nix-env -i package1, nix-env -i package2, etc., I would prefer to
write a nix expression containing the list of packages that I want to
install. How can I do that?

I use ‘buildEnv’, with something like the following:

{ buildEnv, pkg1, pkg2, pkg3 }:

buildEnv {
  name  = "my-favourite-packages";
  paths = [ pkg1 pkg2 pkg3 ];
}

If this is in a file like ./my-favourite-packages.nix then we can do
‘(import {}).callPackage ./my-favourite-packages.nix {}’, e.g.
as the ‘-E’ argument to nix-env. An alternative is to use a file like
~/.nixpkgs/config.nix or ~/.config/nixpkgs/config.nix