Don't complain if HOME isn't writable

Shea Levy 17f88453 fefc0d99

+27 -25
+27 -25
nixos/modules/programs/shell.nix
··· 28 28 echo "WARNING: bad ownership on $NIX_USER_PROFILE_DIR" >&2 29 29 fi 30 30 31 - if ! test -L $HOME/.nix-profile; then 32 - if test "$USER" != root; then 33 - ln -s $NIX_USER_PROFILE_DIR/profile $HOME/.nix-profile 34 - else 35 - # Root installs in the system-wide profile by default. 36 - ln -s /nix/var/nix/profiles/default $HOME/.nix-profile 37 - fi 38 - fi 31 + if test -w $HOME; then 32 + if ! test -L $HOME/.nix-profile; then 33 + if test "$USER" != root; then 34 + ln -s $NIX_USER_PROFILE_DIR/profile $HOME/.nix-profile 35 + else 36 + # Root installs in the system-wide profile by default. 37 + ln -s /nix/var/nix/profiles/default $HOME/.nix-profile 38 + fi 39 + fi 39 40 40 - # Subscribe the root user to the NixOS channel by default. 41 - if [ "$USER" = root -a ! -e $HOME/.nix-channels ]; then 42 - echo "${config.system.defaultChannel} nixos" > $HOME/.nix-channels 43 - fi 41 + # Subscribe the root user to the NixOS channel by default. 42 + if [ "$USER" = root -a ! -e $HOME/.nix-channels ]; then 43 + echo "${config.system.defaultChannel} nixos" > $HOME/.nix-channels 44 + fi 44 45 45 - # Create the per-user garbage collector roots directory. 46 - NIX_USER_GCROOTS_DIR=/nix/var/nix/gcroots/per-user/$USER 47 - mkdir -m 0755 -p $NIX_USER_GCROOTS_DIR 48 - if test "$(stat --printf '%u' $NIX_USER_GCROOTS_DIR)" != "$(id -u)"; then 49 - echo "WARNING: bad ownership on $NIX_USER_GCROOTS_DIR" >&2 50 - fi 46 + # Create the per-user garbage collector roots directory. 47 + NIX_USER_GCROOTS_DIR=/nix/var/nix/gcroots/per-user/$USER 48 + mkdir -m 0755 -p $NIX_USER_GCROOTS_DIR 49 + if test "$(stat --printf '%u' $NIX_USER_GCROOTS_DIR)" != "$(id -u)"; then 50 + echo "WARNING: bad ownership on $NIX_USER_GCROOTS_DIR" >&2 51 + fi 51 52 52 - # Set up a default Nix expression from which to install stuff. 53 - if [ ! -e $HOME/.nix-defexpr -o -L $HOME/.nix-defexpr ]; then 54 - rm -f $HOME/.nix-defexpr 55 - mkdir $HOME/.nix-defexpr 56 - if [ "$USER" != root ]; then 57 - ln -s /nix/var/nix/profiles/per-user/root/channels $HOME/.nix-defexpr/channels_root 58 - fi 53 + # Set up a default Nix expression from which to install stuff. 54 + if [ ! -e $HOME/.nix-defexpr -o -L $HOME/.nix-defexpr ]; then 55 + rm -f $HOME/.nix-defexpr 56 + mkdir $HOME/.nix-defexpr 57 + if [ "$USER" != root ]; then 58 + ln -s /nix/var/nix/profiles/per-user/root/channels $HOME/.nix-defexpr/channels_root 59 + fi 60 + fi 59 61 fi 60 62 ''; 61 63