Installing home-manager on ubuntu

Hi everyone,

I hope I can get some help here.

I was trying to install home manager with flake on a ubuntu server but then I notice the same method I used on my local machine does not work anymore.

Environment

  • Ubuntu 22.04
  • Nix latest (Multi-user installation)
  • add experimental-features = nix-command flakes to /etc/nix/nix.conf

Installation

Installing Nix was pretty straight forward. After that I log out and log in again to the server. Then I copy the same example file on official doc.

I use the same flake file in the example and change the user name to ubuntu which is the current username of my server.

Then I run below commands

nix build --no-link .#homeConfigurations.ubuntu.activationPackage

"$(nix path-info .#homeConfigurations.ubuntu.activationPackage)"/activate

The first command run successfully but the second one returns an error

$ "$(nix path-info .#homeConfigurations.ubuntu.activationPackage)"/activate                                       
Starting Home Manager activation
error: opening lock file '/nix/var/nix/profiles/per-user/ubuntu/home-manager.lock': No such file or directory
FAIL

I am not too sure why the directory was not created. I also tried nix-shell '<home-manager>' -A install but I ended up with more errors.

$ nix-shell '<home-manager>' -A install                                                                          
error:
       … while calling the 'import' builtin

         at /nix/store/5s2sfki1h57d1iyp839v00h01ckbzxbs-home-manager/home-manager/default.nix:1:10:

            1| { pkgs ? import <nixpkgs> { } }:
             |          ^
            2|

       … while calling the 'findFile' builtin

         at /nix/store/5s2sfki1h57d1iyp839v00h01ckbzxbs-home-manager/home-manager/default.nix:1:17:

            1| { pkgs ? import <nixpkgs> { } }:
             |                 ^
            2|

       error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)

       at «none»:0: (source not available)
FAIL

I followed the same doc and run the same command to install nix and home manager successfully on my host machine (PopOS).

Can anyone please advise what to do next?

Thank you

It looks like the profile is pointing to /home/ubuntu/.local/state/nix/profiles/profile

ubuntu@fourth: ~
$ ls -l ~/.nix-profile
lrwxrwxrwx 1 ubuntu ubuntu 46 Mar  2 14:29 /home/ubuntu/.nix-profile -> /home/ubuntu/.local/state/nix/profiles/profile

On my host, it is pointing to /nix/var/nix/profiles/per-user/$<username>/profile

It seems to me there might be some issue with the multi-user installation script

an you please run nix show-config|grep xdg and show its output?

Also please tell us the value of XDG_STATE_HOME (printenv XDG_STATE_HOME), just in case.

I have my thoughts about use-xdg-base-directories…

Though also, I don’t think thats related to the original issue.

/home/ubuntu/.local/state/nix/profiles/profile is probably just a symlink as well.


To debug your initial problem:

  • Do other nix commands work?
  • Is there a reason for not using the home-manager CLI?
  • Is the demon running?

Thanks for the reply.

  • please run nix show-config|grep xdg and show its output?

    $ nix show-config|grep xdg
    use-xdg-base-directories = false
    
  • tell us the value of XDG_STATE_HOME ( printenv XDG_STATE_HOME )
    I don’t have this set.

    $ printenv | grep XDG
    XDG_SESSION_ID=5083
    XDG_RUNTIME_DIR=/run/user/1001
    XDG_SESSION_TYPE=tty
    XDG_SESSION_CLASS=user
    
  • Do other nix commands work?
    Not really. Even after reinstalling.

    Alright! We're done!
    Try it! Open a new terminal, and type:
    $ nix-shell -p nix-info --run "nix-info -m"
    
    ubuntu@fourth: ~
    $ exit                                                                                                           
    Connection to xxx closed.
    ❯ ssh fourth
    Enter passphrase for key '/home/fomm/.ssh/fourth/private':
    ubuntu@fourth: ~
    $ nix-shell -p nix-info --run "nix-info -m"                                                                       
    error:
         … <borked>
    
           at «none»:0: (source not available)
    
         … while calling the 'import' builtin
    
           at «string»:1:18:
    
              1| {...}@args: with import <nixpkgs> args; (pkgs.runCommandCC or pkgs.runCommand) "shell" { buildInputs = [ (nix-info) ]; } ""
               |                  ^
    
         (stack trace truncated; use '--show-trace' to show the full trace)
    
         error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)
    
         at «none»:0: (source not available)
    FAIL
    
  • Is there a reason for not using the home-manager CLI?
    I was unable to install the home-manager CLI.

  • Is the demon running?
    Yes.

    $ sudo systemctl status nix-daemon.service                                                                         [6:45:47]
    â—Ź nix-daemon.service - Nix Daemon
         Loaded: loaded (/etc/systemd/system/nix-daemon.service; linked; vendor preset: enabled)
         Active: active (running) since Fri 2023-03-03 06:37:20 UTC; 8min ago
    TriggeredBy: â—Ź nix-daemon.socket
           Docs: man:nix-daemon
                 https://nixos.org/manual
       Main PID: 653027 (nix-daemon)
          Tasks: 2 (limit: 14240)
         Memory: 3.6M
         CGroup: /system.slice/nix-daemon.service
                 └─653027 nix-daemon --daemon
    
    Mar 03 06:37:20 fourth systemd[1]: Started Nix Daemon.
    

But thats a different error…

This usually means that you haven’t set up channels.

Please check nix-env -q instead for a regular command or nix shell nixpkgs#nix-info -c nix-info -m for the flake equivalent of what you did above.

What was the problem? For the first build usually nix run nixpkgs#home-manager -- build --flake ./… -- switch … is totally sufficient.

Then I am out of ideas for now…

Though from what I understand, using home-manager with --verbose would give additional information during the activation. Which could then help us to further debug.

Thanks again for the reply.

This is the same error message I got.

$ nix run nixpkgs#home-manager -- build --flake . switch
Starting Home Manager activation
error: opening lock file '/nix/var/nix/profiles/per-user/ubuntu/home-manager.lock': No such file or directory
FAIL

I am not too sure why /nix/var/nix/profiles/per-user/$<username> was missing.

$ ls -ls /nix/var/nix/profiles/per-user
total 0

And any insights using the aforementioned --verbose switch?

I solved the issue by creating two folders and change ownership manually.

sudo mkdir /nix/var/nix/profiles/per-user/ubuntu
sudo mkdir /nix/var/nix/gcroots/per-user/ubuntu
sudo chown ubuntu:root /nix/var/nix/profiles/per-user/ubuntu
sudo chown ubuntu:root /nix/var/nix/gcroots/per-user/ubuntu

It feels like the current multi-user installation script does not create all necessary folders.

Thank you again for all the info.

1 Like

FYI the single user installer also stopped creating those so whoever stumbles on this try:

mkdir -p /nix/var/nix/profiles/per-user/$USER
mkdir -p /nix/var/nix/gcroots/per-user/$USER