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

Activation preset for home-manager #43

Closed
notgne2 opened this issue Jan 8, 2021 · 6 comments · Fixed by #82
Closed

Activation preset for home-manager #43

notgne2 opened this issue Jan 8, 2021 · 6 comments · Fixed by #82
Labels
enhancement New feature or request

Comments

@notgne2
Copy link
Contributor

notgne2 commented Jan 8, 2021

Despite intentionally remaining profile-agnostic, deploy-rs provides support for NixOS in the form of activate.nixos, I would like to provide a similar option for home-manager deployments, this is something I know to be possible as I use it in my own deployments, though last time I checked required modifying some of home-manager's code.

@notgne2 notgne2 added the enhancement New feature or request label Jan 8, 2021
@Pacman99
Copy link

It would be great if you could share the code for how to do this. I don't entirely know how to use the custom activate script, so I wasn't able to figure it out myself.
And what would you have to modify in home-manager?

@notgne2
Copy link
Contributor Author

notgne2 commented Mar 14, 2021

I don't actually remember the modifications I made, the original file which I copied and altered has changed quite some bit (and I think the way I made it work was not entirely correct anyway). I'm going to revisit how to do it from scratch, and document it as I go.

@notgne2
Copy link
Contributor Author

notgne2 commented Mar 30, 2021

So it looks like the issue is that modules/modules.nix will try to use pkgs incorrectly unless you call it with useNixpkgsModule = false;, which makes sense, and it would be as simple as providing this flag, but, the ways home-manager exports itself for usage is through homeManagerConfiguration in the flake, which uses modules/default.nix internally, or simply using modules/default.nix, but modules/default.nix actually doesn't let you change all the arguments given to modules/modules.nix.

My modified code was simply a modules/default.nix altere to call modules/modules.nix with useNixpkgsModule = false;

It looks like the actual NixOS module (nixos/default.nix) actually completely skips over modules/default.nix entirely, making it perhaps less insane for me to include (a better version of) my altered code in deploy-rs, though it still seems like a design oversight on home-manager's part, and might be worth taking upstream.

@notgne2
Copy link
Contributor Author

notgne2 commented Mar 30, 2021

There's also a little bit of philosphical design consideration to be done, for the NixOS activation it makes a lot of sense, you use nixpkgs.lib.nixosSystem, and give that to activate.nixos which turns it into a deploy path for deploy-rs. home-manager has no such method (it has homeManagerConfiguration, which is exactly that, but is for our purposes, completely broken), so we would have to make our activation helper take the config and system, then do all the generation internally, which seems very weird

@notgne2
Copy link
Contributor Author

notgne2 commented Mar 30, 2021

Thankfully, I now believe I am an idiot, and everything I have just said seems to be wrong. Adding inherit pkgs; useNixpkgsModule = false; to extraSpecialArgs seems to fix everything, guess I forgot my way around the module system

EDIT: wrong again useNixpkgsModule = false; yet again does nothing here, though inherit pkgs; does seem to have fixed at least part of the issue, before doing that it would fail due to wanting allowUnfree (which I of course have elsewhere in my flake when I invoke nixpkgs)

@notgne2
Copy link
Contributor Author

notgne2 commented Mar 30, 2021

So basically, something like this does seem to work

        {
          profiles.notgne2-home-manager = {
            user = "notgne2";
            profilePath = "/nix/var/nix/profiles/per-user/notgne2/home-manager";
            path = deploy-rs.lib.${system}.activate.custom (home-manager.lib.homeManagerConfiguration {
              inherit pkgs system;
              extraSpecialArgs = { inherit pkgs inputs; };
              homeDirectory = "/home/notgne2";
              username = "notgne2";
              configuration = ./home-manager/configuration.nix;
            }).activationPackage "$PROFILE/activate";
          };
        }

And if we add a preset for it, it can look like this

        {
          profiles.notgne2-home-manager = {
            user = "notgne2";
            profilePath = "/nix/var/nix/profiles/per-user/notgne2/home-manager";
            path = deploy-rs.lib.${system}.activate.hm (home-manager.lib.homeManagerConfiguration {
              inherit pkgs system;
              extraSpecialArgs = { inherit pkgs inputs; };
              homeDirectory = "/home/notgne2";
              username = "notgne2";
              configuration = ./home-manager/configuration.nix;
            });
          };
        }

I'm still not sure why it works, or why it didn't, but I don't think that matters too much

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

Successfully merging a pull request may close this issue.

2 participants