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

Conversation

Projects
None yet
5 participants
@rycee
Owner

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.

@rycee

This comment has been minimized.

Show comment
Hide comment
@rycee

rycee Dec 11, 2017

Owner

Turns out it is better to use just a path in the imports field. In particular this improves error messages.

So suggested import attribute is now

{
  # …

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

  # …
}
Owner

rycee commented Dec 11, 2017

Turns out it is better to use just a path in the imports field. In particular this improves error messages.

So suggested import attribute is now

{
  # …

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

  # …
}
@flokli

This comment has been minimized.

Show comment
Hide comment
@flokli

flokli Dec 18, 2017

Contributor

I gave this a try, and it seems to work so far :-)

When moving to this, I tried separating home-manager config into different files, and wanted to use imports for that, but on the home-manager.users.<name>.imports level (with the imported files only returning the subtree, like in ~/.config/nixpkgs/home.nix previously.

Am I missing something obvious, or it that not really possible currently?

Contributor

flokli commented Dec 18, 2017

I gave this a try, and it seems to work so far :-)

When moving to this, I tried separating home-manager config into different files, and wanted to use imports for that, but on the home-manager.users.<name>.imports level (with the imported files only returning the subtree, like in ~/.config/nixpkgs/home.nix previously.

Am I missing something obvious, or it that not really possible currently?

@rycee

This comment has been minimized.

Show comment
Hide comment
@rycee

rycee Dec 18, 2017

Owner

@flokli Currently I personally simply use import, e.g.,

home-manager.users.rah = import ./home-rah.nix;

but when I try directly using imports as you mentioned it doesn't work. Instead I had to make the option a full module (i.e., a function):

home-manager.users.rah = {...}: { imports = [ ./home-rah.nix ]; };
Owner

rycee commented Dec 18, 2017

@flokli Currently I personally simply use import, e.g.,

home-manager.users.rah = import ./home-rah.nix;

but when I try directly using imports as you mentioned it doesn't work. Instead I had to make the option a full module (i.e., a function):

home-manager.users.rah = {...}: { imports = [ ./home-rah.nix ]; };
@Infinisil

This comment has been minimized.

Show comment
Hide comment
@Infinisil

Infinisil Dec 18, 2017

Collaborator

I am using this branch now too for my machines and it's working great! One thing that would be nice (but I'm not sure how to do it) is to automatically set the <user>.home.username and <user>.home.homeDirectory to config.users.users.<user>.name and config.users.users.<user>.home. Something like this:

{
  home-manager.users = mapAttrs (username: usercfg: {
    home.username = config.users.users.${username}.name;
    home.homeDirectory = config.users.users.${username}.home;
  }) config.home-manager.users;
}

But this doesn't work because of infinite recursion. Perhaps these 2 arguments can be passed to the submodule somehow else though. Right now I'm doing this manually for each user.

Collaborator

Infinisil commented Dec 18, 2017

I am using this branch now too for my machines and it's working great! One thing that would be nice (but I'm not sure how to do it) is to automatically set the <user>.home.username and <user>.home.homeDirectory to config.users.users.<user>.name and config.users.users.<user>.home. Something like this:

{
  home-manager.users = mapAttrs (username: usercfg: {
    home.username = config.users.users.${username}.name;
    home.homeDirectory = config.users.users.${username}.home;
  }) config.home-manager.users;
}

But this doesn't work because of infinite recursion. Perhaps these 2 arguments can be passed to the submodule somehow else though. Right now I'm doing this manually for each user.

@rycee

This comment has been minimized.

Show comment
Hide comment
@rycee

rycee Dec 18, 2017

Owner

@Infinisil Good point! I pushed a commit that should fix this.

Owner

rycee commented Dec 18, 2017

@Infinisil Good point! I pushed a commit that should fix this.

@flokli

This comment has been minimized.

Show comment
Hide comment
@flokli

flokli Dec 18, 2017

Contributor

@rycee I tried using something like

home-manager.users.flokli = {...}: { imports = [ ./one.nix ./two.nix ]; };

With one.nix and two.nix looking similar to:

{ pkgs, ... }:

{
  home.packages = with pkgs; [
    ...
   ];
}

It seems like merging doesn't happen as it should. For example, as long as I have one home.packages defined, those binaries appear in $PATH inside the users Xsession, but as soon as there are two (in different files), none of those binaries appear.

Do you have an idea what's going on here?

Contributor

flokli commented Dec 18, 2017

@rycee I tried using something like

home-manager.users.flokli = {...}: { imports = [ ./one.nix ./two.nix ]; };

With one.nix and two.nix looking similar to:

{ pkgs, ... }:

{
  home.packages = with pkgs; [
    ...
   ];
}

It seems like merging doesn't happen as it should. For example, as long as I have one home.packages defined, those binaries appear in $PATH inside the users Xsession, but as soon as there are two (in different files), none of those binaries appear.

Do you have an idea what's going on here?

@rycee

This comment has been minimized.

Show comment
Hide comment
@rycee

rycee Dec 18, 2017

Owner

@flokli Hmm, i'm unable to reproduce this. I changed

home-manager.users.rah = {...}: { imports = [ ./home-rah.nix ]; };

in my configuration to

home-manager.users.rah = {...}: { imports = [ ./home-rah.nix ./test.nix ]; };

where text.nix contains

{ pkgs, ... }:

{
  home.packages = [ pkgs.hello ];
}

After doing nixos-rebuild switch and restarting the affected container both my old packages and the hello package was available. Note, the home-rah.nix file contains a home.packages setting and also imports other files that adds additional packages to home.packages.

This works for me through both NixOps and NixOS declarative containers. But when I'm in a declarative NixOS container I seem to have to run the switch service manually (or restart the container). Try running $ sudo systemctl start home-manager-$USER.service as your user inside the container in that case.

Owner

rycee commented Dec 18, 2017

@flokli Hmm, i'm unable to reproduce this. I changed

home-manager.users.rah = {...}: { imports = [ ./home-rah.nix ]; };

in my configuration to

home-manager.users.rah = {...}: { imports = [ ./home-rah.nix ./test.nix ]; };

where text.nix contains

{ pkgs, ... }:

{
  home.packages = [ pkgs.hello ];
}

After doing nixos-rebuild switch and restarting the affected container both my old packages and the hello package was available. Note, the home-rah.nix file contains a home.packages setting and also imports other files that adds additional packages to home.packages.

This works for me through both NixOps and NixOS declarative containers. But when I'm in a declarative NixOS container I seem to have to run the switch service manually (or restart the container). Try running $ sudo systemctl start home-manager-$USER.service as your user inside the container in that case.

@flokli

This comment has been minimized.

Show comment
Hide comment
@flokli

flokli Dec 18, 2017

Contributor

It looks like home-manager-flokli.service fails to setup the environment completely:
(test inside nixos-rebuild build-vm in my case)

● home-manager-flokli.service - Home Manager environment for flokli
   Loaded: loaded (/nix/store/hd0g6dinx1fp7i0zsw1dkyrm3icxixi9-unit-home-manager-flokli.service/home-manager-flokli.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2017-12-18 22:25:23 CET; 6min ago
  Process: 636 ExecStart=/nix/store/1hhgd5nrzhzqygnaijmh6s3z89q7g5v9-activate-flokli (code=exited, status=1/FAILURE)
 Main PID: 636 (code=exited, status=1/FAILURE)
      CPU: 55ms

Dec 18 22:25:18 tp-vm 1hhgd5nrzhzqygnaijmh6s3z89q7g5v9-activate-flokli[636]: Activating writeBoundary
Dec 18 22:25:18 tp-vm 1hhgd5nrzhzqygnaijmh6s3z89q7g5v9-activate-flokli[636]: Activating installPackages
Dec 18 22:25:18 tp-vm 1hhgd5nrzhzqygnaijmh6s3z89q7g5v9-activate-flokli[636]: installing ‘home-manager-path’
Dec 18 22:25:23 tp-vm 1hhgd5nrzhzqygnaijmh6s3z89q7g5v9-activate-flokli[636]: warning: Nix search path entry ‘/nix/var/nix/profiles/per-user/root/channels’ does not exist, ignoring
Dec 18 22:25:23 tp-vm 1hhgd5nrzhzqygnaijmh6s3z89q7g5v9-activate-flokli[636]: building path(s) ‘/nix/store/xb6j4zjfdd06h14fyl9in3ws0n8hc7h1-user-environment’
Dec 18 22:25:23 tp-vm 1hhgd5nrzhzqygnaijmh6s3z89q7g5v9-activate-flokli[636]: error: linking ‘/nix/store/hdmyg5hnqzrycyp4qv2g48sn68a92w7s-user-environment.drv.chroot/nix/store/7ky19m5bv1z4vin5rwvvwr1wgqwgyi6f-fix-qt-module-paths.sh’ to ‘/nix/store/7ky19m5bv1z4vin5rwvvwr1wgqwgyi6f-fix-qt-module-paths.sh’: Operation not permitted
Dec 18 22:25:23 tp-vm systemd[1]: home-manager-flokli.service: Main process exited, code=exited, status=1/FAILURE
Dec 18 22:25:23 tp-vm systemd[1]: Failed to start Home Manager environment for flokli.
Dec 18 22:25:23 tp-vm systemd[1]: home-manager-flokli.service: Unit entered failed state.
Dec 18 22:25:23 tp-vm systemd[1]: home-manager-flokli.service: Failed with result 'exit-code'.

When specifying home.packages only once, it succeeds:

● home-manager-flokli.service - Home Manager environment for flokli
   Loaded: loaded (/nix/store/bmr4356avmibcmz7bmlac69cmsvfpqnj-unit-home-manager-flokli.service/home-manager-flokli.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Mon 2017-12-18 22:37:06 CET; 1min 29s ago
  Process: 636 ExecStart=/nix/store/1rpd6b32yk5vb4ibznfg35bpsq030x6r-activate-flokli (code=exited, status=0/SUCCESS)
 Main PID: 636 (code=exited, status=0/SUCCESS)
      CPU: 81ms

Dec 18 22:37:00 tp-vm 1rpd6b32yk5vb4ibznfg35bpsq030x6r-activate-flokli[636]: Activating installPackages
Dec 18 22:37:00 tp-vm 1rpd6b32yk5vb4ibznfg35bpsq030x6r-activate-flokli[636]: installing ‘home-manager-path’
Dec 18 22:37:05 tp-vm 1rpd6b32yk5vb4ibznfg35bpsq030x6r-activate-flokli[636]: warning: Nix search path entry ‘/nix/var/nix/profiles/per-user/root/channels’ does not exist, ignoring
Dec 18 22:37:05 tp-vm 1rpd6b32yk5vb4ibznfg35bpsq030x6r-activate-flokli[636]: building path(s) ‘/nix/store/bwjgyz45br7iw6m1wc18r4kskma5v8hp-user-environment’
Dec 18 22:37:06 tp-vm 1rpd6b32yk5vb4ibznfg35bpsq030x6r-activate-flokli[636]: created 7 symlinks in user environment
Dec 18 22:37:06 tp-vm 1rpd6b32yk5vb4ibznfg35bpsq030x6r-activate-flokli[636]: Activating linkGeneration
Dec 18 22:37:06 tp-vm 1rpd6b32yk5vb4ibznfg35bpsq030x6r-activate-flokli[636]: Creating profile generation 1
Dec 18 22:37:06 tp-vm 1rpd6b32yk5vb4ibznfg35bpsq030x6r-activate-flokli[636]: Creating home file links in /home/flokli
Dec 18 22:37:06 tp-vm 1rpd6b32yk5vb4ibznfg35bpsq030x6r-activate-flokli[636]: Activating reloadI3
Dec 18 22:37:06 tp-vm systemd[1]: Started Home Manager environment for flokli.

So it looks like it's a misbehaving qt hook. I'll try to identify the culprit.

Contributor

flokli commented Dec 18, 2017

It looks like home-manager-flokli.service fails to setup the environment completely:
(test inside nixos-rebuild build-vm in my case)

● home-manager-flokli.service - Home Manager environment for flokli
   Loaded: loaded (/nix/store/hd0g6dinx1fp7i0zsw1dkyrm3icxixi9-unit-home-manager-flokli.service/home-manager-flokli.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2017-12-18 22:25:23 CET; 6min ago
  Process: 636 ExecStart=/nix/store/1hhgd5nrzhzqygnaijmh6s3z89q7g5v9-activate-flokli (code=exited, status=1/FAILURE)
 Main PID: 636 (code=exited, status=1/FAILURE)
      CPU: 55ms

Dec 18 22:25:18 tp-vm 1hhgd5nrzhzqygnaijmh6s3z89q7g5v9-activate-flokli[636]: Activating writeBoundary
Dec 18 22:25:18 tp-vm 1hhgd5nrzhzqygnaijmh6s3z89q7g5v9-activate-flokli[636]: Activating installPackages
Dec 18 22:25:18 tp-vm 1hhgd5nrzhzqygnaijmh6s3z89q7g5v9-activate-flokli[636]: installing ‘home-manager-path’
Dec 18 22:25:23 tp-vm 1hhgd5nrzhzqygnaijmh6s3z89q7g5v9-activate-flokli[636]: warning: Nix search path entry ‘/nix/var/nix/profiles/per-user/root/channels’ does not exist, ignoring
Dec 18 22:25:23 tp-vm 1hhgd5nrzhzqygnaijmh6s3z89q7g5v9-activate-flokli[636]: building path(s) ‘/nix/store/xb6j4zjfdd06h14fyl9in3ws0n8hc7h1-user-environment’
Dec 18 22:25:23 tp-vm 1hhgd5nrzhzqygnaijmh6s3z89q7g5v9-activate-flokli[636]: error: linking ‘/nix/store/hdmyg5hnqzrycyp4qv2g48sn68a92w7s-user-environment.drv.chroot/nix/store/7ky19m5bv1z4vin5rwvvwr1wgqwgyi6f-fix-qt-module-paths.sh’ to ‘/nix/store/7ky19m5bv1z4vin5rwvvwr1wgqwgyi6f-fix-qt-module-paths.sh’: Operation not permitted
Dec 18 22:25:23 tp-vm systemd[1]: home-manager-flokli.service: Main process exited, code=exited, status=1/FAILURE
Dec 18 22:25:23 tp-vm systemd[1]: Failed to start Home Manager environment for flokli.
Dec 18 22:25:23 tp-vm systemd[1]: home-manager-flokli.service: Unit entered failed state.
Dec 18 22:25:23 tp-vm systemd[1]: home-manager-flokli.service: Failed with result 'exit-code'.

When specifying home.packages only once, it succeeds:

● home-manager-flokli.service - Home Manager environment for flokli
   Loaded: loaded (/nix/store/bmr4356avmibcmz7bmlac69cmsvfpqnj-unit-home-manager-flokli.service/home-manager-flokli.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Mon 2017-12-18 22:37:06 CET; 1min 29s ago
  Process: 636 ExecStart=/nix/store/1rpd6b32yk5vb4ibznfg35bpsq030x6r-activate-flokli (code=exited, status=0/SUCCESS)
 Main PID: 636 (code=exited, status=0/SUCCESS)
      CPU: 81ms

Dec 18 22:37:00 tp-vm 1rpd6b32yk5vb4ibznfg35bpsq030x6r-activate-flokli[636]: Activating installPackages
Dec 18 22:37:00 tp-vm 1rpd6b32yk5vb4ibznfg35bpsq030x6r-activate-flokli[636]: installing ‘home-manager-path’
Dec 18 22:37:05 tp-vm 1rpd6b32yk5vb4ibznfg35bpsq030x6r-activate-flokli[636]: warning: Nix search path entry ‘/nix/var/nix/profiles/per-user/root/channels’ does not exist, ignoring
Dec 18 22:37:05 tp-vm 1rpd6b32yk5vb4ibznfg35bpsq030x6r-activate-flokli[636]: building path(s) ‘/nix/store/bwjgyz45br7iw6m1wc18r4kskma5v8hp-user-environment’
Dec 18 22:37:06 tp-vm 1rpd6b32yk5vb4ibznfg35bpsq030x6r-activate-flokli[636]: created 7 symlinks in user environment
Dec 18 22:37:06 tp-vm 1rpd6b32yk5vb4ibznfg35bpsq030x6r-activate-flokli[636]: Activating linkGeneration
Dec 18 22:37:06 tp-vm 1rpd6b32yk5vb4ibznfg35bpsq030x6r-activate-flokli[636]: Creating profile generation 1
Dec 18 22:37:06 tp-vm 1rpd6b32yk5vb4ibznfg35bpsq030x6r-activate-flokli[636]: Creating home file links in /home/flokli
Dec 18 22:37:06 tp-vm 1rpd6b32yk5vb4ibznfg35bpsq030x6r-activate-flokli[636]: Activating reloadI3
Dec 18 22:37:06 tp-vm systemd[1]: Started Home Manager environment for flokli.

So it looks like it's a misbehaving qt hook. I'll try to identify the culprit.

@flokli

This comment has been minimized.

Show comment
Hide comment
@flokli

flokli Dec 18, 2017

Contributor

Confirmed. As soon as a QT application is added to home.packages, home-manager-$user.service fails to setup the environment.
This is also reproducible without using imports, but the structure suggested in the initial description.

Contributor

flokli commented Dec 18, 2017

Confirmed. As soon as a QT application is added to home.packages, home-manager-$user.service fails to setup the environment.
This is also reproducible without using imports, but the structure suggested in the initial description.

@flokli

This comment has been minimized.

Show comment
Hide comment
@flokli

flokli Dec 18, 2017

Contributor

Unrelated to the QT problem, after a reboot, home-manager-$user.service seems to fail, too:

● home-manager-flokli.service - Home Manager environment for flokli
   Loaded: loaded (/nix/store/4njqy7yrim53xkri4vcm726ph96b1bh0-unit-home-manager-flokli.service/home-manager-flokli.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2017-12-19 00:07:52 CET; 58s ago
  Process: 611 ExecStart=/nix/store/0mb9zq07zggbjjsc0695clv395xyxp2c-activate-flokli (code=exited, status=1/FAILURE)
 Main PID: 611 (code=exited, status=1/FAILURE)
      CPU: 83ms

Dec 19 00:07:47 tp-vm 0mb9zq07zggbjjsc0695clv395xyxp2c-activate-flokli[611]: Activating checkLinkTargets
Dec 19 00:07:47 tp-vm 0mb9zq07zggbjjsc0695clv395xyxp2c-activate-flokli[611]: Activating writeBoundary
Dec 19 00:07:47 tp-vm 0mb9zq07zggbjjsc0695clv395xyxp2c-activate-flokli[611]: Activating installPackages
Dec 19 00:07:47 tp-vm 0mb9zq07zggbjjsc0695clv395xyxp2c-activate-flokli[611]: installing ‘home-manager-path’
Dec 19 00:07:52 tp-vm 0mb9zq07zggbjjsc0695clv395xyxp2c-activate-flokli[611]: warning: Nix search path entry ‘/nix/var/nix/profiles/per-user/root/channels’ does not exist, ignoring
Dec 19 00:07:52 tp-vm 0mb9zq07zggbjjsc0695clv395xyxp2c-activate-flokli[611]: error: opening file ‘/nix/store/0pajyli2bx82p59hxw6ygn4anaafbgdl-user-environment.drv’: No such file or directory
Dec 19 00:07:52 tp-vm systemd[1]: home-manager-flokli.service: Main process exited, code=exited, status=1/FAILURE
Dec 19 00:07:52 tp-vm systemd[1]: Failed to start Home Manager environment for flokli.
Dec 19 00:07:52 tp-vm systemd[1]: home-manager-flokli.service: Unit entered failed state.
Dec 19 00:07:52 tp-vm systemd[1]: home-manager-flokli.service: Failed with result 'exit-code'.
Contributor

flokli commented Dec 18, 2017

Unrelated to the QT problem, after a reboot, home-manager-$user.service seems to fail, too:

● home-manager-flokli.service - Home Manager environment for flokli
   Loaded: loaded (/nix/store/4njqy7yrim53xkri4vcm726ph96b1bh0-unit-home-manager-flokli.service/home-manager-flokli.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2017-12-19 00:07:52 CET; 58s ago
  Process: 611 ExecStart=/nix/store/0mb9zq07zggbjjsc0695clv395xyxp2c-activate-flokli (code=exited, status=1/FAILURE)
 Main PID: 611 (code=exited, status=1/FAILURE)
      CPU: 83ms

Dec 19 00:07:47 tp-vm 0mb9zq07zggbjjsc0695clv395xyxp2c-activate-flokli[611]: Activating checkLinkTargets
Dec 19 00:07:47 tp-vm 0mb9zq07zggbjjsc0695clv395xyxp2c-activate-flokli[611]: Activating writeBoundary
Dec 19 00:07:47 tp-vm 0mb9zq07zggbjjsc0695clv395xyxp2c-activate-flokli[611]: Activating installPackages
Dec 19 00:07:47 tp-vm 0mb9zq07zggbjjsc0695clv395xyxp2c-activate-flokli[611]: installing ‘home-manager-path’
Dec 19 00:07:52 tp-vm 0mb9zq07zggbjjsc0695clv395xyxp2c-activate-flokli[611]: warning: Nix search path entry ‘/nix/var/nix/profiles/per-user/root/channels’ does not exist, ignoring
Dec 19 00:07:52 tp-vm 0mb9zq07zggbjjsc0695clv395xyxp2c-activate-flokli[611]: error: opening file ‘/nix/store/0pajyli2bx82p59hxw6ygn4anaafbgdl-user-environment.drv’: No such file or directory
Dec 19 00:07:52 tp-vm systemd[1]: home-manager-flokli.service: Main process exited, code=exited, status=1/FAILURE
Dec 19 00:07:52 tp-vm systemd[1]: Failed to start Home Manager environment for flokli.
Dec 19 00:07:52 tp-vm systemd[1]: home-manager-flokli.service: Unit entered failed state.
Dec 19 00:07:52 tp-vm systemd[1]: home-manager-flokli.service: Failed with result 'exit-code'.
@rycee

This comment has been minimized.

Show comment
Hide comment
@rycee

rycee Dec 19, 2017

Owner

@flokli I believe I have fixed this issue now. Unfortunately the fix seems to expose a few bugs in NixOS. For example, qt programs cannot find qt plugins and fontconfig doesn't seem to see installed fonts. I pushed the nixos-module-user-pkgs branch that includes the fix commit so you can try importing

"${builtins.fetchTarball https://github.com/rycee/home-manager/archive/nixos-module-user-pkgs.tar.gz}/nixos"

I will try looking in to what can be done on the NixOS side (the issue is that things don't consider packages installed through users.users.<name?>.packages)…

Owner

rycee commented Dec 19, 2017

@flokli I believe I have fixed this issue now. Unfortunately the fix seems to expose a few bugs in NixOS. For example, qt programs cannot find qt plugins and fontconfig doesn't seem to see installed fonts. I pushed the nixos-module-user-pkgs branch that includes the fix commit so you can try importing

"${builtins.fetchTarball https://github.com/rycee/home-manager/archive/nixos-module-user-pkgs.tar.gz}/nixos"

I will try looking in to what can be done on the NixOS side (the issue is that things don't consider packages installed through users.users.<name?>.packages)…

@flokli

This comment has been minimized.

Show comment
Hide comment
@flokli

flokli Jan 9, 2018

Contributor

I tinkered around with it a bit more, it seems there is currently no way to set nixpkgs.config.allowUnfree = true for packages that should be installed inside the user environment context (and the nixpkgs.config.allowUnfree from above is not respected).

Contributor

flokli commented Jan 9, 2018

I tinkered around with it a bit more, it seems there is currently no way to set nixpkgs.config.allowUnfree = true for packages that should be installed inside the user environment context (and the nixpkgs.config.allowUnfree from above is not respected).

@Infinisil

This comment has been minimized.

Show comment
Hide comment
@Infinisil

Infinisil Jan 26, 2018

Collaborator

An issue I just discovered is that the users systemd daemon isn't reloaded automatically, so it still uses the old unit files until a manual systemctl --user daemon-reload

Collaborator

Infinisil commented Jan 26, 2018

An issue I just discovered is that the users systemd daemon isn't reloaded automatically, so it still uses the old unit files until a manual systemctl --user daemon-reload

@rycee

This comment has been minimized.

Show comment
Hide comment
@rycee

rycee Jan 27, 2018

Owner

@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.

Owner

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

This comment has been minimized.

Show comment
Hide comment
@rycee

rycee Jan 27, 2018

Owner

@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.

Owner

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

This comment has been minimized.

Show comment
Hide comment
@throwup

throwup 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

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

This comment has been minimized.

Show comment
Hide comment
@Infinisil

Infinisil Jan 30, 2018

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/)

Collaborator

Infinisil commented Jan 30, 2018

@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

This comment has been minimized.

Show comment
Hide comment
@Infinisil

This comment has been minimized.

Show comment
Hide comment
@Infinisil

Infinisil Jan 31, 2018

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

Collaborator

Infinisil commented Jan 31, 2018

@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

This comment has been minimized.

Show comment
Hide comment
@throwup

throwup 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?

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

This comment has been minimized.

Show comment
Hide comment
@Infinisil

Infinisil Jan 31, 2018

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)

Collaborator

Infinisil commented Jan 31, 2018

@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

This comment has been minimized.

Show comment
Hide comment
@rycee

rycee Jan 31, 2018

Owner

@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.

Owner

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

This comment has been minimized.

Show comment
Hide comment
@throwup

throwup 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!

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

This comment has been minimized.

Show comment
Hide comment
@rycee

rycee Feb 3, 2018

Owner

@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.

Owner

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

This comment has been minimized.

Show comment
Hide comment
@rummik

rummik 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

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

This comment has been minimized.

Show comment
Hide comment
@throwup

throwup 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?)

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

This comment has been minimized.

Show comment
Hide comment
@rycee

rycee Feb 5, 2018

Owner

@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.

Owner

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

This comment has been minimized.

Show comment
Hide comment
@rycee

rycee Feb 5, 2018

Owner

@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.

Owner

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

This comment has been minimized.

Show comment
Hide comment
@flokli

flokli Feb 6, 2018

Contributor

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

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 from [WIP] Experimental NixOS module to Experimental NixOS module Feb 6, 2018

@rycee

This comment has been minimized.

Show comment
Hide comment
@rycee

rycee Feb 6, 2018

Owner

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.

Owner

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.

allow Home Manager to be used as a NixOS module
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.

@rycee rycee merged commit 1bc59f7 into master Feb 7, 2018

@flokli

This comment has been minimized.

Show comment
Hide comment
@flokli

flokli Feb 15, 2018

Contributor

yay :-)

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