NixOS/nixpkgs — pull request #4432 by ts468 (2014-10-09 08:43:19+00:00)
Title: Add infrastruture: vimProfile

VimProfile allows to wrap vim with different configurations.
A configuration is composed by enabling and customizing pre-defined modules.
A module is a set of vim plugins and vimrc statements that are tightly linked.
Configurations are hierarchical and can inherit from each other.
The base of each hierarchy of configurations is a distingued default configuration.
Enabled vim configurations appear as normal package in nix, and have to be
installed accordingly.

The vimProfiles are declared either for system wide installations in
/etc/nixos/configuration.nix, or for each user in ~/.nixuser/configuration.nix.

An example for a vim configuration, here the content of ~/.nixuser/configuration.nix:

{ config, pkgs, ... }:
with pkgs;
{
programs.vim =
{ enable = true;
leader = " ";
general.enable = true;
statusline.enable = true;
profiles =
{ # Haskell configuration
hvim =
{ enable = true;
exec = { package = pkgs.vim_configurable; bin = "bin/vim"; };
search.enable = true;
# leader can be overwritten independently for each module
search.leader = "|";
text.enable = true;
sidebar.enable = true;
# overwrite default key binding
sidebar.toggleUndo = "uu";
completion.enable = true;
haskell.enable = true;
};
# graphical Haskell configuration
hqvim =
{ enable = true;
# set the name to call the wrapped vim
name = "Hvim";
parent = "hvim";
exec = { package = pkgs.qvim; bin = "bin/qvim"; };
# just as an example that inherited modules can also be disabled
search.enable = false;
};
# same configuration as for default, but with qvim
qvim =
{ # don't make that profile installable
enable = false;
exec = { package = pkgs.qvim; bin = "bin/qvim"; };
# if no name attribute is given, the attribute name
# of the configuration is taken: "qvim"
};
# alias declaration for qvim
gvim =
{ enable = true;
# inherit from a configuration by its attribute name
# you can inherit from a disabled configuration as well
parent = "qvim";
# add statement to the generated vimrc; it is inserted
# before any module statement
vimrc = ''
" Leader key timeout
set tm=2000
'';
};
};
};
}

The declaration above defines the following packages in nix:
"vimProfile.hvim", "vimProfile.hqvim" and "vimProfile.gvim".
When the default profile is enabled, it is automatically installed with
the package "vim".
An un-wrapped vim package is always available with "vimPlain".

-------------------

Internals of the implementation:

A new file "nixos/modules/nixuser-module-list.nix" is added.
The file lists modules that are made available both for system configuration
and for user configuration.
The file is imported by "nixos/modules/module-list.nix" and is used in
"pkgs/top-level/all-packages.nix".

A new user specific configuration file is introduced.
It is located in "~/.nixuser/configuration.nix".
The idea is to have a declarative approach for defining the user environment
at some point. The configuration file acts as the input of a module evaluation
system, similar to "/etc/nixos/configuration.nix" for the NixOS configuration.

The configuration modules provided with vimProfile reduce to "nixpkgs.config"
attributes, which are added to the configuration of "~/.nixpkgs/config.nix".