mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-17 07:13:23 +01:00
b3f4040512
This change does two things: * "NixOSizes" environment variables generation. This allows some more error-checking and opens possibilities for a modular environment configuration. From now on the most of environment variables are generated directly by the nix code. Generating sh code that generates environment variables is left in a few places where nontrivial access to a local environment state is needed. * By doing the first change this patch untangles bash from the environment configuration and makes it trivial to add a support for other non bash-compatible shells. Now to the sad part. This change is quite large (and I'm not sure it's possible to split it) and yet is not quite complete, it needs some changes to nixpkgs to be perfect. See !!! comments in modules/config/shells-environment.nix. Main principle behind this change is "change environment generation and nothing else". In particular, shell configuration principles stay exactly the same as before.
67 lines
2 KiB
Nix
67 lines
2 KiB
Nix
# This module defines a standard configuration for NixOS shells.
|
|
|
|
{ config, pkgs, ... }:
|
|
|
|
with pkgs.lib;
|
|
|
|
let
|
|
|
|
cfg = config.environment;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
config = {
|
|
|
|
environment.shellAliases =
|
|
{ ls = "ls --color=tty";
|
|
ll = "ls -l";
|
|
l = "ls -alh";
|
|
};
|
|
|
|
environment.shellInit =
|
|
''
|
|
# Set up the per-user profile.
|
|
mkdir -m 0755 -p $NIX_USER_PROFILE_DIR
|
|
if test "$(stat --printf '%u' $NIX_USER_PROFILE_DIR)" != "$(id -u)"; then
|
|
echo "WARNING: bad ownership on $NIX_USER_PROFILE_DIR" >&2
|
|
fi
|
|
|
|
if ! test -L $HOME/.nix-profile; then
|
|
echo "creating $HOME/.nix-profile" >&2
|
|
if test "$USER" != root; then
|
|
ln -s $NIX_USER_PROFILE_DIR/profile $HOME/.nix-profile
|
|
else
|
|
# Root installs in the system-wide profile by default.
|
|
ln -s /nix/var/nix/profiles/default $HOME/.nix-profile
|
|
fi
|
|
fi
|
|
|
|
# Subscribe the root user to the NixOS channel by default.
|
|
if [ "$USER" = root -a ! -e $HOME/.nix-channels ]; then
|
|
echo "creating $HOME/.nix-channels with nixos-unstable subscription" >&2
|
|
echo "http://nixos.org/channels/nixos-unstable nixos" > $HOME/.nix-channels
|
|
fi
|
|
|
|
# Create the per-user garbage collector roots directory.
|
|
NIX_USER_GCROOTS_DIR=/nix/var/nix/gcroots/per-user/$USER
|
|
mkdir -m 0755 -p $NIX_USER_GCROOTS_DIR
|
|
if test "$(stat --printf '%u' $NIX_USER_GCROOTS_DIR)" != "$(id -u)"; then
|
|
echo "WARNING: bad ownership on $NIX_USER_GCROOTS_DIR" >&2
|
|
fi
|
|
|
|
# Set up a default Nix expression from which to install stuff.
|
|
if [ ! -e $HOME/.nix-defexpr -o -L $HOME/.nix-defexpr ]; then
|
|
echo "creating $HOME/.nix-defexpr" >&2
|
|
rm -f $HOME/.nix-defexpr
|
|
mkdir $HOME/.nix-defexpr
|
|
if [ "$USER" != root ]; then
|
|
ln -s /nix/var/nix/profiles/per-user/root/channels $HOME/.nix-defexpr/channels_root
|
|
fi
|
|
fi
|
|
'';
|
|
|
|
};
|
|
|
|
}
|