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

Experimental NixOS module #97

Merged
merged 1 commit into from
Feb 7, 2018
Merged

Experimental NixOS module #97

merged 1 commit into from
Feb 7, 2018

Conversation

rycee
Copy link
Member

@rycee rycee commented Oct 14, 2017

With this it is possible to put, e.g.,

{
  # …

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

  users.users.jimdumree.isNormalUser = true;

  home-manager.users.jimdumree = {
    home.file."TEST".text = "foo";
    home.packages = [ pkgs.nload ];
    services.random-background = { enable = true; imageDirectory = "bgs"; };
  };

  # …
}

in the system configuration.nix and the user environment will be set up when nixos-rebuild switch runs. No need to install Home Manager first.

Hacky for now and some HM modules won't work.

Edit (2019-03-22): There are now some basic instructions on how to use the NixOS module in the Home Manager manual.

@rycee
Copy link
Member Author

rycee commented Jan 27, 2018

@infinisil It was quite tricky but I think I figured it out 😄 Please retry. Basically, if the user is logged in when the nixos-rebuild switch happens then the HM system service for the user will try to do the regular user systemd daemon reload as if running home-manager switch. If the user is not logged in then the systemd part will be skipped.

@rycee
Copy link
Member Author

rycee commented Jan 27, 2018

@flokli Sorry for leaving you waiting for so long. I've looked into the nixpkgs config option a bit. It is true that the nixpkgs.config value of the system will be ignored inside the home-manager.user option. But from what I can tell you can use the HM nixpkgs module. E.g., having

home-manager.user.foo.nixpkgs.allowUnfree = true

in my system configuration seems to work for me.

I think it would be possible to make the home-manager.user option honor the system nixpkgs module but I'm not sure about the best semantics w.r.t merging the configurations. Generally I would like to have a user HM configuration managed through the NixOS module work as close as possible to managing it through the home-manager tool and in that case it won't honor the system nixpkgs configuration.

@throwup
Copy link

throwup commented Jan 30, 2018

This does not seem to work for me, I get an error when trying to rebuild with the home manager enabled, regardless of what I put inside home-manager.users.<username>. What could I be missing?

● home-manager-leo.service - Home Manager environment for leo
   Loaded: loaded (/nix/store/gfqfyrhnybz49six90aqbiz671054d2i-unit-home-manager-leo.service/home-manager-leo.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2018-01-30 23:20:35 CET; 19ms ago
  Process: 5571 ExecStart=/nix/store/vfnnbv78l5lvb52svg8sv82qp3kzj5xp-activate-leo (code=exited, status=2)
 Main PID: 5571 (code=exited, status=2)

Jan 30 23:20:35 nixos vfnnbv78l5lvb52svg8sv82qp3kzj5xp-activate-leo[5571]: Activating linkGeneration
Jan 30 23:20:35 nixos vfnnbv78l5lvb52svg8sv82qp3kzj5xp-activate-leo[5571]: Cleaning up orphan links from /home/leo
Jan 30 23:20:35 nixos vfnnbv78l5lvb52svg8sv82qp3kzj5xp-activate-leo[5571]: No change so reusing latest profile generation 4
Jan 30 23:20:35 nixos vfnnbv78l5lvb52svg8sv82qp3kzj5xp-activate-leo[5571]: Creating home file links in /home/leo
Jan 30 23:20:35 nixos vfnnbv78l5lvb52svg8sv82qp3kzj5xp-activate-leo[5571]: Activating reloadSystemD
Jan 30 23:20:35 nixos vfnnbv78l5lvb52svg8sv82qp3kzj5xp-activate-leo[5571]: /nix/store/35ifr39r4119si4a7mij5dl8vs571c7c-home-manager-generation/activate: line 140: syntax error near unexpected token `('
Jan 30 23:20:35 nixos systemd[1]: home-manager-leo.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Jan 30 23:20:35 nixos systemd[1]: Failed to start Home Manager environment for leo.
Jan 30 23:20:35 nixos systemd[1]: home-manager-leo.service: Unit entered failed state.
Jan 30 23:20:35 nixos systemd[1]: home-manager-leo.service: Failed with result 'exit-code'.
warning: error(s) occurred while switching to the new configuration

@infinisil
Copy link
Collaborator

@throwup Please show your configuration.nix and the contents of /nix/store/35ifr39r4119si4a7mij5dl8vs571c7c-home-manager-generation/activate (use something like https://gist.github.com/)

@throwup
Copy link

throwup commented Jan 30, 2018

@infinisil
Copy link
Collaborator

@throwup Ah, i see, @rycee broke it with the latest commit in this branch :). Right here: 5af0d40#diff-40cef6e54189bc6970bd2e6427de09e6R165

This doesn't work because legacyReloadCmd is a huge string representing a shell script, not inlineable

@throwup
Copy link

throwup commented Jan 31, 2018

@infinisil Ok, that makes sense (I think). So do you suggest just waiting until it's fixed, or is there anything I can do?

@infinisil
Copy link
Collaborator

@throwup What you can do is just use the previous commit until it's fixed:

{
  imports = [
    (import (builtins.fetchTarball https://github.com/rycee/home-manager/archive/804d1f4872dca47cd53ea566399ca489db678599.tar.gz) {}).nixos
  ];
}

(Untested but 99% sure this should work)

@rycee
Copy link
Member Author

rycee commented Jan 31, 2018

@throwup Sorry for the problems you've been having! I've been slowly working on a test framework that would have caught this type of silly coding errors but it's still in the pipeline :-(

In any case, I've pushed a new version that should fix the error. Please give it a try.

@throwup
Copy link

throwup commented Feb 1, 2018

@rycee Hey, there's absolutely no need to apologize! With WIP-features you have to expect that some thing don't always work and it's not like I lost any considerable time/work through this bug. Moreover, you are working on this in your free time, for free so if anything I'd have to thank you for the great tools you are providing to all of us!

@rycee
Copy link
Member Author

rycee commented Feb 3, 2018

@throwup Cool, thanks :-D Does it work OK for you now?

Unless anybody has major concern I'll put together some news entry and merge this to master as an "experimental feature". Ideally we'll be able to get the user-pkg branch to work but there are still some issues with Qt applications installed that way.

@rummik
Copy link

rummik commented Feb 4, 2018

The example in the PR works well for me 👍 I'm currently only using it to configure Git though.

I did run into some issues with an apparent local copy of Git on one system; the error output from the systemd service was a bit unclear about why a collision was occurring, so it took a little head scratching to figure out what was happening.

Unfortunately I didn't think to keep any logs, or I'd leave them here, but steps to reproduce should essentially be:

  1. Run nix-env -iA nixos.git
  2. Configure Git options through home-manager
  3. Run a nixos-rebuild test -- it doesn't fail until after starting the service and attempting to add the configuration for Git

To fix it I just had to do a nix-env -e git, but it would be pretty neat to have it say as much in the service error log

@throwup
Copy link

throwup commented Feb 4, 2018

At the moment most of the things work for me, however I might have found some bugs:
home.sessionVariables does not seem to work for me. I get no errors, but the Variables are not set.
home.keyboard.layout/variants/options also does not do anything (this is meant for setting the Xserver keyboard, correct?)

@rycee
Copy link
Member Author

rycee commented Feb 5, 2018

@throwup Yeah, at the moment the home.keyboard.* options are only applied when xsession.enable is set and will only affect the X session. Ideally this should change to use localectl and not be dependent on HM managing the X session.

For the session variables, are you using Home Manager to manage your Bash or Z shell configurations? If not then you unfortunately must source the ~/.nix-profile/etc/profile.d/hm-session-vars.sh file manually.

@rycee
Copy link
Member Author

rycee commented Feb 5, 2018

@rummik Yeah, this collision problem is a bit unfortunate and several people have been bitten by it. The problem does not just apply to using Home Manager as a NixOS module but also when running through the home-manager tool. I've added a FAQ that includes the collision problem but like you said some more clear error would be nice.

@flokli
Copy link
Contributor

flokli commented Feb 6, 2018

@rycee I'd suggest adding a separate issue for the home.keyboard.* options to be set via localectl, and get this one in soon :-)

@rycee rycee changed the title [WIP] Experimental NixOS module Experimental NixOS module Feb 6, 2018
@rycee
Copy link
Member Author

rycee commented Feb 6, 2018

Ok, I've added a news entry and removed the WIP tag. It's a bit late to merge today so I will try to do it tomorrow. If there are any last major concerns then now is the time to raise them 😃

I also added a commit that should make the log entries for the activation scripts a bit prettier.

Edit: Btw, I'll make sure not to immediately delete the branch after merge to allow people some time to switch over their import expressions.

This is a NixOS module that is intended to be imported into a NixOS
system configuration. It allows the system users to be set up directly
from the system configuration.

The actual profile switch is performed by a oneshot systemd unit per
configured user that acts much like the regular `home-manager switch`
command.

With this implementation, the NixOS module does not work properly with
the `nixos-rebuild build-vm` command. This can be solved by using the
`users.users.<name?>.packages` option to install packages but this
does not work flawlessly with certain Nixpkgs packages. In particular,
for programs using the Qt libraries.
@flokli
Copy link
Contributor

flokli commented Feb 15, 2018

yay :-)

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

Successfully merging this pull request may close these issues.

5 participants