···2828 echo "WARNING: bad ownership on $NIX_USER_PROFILE_DIR" >&2
2929 fi
30303131- if ! test -L $HOME/.nix-profile; then
3232- if test "$USER" != root; then
3333- ln -s $NIX_USER_PROFILE_DIR/profile $HOME/.nix-profile
3434- else
3535- # Root installs in the system-wide profile by default.
3636- ln -s /nix/var/nix/profiles/default $HOME/.nix-profile
3737- fi
3838- fi
3131+ if test -w $HOME; then
3232+ if ! test -L $HOME/.nix-profile; then
3333+ if test "$USER" != root; then
3434+ ln -s $NIX_USER_PROFILE_DIR/profile $HOME/.nix-profile
3535+ else
3636+ # Root installs in the system-wide profile by default.
3737+ ln -s /nix/var/nix/profiles/default $HOME/.nix-profile
3838+ fi
3939+ fi
39404040- # Subscribe the root user to the NixOS channel by default.
4141- if [ "$USER" = root -a ! -e $HOME/.nix-channels ]; then
4242- echo "${config.system.defaultChannel} nixos" > $HOME/.nix-channels
4343- fi
4141+ # Subscribe the root user to the NixOS channel by default.
4242+ if [ "$USER" = root -a ! -e $HOME/.nix-channels ]; then
4343+ echo "${config.system.defaultChannel} nixos" > $HOME/.nix-channels
4444+ fi
44454545- # Create the per-user garbage collector roots directory.
4646- NIX_USER_GCROOTS_DIR=/nix/var/nix/gcroots/per-user/$USER
4747- mkdir -m 0755 -p $NIX_USER_GCROOTS_DIR
4848- if test "$(stat --printf '%u' $NIX_USER_GCROOTS_DIR)" != "$(id -u)"; then
4949- echo "WARNING: bad ownership on $NIX_USER_GCROOTS_DIR" >&2
5050- fi
4646+ # Create the per-user garbage collector roots directory.
4747+ NIX_USER_GCROOTS_DIR=/nix/var/nix/gcroots/per-user/$USER
4848+ mkdir -m 0755 -p $NIX_USER_GCROOTS_DIR
4949+ if test "$(stat --printf '%u' $NIX_USER_GCROOTS_DIR)" != "$(id -u)"; then
5050+ echo "WARNING: bad ownership on $NIX_USER_GCROOTS_DIR" >&2
5151+ fi
51525252- # Set up a default Nix expression from which to install stuff.
5353- if [ ! -e $HOME/.nix-defexpr -o -L $HOME/.nix-defexpr ]; then
5454- rm -f $HOME/.nix-defexpr
5555- mkdir $HOME/.nix-defexpr
5656- if [ "$USER" != root ]; then
5757- ln -s /nix/var/nix/profiles/per-user/root/channels $HOME/.nix-defexpr/channels_root
5858- fi
5353+ # Set up a default Nix expression from which to install stuff.
5454+ if [ ! -e $HOME/.nix-defexpr -o -L $HOME/.nix-defexpr ]; then
5555+ rm -f $HOME/.nix-defexpr
5656+ mkdir $HOME/.nix-defexpr
5757+ if [ "$USER" != root ]; then
5858+ ln -s /nix/var/nix/profiles/per-user/root/channels $HOME/.nix-defexpr/channels_root
5959+ fi
6060+ fi
5961 fi
6062 '';
6163