So far, I have been trying out the Nix package manager by nix-env -i
installing packages. Now, I would like to manage that with a ~/configuration.nix
, like the example here, so that I can version it in my dotfiles. Is there a way to generate this configuration from my current environment?
All of the information that I can find about user or system level configuration is specific to NixOS, and assumes that I have run nixos-generate-config
to create the file. This tool is not available from nixpkgs, which makes me think that it is designed only to create a NixOS install, not for general config-file creation.
Also, why doesn't the Nix package manager create this file when it is installed? How do Nix (not NixOS) users configure their installed software, such as Vim plugins, without this file?
Best Answer
This file is indeed specific to NixOS and it is created automatically when installing NixOS. That said, there are workarounds.
One of them is described in https://nixos.org/nixpkgs/manual/#sec-declarative-package-management in the Nixpkgs manual. (Added in this PR.)
Please note that the overlays mechanism came along since then, and according to Chapter 12. Overlays: "Overlays are similar to other methods for customizing Nixpkgs, in particular the
packageOverrides
attribute described in Section 6.5, “Modify packages viapackageOverrides
”. Indeed,packageOverrides
acts as an overlay with only the super argument. It is therefore appropriate for basic use, but overlays are more powerful and easier to distribute."It seems that there was also a work-in-progress for a user-side declarative configuration but it hasn't been updated in a while: https://github.com/NixOS/nixpkgs/pull/9250
See also the Declarative package management for normal users discussion on the NixOS Discourse.