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

Recreate .guix-profile; .guix-home; and .profile at startup #7

Closed
a12l opened this issue Nov 13, 2022 · 6 comments
Closed

Recreate .guix-profile; .guix-home; and .profile at startup #7

a12l opened this issue Nov 13, 2022 · 6 comments
Labels
bug Something isn't working

Comments

@a12l
Copy link

a12l commented Nov 13, 2022

Describe the bug

I'm using ephemeral home and root[0], and the directories where I store my files are mounted at boot. This means that all files under ~/ is removed. After rebooting I don't have the links ~/.guix-profile; ~/.guix-home; and ~/.profile.

I'm trying to use guix home for configuring my home environment, instead of Home Manager. This is intended as a way to test out Guix; and potentially be a stepping stone to fully move over to Guix from NixOS on my desktop systems.

The link

.guix-profile -> /var/guix/profiles/per-user/a12l/guix-profile

seems to be created when I install a package into my profile with guix install kakoune, but not when I try to update my home environment by running guix home reconfigure a12l.scm. I also get warnings that ~/.profile doesn't exist when I open a shell.

$ exa -la
drwxr-xr-x  - a12l 13 Nov 15:12 .cache
drwxr-xr-x  - a12l 13 Nov 15:12 .config
lrwxrwxrwx 45 a12l 13 Nov 15:20 .guix-profile -> /var/guix/profiles/per-user/a12l/guix-profile
drwxr-xr-x  - a12l 13 Nov 14:41 .local
lrwxrwxrwx 71 a12l 13 Nov 15:12 .manpath -> /nix/store/p2i46958lc8ya7vbacaqbkw6ax9d3m56-home-manager-files/.manpath
drwxr-xr-x  - a12l 13 Nov 14:40 .nix-defexpr
lrwxrwxrwx 43 a12l 13 Nov 14:40 .nix-profile -> /nix/var/nix/profiles/per-user/a12l/profile
drwxr-xr-x  - a12l 27 Oct 13:00 .ssh

(removed irrelevant directories from the output)

To Reproduce
Steps to reproduce the behavior:

  1. Remove ~/.guix-profile and ~/.guix-home directories
  2. Reboot the machine

Expected behavior

The symbolic links ~/.guix-profile; ~/.guix-home; and ~/.profile are recreated at startup if missing.

[0] https://elis.nu/blog/2020/05/nixos-tmpfs-as-root/

@a12l a12l added the bug Something isn't working label Nov 13, 2022
@foo-dogsquared
Copy link
Owner

I'm using ephemeral home and root[0], and the directories where I store my files are mounted at boot. This means that all files under ~/ is removed. After rebooting I don't have the links ~/.guix-profile; ~/.guix-home; and ~/.profile.

That's an interesting setup. Comments aside, this is a valid bug as my module does not properly reactivate those profiles unlike NixOS and home-manager profiles.

(Though, for ~/.profile which is a file often used for shell configurations, this is not something my module doesn't and shouldn't touch. ~/.profile is something that is managed by whatever means you prefer [i.e., Guix Home, home-manager, not at all].).

@foo-dogsquared
Copy link
Owner

foo-dogsquared commented Nov 14, 2022

For now, I'm going to leave these puzzle pieces for me (or anyone who's interested) to revisit these next time. Hopefully, this could also spark a discussion and put the puzzle pieces together. Here's what I came up with from at least 15 minutes fiddling with this. :)

  • Read more details at Guix manual.

  • The main bug here is the lack of proper activation for these Guix profiles. Guix has several profiles for several users such as root and other users (e.g., non-system users). These profiles can be seen at $GUIX_STATE_DIR/guix/profiles (i.e., /var/guix/profiles by default).

    • guix-profile is a profile that is mainly managed from ad-hoc installations(?) (e.g., guix package -i, guix package -r). For its Nix counterpart at ~/.nix-profile, this is managed somewhere in nixpkgs.
    • current-guix seems to be generated from updating the Guix channel (i.e., guix pull).
    • guix-home for Guix Home configuration. Unlike the previous profiles, it has an activation script that we can invoke for setting up the home environment for that user (i.e., $GUIX_STATE_DIR/guix/profiles/per-user/$USER/guix-home/activate)
  • Like NixOS and home-manager profiles, Guix Home profiles do have an activation script that can be invoked to properly set up per boot. If we could reliably get the current Guix Home profile and activate it, this would fix most of the problems described in the original issue.

  • For Guix profiles without the activation script such as current-guix and guix-profile, I guess symlinking them would solve it.

  • Nothing to do with the bug report, I didn't use Guix Home prior to this bug report but it seems to mostly work surprisingly well. It's possible for someone to manage their home environment fully with Guix Home inside NixOS (that is if the profiles are properly activated).

  • One way to solve this issue is to create an activation script for the previously mentioned Guix profiles. However, one would worry about what profiles are supposed to be activated and it is done per-user.

@foo-dogsquared
Copy link
Owner

foo-dogsquared commented Nov 14, 2022

As for a possible workaround while no fix is here, I guess manually creating a systemd service for activating would suffice. Here's a very very very crude (and untested) example of one.

systemd.services.guix-profiles-activation-$USER = {
  description = "Guix profiles activation for $USER";
  wantedBy = [ "multi-user.target" ];
  after = [ "guix-daemon.service" ];
  script = ''
    # Link back the profiles.
    ln -sf /var/guix/profiles/per-user/$USER/current-guix /home/$USER/.config/guix/current
    ln -sf /var/guix/profiles/per-user/$USER/guix-profile /home/$USER/.guix-profile
    ln -sf /var/guix/profiles/per-user/$USER/guix-home /home/$USER/.guix-home

    # Activate the Guix home profile.
    /var/guix/profiles/per-user/$USER/guix-home/activate
  '';
}

Another way would be to use environment.extraInit and link them back to the home directory (also untested).

environment.extraInit = ''
  # Link back the profiles.
  ln -sf /var/guix/profiles/per-user/$USER/current-guix $HOME/.config/guix/current
  ln -sf /var/guix/profiles/per-user/$USER/guix-profile $HOME/.guix-profile
  ln -sf /var/guix/profiles/per-user/$USER/guix-home $HOME/.guix-home

  # Activate the Guix home profile.
  /var/guix/profiles/per-user/$USER/guix-home/activate
'';

This is closer to the supposed solution I would do (except more elegant).

@foo-dogsquared
Copy link
Owner

I haven't formally revisit these issues yet (just putting my thoughts in the open) but I think creating an activation script for these profiles (so that they can regenerated at startup) would solve the crux of this issue. I guess a script written in Guile (to interact with Guix API) can be the solution(?). I'm not aware if it's even possible in the first place. This should be investigated in the future.

@foo-dogsquared
Copy link
Owner

This is now implemented in nixpkgs' version of the module. Though Guix home is not yet supported since it has other things for me to worry about such as running the activation script of the profile (but it should be trivial to add it if needed, it just needs some more consideration for nixpkgs' version).

@foo-dogsquared
Copy link
Owner

I'll consider this closed since it resolves the behavior now. For the missing Guix home support, it will be considered resolved at #8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants