Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Home manager does not install or build with config (reproducer included) #13

Closed
ParetoOptimalDev opened this issue Dec 1, 2022 · 4 comments

Comments

@ParetoOptimalDev
Copy link

ParetoOptimalDev commented Dec 1, 2022

My understanding is that this config is using home-manager as a nixos module. So whenever you do nixos-rebuild switch or nixos-rebuild vm the home-manage configuration should ge run too.

That doesn't happen though, and you can reproduce locally with:

git clone https://github.com/ParetoOptimalDev/try-nix-starter-config
cd try-nix-starter-config
git checkout a7d38df74b1d46631e7026f9a76ff23e5fbd7588
nixos-rebuild build-vm --flake .#your-hostname
/result/bin/run-your-hostname-vm 
# you can login with username and password nixos

related to #12. After reading #12 I thought "Oh... maybe the home-manager binary is available even though the home-manager nixos module wasn't run".

However home-manager in the shell after logging in returns home-manager: command not found.

@DavSanchez
Copy link

DavSanchez commented Dec 2, 2022

Hi, here home-manager acts as a stand-alone installation. If it was a NixOS module then the reference to a home.nix file would be inside the nixosConfigurations attrset's modules:

    nixosConfigurations = {
      hostname = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          ./configuration.nix
          home-manager.nixosModules.home-manager
          {
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
            home-manager.users.jdoe = import ./home.nix;
            # Optionally, use home-manager.extraSpecialArgs to pass
            # arguments to home.nix
          }
        ];
      };
    };

What is discussed in #12 is that apparently a home-manager needs to be activated when used for the first time.

According to the home-manager manual section for stand-alone installs using flakes, you should do this first:

$ nix build --no-link <flake-uri>#homeConfigurations.jdoe.activationPackage
$ "$(nix path-info <flake-uri>#homeConfigurations.jdoe.activationPackage)"/activate

Then home-manager will be correctly sourced on the login shell and subsequent calls to home-manager switch --flake '<flake-uri>#jdoe' should work.

The manual seems to say that from 21.05 onwards you can do just home-manager switch --flake '<flake-uri>#jdoe' and it will be expanded to the correct activationPackage, but it did not work in my case in 22.05 (nor in a nix-darwin setup). I needed to activate it first using the above 2 commands before home-manager switch --flake '<flake-uri>#jdoe' started to work properly.

Before that, my shell was trying to source hm-session-vars.sh from the wrong path (complained that the file was missing). The activate step put the files in the correct place.

@Misterio77
Copy link
Owner

Misterio77 commented Dec 2, 2022

@DavSanchez is correct, this template provides a standalone home-manager config. As they showed, it's pretty simple to use it as a NixOS module instead, if you prefer.

I would add, however, that getting the home-manager is easier than remembering that big nix build command: nix shell nixpkgs#home-manager should get you going.
You can alternatively use the provided shell.nix that automatically provides you with the latest nix (with flakes and nix-command enabled), git, and home-manager. Just run nix develop or nix-shell and you should be good to go.

@ParetoOptimalDev
Copy link
Author

Thank you both for your help. Your answers make sense but leave me with some questions.

Doesn't using home-manager as a nixos module subsume the standalone home-manager case?

Plus it would seem to avoid the user not having home-manager like I did.

Are there downsides to using the home-manager module?

@Misterio77
Copy link
Owner

Are there downsides to using the home-manager module?

The main one is just that you need to rebuild the system (including using sudo) when changing home configs, but it's mostly a personal preference.
It is worth noting that home-manager works on other distros and darwin, so having the standalone version available is nice to have, even if you mainly use NixOS.

The home-manager nixos module pretty much just creates a user systemd unit that calls the hm activation script, so they're not really incompatible. That means you can even combine the two, e.g. include your home config into your nixos system config, and iterate on it with home-manager switch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants