Question about nixpkgs/config.nix

I’m trying to build my ~/.config/nixpkgs/config.nix file so that I would be able to install all packages I use with single command.

So according to “Nixpkgs Manual” I can use packageOverrides to define environment

 packageOverrides = pkgs: with pkgs; {
    myPkgs = pkgs.buildEnv {
      name = "my_pkgs";
      paths = [
        gdb
        git
        zsh
      ];
    };
  };
}

and then install it with nix-env -iA nixpkgs.myPkgs.

I also want to override Vim package to use python3 and the easiest way to do it as learned is:

{
  packageOverrides = pkgs: with pkgs; {
    myVim = pkgs.vim_configurable.override {
        python = pkgs.python3;
    };
}

so I can install it with nix-env -iA nixpkgs.myVim.

But what I can’t figure out is how to include myVim in myPkgs so that installing myPkgs will install myVim too.

Worth mentioning that I’m on non-NixOS distro and also I prefer not to use Home Manager if I can manage everything with nixpkgs config file.

This probably why they always say that packageOverrides don’t compose well.

You could try to put both in the same override or use overlays instead.

Anyway. What are your reasons against home-manager?

How can I put them both into same override?

Regarding home-manager, I have no particular reason against it but just don’t want to introduce new dependency without reason. I’m using Nix as rather “conventional” package manager which for me has great advantage of being distro-independent. My environment consists of small number of developer tools, and I don’t want Nix to manage my config files, python packages, vim plugins etc. What additional benefit does home-manager have for me?

As I said, I never used overrides, but naïve as I am, I’d try the following:

packageOverrides = pkgs: with pkgs; rec {
  myVim = ...;

  myPkgs = pkgs.buildEnv {
    name = "my_pkgs";
    paths = [
      gdb
      git
      zsh
      myVim
    ];
  };
};

Or if you don’t want to use a recursive attrset, use a let binding.

Though I’d really suggest using an overlay instead.

what you probably want is an overlay(s), they can be composed in ways that you’re describing Overlays - NixOS Wiki

Taking a step back though, doing nix-env -iA nixpkgs.myVim seems more like you’re trying to add programs to your user environment. I would highly recommend to use home-manager for this.

Most seem to do, though it seems as if the op wouldn’t want to use the config management parts of it, and only using home.packages wouldn’t be that much different from what they do now I think…

I really can’t think of any USP for home manager which wasn’t configuration management, which the op actively doesn’t want to use as they said.

I haven’t had a great experience using nix-env to manage my user env, and I found home-manager to be refreshing.

I recommend using home-manager, if someone prefers not to, then that’s their choice to make. :slight_smile:

1 Like

I can second what you said.

I’ve heard good things about home-manager but haven’t checked it out yet. Instead I use a variant of @LnL7’s overlay (what I’m actually using is a further refinement on that but I haven’t posted the new version anywhere). With this overlay you just edit the packages referred to in the userPackages set and run nix-rebuild and it replaces your current environment with the new one.

If you have the inclination to do so I’d suggest checking out home-manager, but this overlay is a lightweight way to get declarative package sets. I only haven’t gone down the home-manager route myself yet because I don’t have the time to mess with a system that works.

Edit: I just posted my updated overlay to the same gist.

2 Likes

I would like to use something like home-manager but way less opinionated. (Or maybe with my opinions :slight_smile: )

home-manager just re-uses the nixos module system, but at a user level. You could write your own modules.

I would rewrite all modules, to be honest. Indeed I am thinking about it in that exact moment!
As an example, I have my own externally maintained Emacs init.org file (yes, literate org files!). It is almost impossible to put it in the home-manager.

(Please, don’t think I think HM is poorly built. It just isn’t ideal for me.)