at 18.09-beta 2.0 kB view raw
1# This module defines a standard configuration for NixOS shells. 2 3{ config, lib, ... }: 4 5with lib; 6 7{ 8 9 config = { 10 11 environment.shellAliases = 12 { ls = "ls --color=tty"; 13 ll = "ls -l"; 14 l = "ls -alh"; 15 }; 16 17 environment.shellInit = 18 '' 19 # Set up the per-user profile. 20 mkdir -m 0755 -p "$NIX_USER_PROFILE_DIR" 21 if [ "$(stat --printf '%u' "$NIX_USER_PROFILE_DIR")" != "$(id -u)" ]; then 22 echo "WARNING: bad ownership on $NIX_USER_PROFILE_DIR, should be $(id -u)" >&2 23 fi 24 25 if [ -w "$HOME" ]; then 26 if ! [ -L "$HOME/.nix-profile" ]; then 27 if [ "$USER" != root ]; then 28 ln -s "$NIX_USER_PROFILE_DIR/profile" "$HOME/.nix-profile" 29 else 30 # Root installs in the system-wide profile by default. 31 ln -s /nix/var/nix/profiles/default "$HOME/.nix-profile" 32 fi 33 fi 34 35 # Subscribe the root user to the NixOS channel by default. 36 if [ "$USER" = root -a ! -e "$HOME/.nix-channels" ]; then 37 echo "${config.system.defaultChannel} nixos" > "$HOME/.nix-channels" 38 fi 39 40 # Create the per-user garbage collector roots directory. 41 NIX_USER_GCROOTS_DIR="/nix/var/nix/gcroots/per-user/$USER" 42 mkdir -m 0755 -p "$NIX_USER_GCROOTS_DIR" 43 if [ "$(stat --printf '%u' "$NIX_USER_GCROOTS_DIR")" != "$(id -u)" ]; then 44 echo "WARNING: bad ownership on $NIX_USER_GCROOTS_DIR, should be $(id -u)" >&2 45 fi 46 47 # Set up a default Nix expression from which to install stuff. 48 if [ ! -e "$HOME/.nix-defexpr" -o -L "$HOME/.nix-defexpr" ]; then 49 rm -f "$HOME/.nix-defexpr" 50 mkdir -p "$HOME/.nix-defexpr" 51 if [ "$USER" != root ]; then 52 ln -s /nix/var/nix/profiles/per-user/root/channels "$HOME/.nix-defexpr/channels_root" 53 fi 54 fi 55 fi 56 ''; 57 58 }; 59 60}