1# This module defines a standard configuration for NixOS shells. 2 3{ config, lib, pkgs, ... }: 4 5with lib; 6 7let 8 9 cfg = config.environment; 10 11in 12 13{ 14 15 config = { 16 17 environment.shellAliases = 18 { ls = "ls --color=tty"; 19 ll = "ls -l"; 20 l = "ls -alh"; 21 }; 22 23 environment.shellInit = 24 '' 25 # Set up the per-user profile. 26 mkdir -m 0755 -p $NIX_USER_PROFILE_DIR 27 if test "$(stat --printf '%u' $NIX_USER_PROFILE_DIR)" != "$(id -u)"; then 28 echo "WARNING: bad ownership on $NIX_USER_PROFILE_DIR" >&2 29 fi 30 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 40 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 45 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 52 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 -p $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 61 fi 62 ''; 63 64 }; 65 66}