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

Using home-manager during nixos install #1154

Closed
eyeinsky opened this issue Apr 15, 2020 · 18 comments
Closed

Using home-manager during nixos install #1154

eyeinsky opened this issue Apr 15, 2020 · 18 comments

Comments

@eyeinsky
Copy link
Contributor

is it possible to use home-manager during installing nixos from an usb stick? I.e when I have booted from an usb stick and the to-be-root is mounted to /mnt?

@inigosola
Copy link

+1

@Kloenk
Copy link
Member

Kloenk commented Apr 18, 2020

I don't understand what you want to achieve. If you just want your config on the shell to install, you can build your own ISO, which includes home-manager.

home-manager needs a directory wich is not auto created at first boot, so you should include an activation Script like This:

{
  system.activationScripts = {
    base-dirs = {
      text = ''
        mkdir -p /nix/var/nix/profiles/per-user/kloenk
      '';
      deps = [ ];
    };
  };
}

@eyeinsky
Copy link
Contributor Author

eyeinsky commented Apr 19, 2020

@Kloenk I'm new to this so bear that in mind, but:

When installing nixos I boot from external media, prepare the disk, then generate the hardware-configuration.nix and configuration.nix into /mnt/etc/nixos/. At this point I clone my private repo, and from the /mnt/etc/nixos/configuration.nix point to a configuration file in that repo, and then run nixos-install. In the linked configuration file I already use home-manager (in addition to defining the OS itself), and although the home-manager works as expected when I'm already inside the newly installed nixos, then it doesn't while I'm outside.

Perhaps using home-manager at install-time isn't supposed to work, I don't really know. With this ticket I'm trying to find out.

@Kloenk
Copy link
Member

Kloenk commented Apr 19, 2020

I'm still not sure what you want to do. nixos-install is just supposed to install things, and not to activate anything, so no home-manager is installed yet (not even if you use nixos-enter). If you want to have you home configuration at install time in the external media, you would have to build your own ISO, which can inclued the home-manager module.

You could create a file like this, and execute nix-build to build your own ISO:

let
  nixos = import <nixpkgs/nixos> {
    configuration = { pkgs, lib, ... }: {
      imports = [
        ((fetchTarball
          "https://github.com/rycee/home-manager/archive/master.tar.gz")
          + "/nixos")
        <nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix>
        <nixpkgs/nixos/modules/installer/cd-dvd/channel.nix>
      ];
      systemd.services.sshd.wantedBy = lib.mkForce [ "multi-user.target" ];
      networking.hostName = "kexec";

      users.users.eyeinsky = {
        isNormalUser = true;
        uid = 1000;
        extraGroups = [ "wheel" ];
        shell = pkgs.fish;
        openssh.authorizedKeys.keys = [
          "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBps9Mp/xZax8/y9fW1Gt73SkskcBux1jDAB8rv0EYUt cardno:000611120054"
        ];
        packages = with pkgs; [
          wget
          nload
          htop
          ripgrep
          git
          gptfdisk
          nix-prefetch-git
          pass
          pass-otp
          gopass
          sl
          neofetch
        ];
      };

      # create dirs for home-manager
      system.activationScripts = {
        base-dirs = {
          text = ''
            mkdir -p /nix/var/nix/profiles/per-user/kloenk
          '';
          deps = [ ];
        };
      };
    };
  };
in nixos.config.system.build.isoImage

@eyeinsky
Copy link
Contributor Author

eyeinsky commented Apr 19, 2020

What I would like to do is have home-manager create the home folder for me. Perhaps this is out of scope, etc. but in general that's what I would like to do.

If I do nixos-rebuild from inside an installed nixos then the situation is similar: the system config rooted at /etc/nixos/configuration.nix builds both the system and the home folder for me. So if I do nixos-install with the same set of configuration files then I thought that it maybe will do the same thing.

Would this be good new feature to be added?

Edit:

I use home-manager as a nixos module like this:

{ config, lib, pkgs, ... }:
let
  home-manager = builtins.fetchGit {
    url = "https://github.com/rycee/home-manager.git";
    rev = "8d663335eb7b5032f637d8b719416ae4f2c1f612";
    ref = "release-19.09";
  };
in
{
  imports = [ (import "${home-manager}/nixos") ];
  # system code here

  home-manager.users.someUser = {
    # user code here
  }
}

I think home-manager is fetched while nixos-install runs, but as you say, it doesn't build the home folder nor activate it.

@Kloenk
Copy link
Member

Kloenk commented Apr 20, 2020

I think this is a duplicate of #948. Home manager populates you home manager. But only after it is ready to install things. The home directory itself is created by nixos, if you set users.users.name.isNormalsUser = true.

nixos-install and nixos-rebuild do very similar things. And if you run nixos-rebuild boot, your homemanager also doesn't get started.

@austinbutler
Copy link
Contributor

I'm still not clear as to whether having home-manager enabled as a module in your configuration.nix during initial installation of NixOS is supported or not.

Meaning in a brand new install, still in the live ISO, having <home-manager/nixos> in /mnt/etc/nixos/configuration.nix, then running nixos-install. Should that work? Or do we just stick basically to the automatically generated configuration.nix, run nixos-install, reboot, then from the installed system add home manager as a module?

@eyeinsky
Copy link
Contributor Author

@austinbutler strictly speaking: no. But I never tried what @Kloenk proposed above: to create the profile folder manually (mkdir -p /nix/var/nix/profiles/per-user/$your_username). If you are in the midst of an install and have time to try, do!

@austinbutler
Copy link
Contributor

austinbutler commented Jan 16, 2021

Is the idea creating /nix/var/nix/profiles/per-user/$your_username on the live USB? In my case that already exists. Well at least for user nixos from the live USB. I don't know if it's because I created my own installer ISO that uses home-manager itself.

Where I am at right now is home-manager works for configuring the live ISO itself, but I get a strange "file or folder not found" error when trying to install NixOS from the booted live ISO USB. The file not found is a VS Code extension, and it references /nix/store (not sure if that's a problem and it should be referencing /mnt/nix/store), however the folder does exist and has the extension in it.

@berbiche
Copy link
Member

If Home Manager is installed side-by-side with NixOS, I think you would need to chroot /mnt for the install script / flake configuration to work correctly.
If used as a NixOS module, it should work out of the box I think?

@austinbutler
Copy link
Contributor

I'm using it as a module in both the live ISO and the installed system. It kept complaining about the same VS Code extension (even though the same config works fine on my other systems that share the same config), so for now I've commented out the VS Code home-manager config and am re-running the install. It's still running and hasn't died yet...

@austinbutler
Copy link
Contributor

austinbutler commented Jan 17, 2021

Well it did work. I guess the file not found error was maybe a red herring. After installation I rebooted, logged in as root, then checked and the normal user folder existed and has my tmux.conf in it as expected. I did not have to use the creating a profile file workaround as suggested earlier, which I was assuming was the case since it seemed a fix had been merged a while back.

To sum up, I was able to make a live ISO that configured some things for the default nixos user and I was also able to install NixOS with home manager as a module.

Does that mean this issue can be closed?

@eyeinsky
Copy link
Contributor Author

@austinbutler Just to sum up/clarify, you were installing NixOS, had booted from a USD stick, had a configuration.nix ready with a line imports = [ <home-manager/nixos> ];, also had a configuration for a user in there, and when you ran nixos-install then after reboot you had the user folder correctly prepared? If so then yes I think the issue can be closed. (Anyone can always reopen it if there are hiccups)

@austinbutler
Copy link
Contributor

austinbutler commented Jan 25, 2021

For the ISO I have this in configuration.nix:

{
 imports = [
    ((fetchTarball
      "https://github.com/rycee/home-manager/archive/master.tar.gz") + "/nixos")
  ];
}

Then the normal imports = [ <home-manager/nixos> ]; for the configuration.nix for the target machine installation.

@eyeinsky
Copy link
Contributor Author

@austinbutler You made the ISO to boot&install from yourself? Do you think that is required for home-manager to work at install time? (I.e can't I just install home-manager while being booted from the ISO?)

@austinbutler
Copy link
Contributor

Yeah I created my own ISO. I don't know whether it's required unfortunately.

@stale
Copy link

stale bot commented Apr 28, 2021

Thank you for your contribution! I marked this issue as stale due to inactivity. If this remains inactive for another 7 days, I will close this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

  • If this is resolved, please consider closing it so that the maintainers know not to focus on this.
  • If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

  • If you are also experiencing this issue, please add details of your situation to help with the debugging process.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

If you have nothing of substance to add, please refrain from commenting and allow the bot close the issue. Also, don't be afraid to manually close an issue, even if it holds valuable information.

Closed issues stay in the system for people to search, read, cross-reference, or even reopen--nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

1 similar comment
@stale
Copy link

stale bot commented Jul 27, 2021

Thank you for your contribution! I marked this issue as stale due to inactivity. If this remains inactive for another 7 days, I will close this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

  • If this is resolved, please consider closing it so that the maintainers know not to focus on this.
  • If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

  • If you are also experiencing this issue, please add details of your situation to help with the debugging process.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

If you have nothing of substance to add, please refrain from commenting and allow the bot close the issue. Also, don't be afraid to manually close an issue, even if it holds valuable information.

Closed issues stay in the system for people to search, read, cross-reference, or even reopen--nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

@stale stale bot added the status: stale label Jul 27, 2021
@stale stale bot closed this as completed Aug 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants