about summary refs log tree commit diff
path: root/nixos/modules/services
diff options
context:
space:
mode:
authorGabriel Arazas <foodogsquared@foodogsquared.one>2023-12-13 19:35:35 +0800
committerGabriel Arazas <foodogsquared@foodogsquared.one>2023-12-14 17:41:22 +0800
commita73ae4bf9fdf3eadcba76109b76bc5746182dbfb (patch)
tree4ed3f3276430f86cdb3e6f51b230ff07d6b77a94 /nixos/modules/services
parent7a9c99545178f59d63e798f5a4c526d125041178 (diff)
downloadnixlib-a73ae4bf9fdf3eadcba76109b76bc5746182dbfb.tar
nixlib-a73ae4bf9fdf3eadcba76109b76bc5746182dbfb.tar.gz
nixlib-a73ae4bf9fdf3eadcba76109b76bc5746182dbfb.tar.bz2
nixlib-a73ae4bf9fdf3eadcba76109b76bc5746182dbfb.tar.lz
nixlib-a73ae4bf9fdf3eadcba76109b76bc5746182dbfb.tar.xz
nixlib-a73ae4bf9fdf3eadcba76109b76bc5746182dbfb.tar.zst
nixlib-a73ae4bf9fdf3eadcba76109b76bc5746182dbfb.zip
nixos/guix: add Guix home support
Diffstat (limited to 'nixos/modules/services')
-rw-r--r--nixos/modules/services/misc/guix/default.nix35
1 files changed, 27 insertions, 8 deletions
diff --git a/nixos/modules/services/misc/guix/default.nix b/nixos/modules/services/misc/guix/default.nix
index 3e1a212693b9..0524f0316e77 100644
--- a/nixos/modules/services/misc/guix/default.nix
+++ b/nixos/modules/services/misc/guix/default.nix
@@ -22,11 +22,19 @@ let
       })
       (builtins.genList guixBuildUser numberOfUsers));
 
-  # A set of Guix user profiles to be linked at activation.
+  # A set of Guix user profiles to be linked at activation. All of these should
+  # be default profiles managed by Guix CLI and the profiles are located in
+  # `${cfg.stateDir}/profiles/per-user/$USER/$PROFILE`.
   guixUserProfiles = {
-    # The current Guix profile that is created through `guix pull`.
+    # The default Guix profile managed by `guix pull`. Take note this should be
+    # the profile with the most precedence in `PATH` env to let users use their
+    # updated versions of `guix` CLI.
     "current-guix" = "\${XDG_CONFIG_HOME}/guix/current";
 
+    # The default Guix home profile. This profile contains more than exports
+    # such as an activation script at `$GUIX_HOME_PROFILE/activate`.
+    "guix-home" = "$HOME/.guix-home/profile";
+
     # The default Guix profile similar to $HOME/.nix-profile from Nix.
     "guix-profile" = "$HOME/.guix-profile";
   };
@@ -262,20 +270,31 @@ in
       # ephemeral setups where only certain part of the filesystem is
       # persistent (e.g., "Erase my darlings"-type of setup).
       system.userActivationScripts.guix-activate-user-profiles.text = let
+        guixProfile = profile: "${cfg.stateDir}/guix/profiles/per-user/\${USER}/${profile}";
+        linkProfile = profile: location: let
+          userProfile = guixProfile profile;
+        in ''
+          [ -d "${userProfile}" ] && [ -L "${location}" ] || ln -sf "${userProfile}" "${location}"
+        '';
         linkProfileToPath = acc: profile: location: let
-          guixProfile = "${cfg.stateDir}/guix/profiles/per-user/\${USER}/${profile}";
-          in acc + ''
-            [ -d "${guixProfile}" ] && [ -L "${location}" ] || ln -sf "${guixProfile}" "${location}"
-          '';
+          in acc + (linkProfile profile location);
 
-        activationScript = lib.foldlAttrs linkProfileToPath "" guixUserProfiles;
+        # This should contain export-only Guix user profiles. The rest of it is
+        # handled manually in the activation script.
+        guixUserProfiles' = lib.attrsets.removeAttrs guixUserProfiles [ "guix-home" ];
+
+        linkExportsScript = lib.foldlAttrs linkProfileToPath "" guixUserProfiles';
       in ''
         # Don't export this please! It is only expected to be used for this
         # activation script and nothing else.
         XDG_CONFIG_HOME=''${XDG_CONFIG_HOME:-$HOME/.config}
 
         # Linking the usual Guix profiles into the home directory.
-        ${activationScript}
+        ${linkExportsScript}
+
+        # Activate all of the default Guix non-exports profiles manually.
+        ${linkProfile "guix-home" "$HOME/.guix-home"}
+        [ -L "$HOME/.guix-home" ] && "$HOME/.guix-home/activate"
       '';
 
       # GUIX_LOCPATH is basically LOCPATH but for Guix libc which in turn used by