Unable to install packages after fresh installation

Hi,

I’ve installed nixos for the first time, following the installation guide, but I’m having problems installing packages after logging in with my new user for the first time.

As soon as I login, I see this: “No directory, logging in with HOME=/”.

If I try to run nix-env -qaP \* I get: “error: getting information about ‘//.nix-defexpr’: No such file or directory”. What I expect to see instead is a list of packages.

From what I can see, my user does not have a home directory. There’s nothing in /home.

Did I miss anything while installing? Any pointers would be greatly appreciated.

I’ve installed nixos version 19.09.2395.02f2241354a in a virtualbox machine. These are the steps I went through to install:

1. Sudo: `sudo -i`
1. `lsblk`
1. `parted /dev/sda -- mklabel msdos`
1. `parted /dev/sda -- mkpart primary 1MiB -10GiB`
1. `parted /dev/sda -- mkpart primary linux-swap -10GiB 100%`
1. `mkfs.ext4 -L nixos /dev/sda1`
1. `mkswap -L swap /dev/sda2`
1. `mount /dev/sda1 /mnt`
1. `swapon /dev/sda2`
1. `nixos-generate-config --root /mnt`
1. `vi /mnt/etc/nixos/configuration.nix`
    a. Uncomment the line `boot.loader.grub.device = "/dev/sda";`
    b. Write and quit
1. `nixos-install`
1. Enter new root password
1. `reboot`
1. Login to root
1. `useradd stian`
1. `passwd stian`
1. `usermod -aG wheel stian`
1. Confirm with `groups stian`
1. `shutdown now`
1. Start the machine and login with stian
1. Try to install something: `nix-env -i neovim`. You'll get the error "error: getting information about '//.nix-defxpr': No such file or directory". <https://github.com/NixOS/nix/issues/650> has a suggestion (`sudo nix-channel --update`) but that doesn't solve it.

You should really add your user declaratively in the configuration.nix as part of the install. Then just set the password for that user after the install.

Alternatively, when you create your user with useradd, create and set the /home directory for that user. I think the flag for that is -m but you might verify that.

nixos really wants you to think about the way you manage the system differently than other distros. A big part of the value of nixos comes from the repeatability of being able to do everything declaratively. Even your install of neovim would probably be better done in your configuration.nix

1 Like

Thank you very much! Adding the user to the configuration file instead solved it :slight_smile:

1 Like