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?


4 Answers 4


This file is indeed specific to NixOS and it is created automatically when installing NixOS. That said, there are workarounds.


You can manage a "nix shell" environment with a nix expression like the below:


{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
  buildInputs = [ pkgs.bash pkgs.zsh pkgs.curl pkgs.wget ];

And then to 'enter' this environment run: nix-shell shell.nix


You can replicate the workflow described in the [NixOS docs](nixos-rebuild switch) for the configuration.nix file by using the tool suggested by Ben Creasy. home-manager.

It has an option for non-NixOS linux distros [1]:

targets.genericLinux.enable = true;


automatically set some environment variables that will ease usage of software installed with nix on non-NixOS linux (fixing local issues, settings XDG_DATA_DIRS, etc.):

You can use home-manager to manage your packages/programs declaratively. Here's a minimal example of a home.nix from the documentation:

{ pkgs, ... }:

  home.packages = [

  programs.emacs = {
    enable = true;
    extraPackages = epkgs: [

  programs.firefox = {
    enable = true;
    profiles = {
      myprofile = {
        settings = {
          "general.smoothScroll" = false;

  services.gpg-agent = {
    enable = true;
    defaultCacheTtl = 1800;
    enableSshSupport = true;

  programs.home-manager = {
    enable = true;
    path = "…";

home-manager switch to then apply any changes.

  1. https://nixos.wiki/wiki/Home_Manager#Usage_on_non-NixOS_Linux

I manage my dotfiles on Ubuntu using Nix. I run this script which is just a wrapper around this installer.

The installer versions the dotfiles into a Nix package, and uses GNU stow to link them back to your home directory.

It is probably a bit complex for most people, but I use it to manage dotfiles between NixOS, Ubuntu and OSX.

  • 3
    Please post code instead of links—I'm trying to access the links but they 404.
    – fnune
    Nov 24, 2022 at 12:42
  • Voting to delete if it is not updated
    – ocodo
    Sep 20, 2023 at 7:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .