Skip to content
This repository has been archived by the owner on Aug 27, 2018. It is now read-only.

Commit

Permalink
Merge pull request #256 from oxij/shells-environment
Browse files Browse the repository at this point in the history
I tested the previous "version" and found my environment to be exactly the same.

Let's start discussing possible extensions/improvements somewhere else. For now it's a nice improvement.
  • Loading branch information
bluescreen303 committed Sep 23, 2013
2 parents bfd86d4 + ffa4b28 commit 3840e96
Show file tree
Hide file tree
Showing 22 changed files with 736 additions and 310 deletions.
11 changes: 4 additions & 7 deletions modules/config/fonts/fontconfig.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,10 @@ with pkgs.lib;
</fontconfig>
'';

environment.shellInit =
''
# FIXME: This variable is no longer needed, but we'll keep it
# around for a while for applications linked against old
# fontconfig builds.
export FONTCONFIG_FILE=/etc/fonts/fonts.conf
'';
# FIXME: This variable is no longer needed, but we'll keep it
# around for a while for applications linked against old
# fontconfig builds.
environment.variables.FONTCONFIG_FILE.value = "/etc/fonts/fonts.conf";

environment.systemPackages = [ pkgs.fontconfig ];

Expand Down
5 changes: 1 addition & 4 deletions modules/config/i18n.nix
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ in

environment.systemPackages = [ glibcLocales ];

environment.shellInit =
''
export LANG=${config.i18n.defaultLocale}
'';
environment.variables.LANG.value = config.i18n.defaultLocale;

# ‘/etc/locale.conf’ is used by systemd.
environment.etc = singleton
Expand Down
202 changes: 202 additions & 0 deletions modules/config/shells-environment.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
# This module defines a global environment configuration and
# a common configuration for all shells.

{ config, pkgs, ... }:

with pkgs.lib;

let

cfg = config.environment;

environOpts = { name, config, ... }: {

options = {

value = mkOption {
example = "/foo/bin";
description =
''
Variable value.
Exactly one of this or <option>list</option> must be set.
'';
type = types.uniq types.string;
};

list = mkOption {
default = null;
example = [ "/foo/bin" "/bar/bin" ];
description =
''
Variable value.
Exactly one of this or <option>value</option> must be set.
'';
type = types.nullOr (types.listOf types.string);
};

};

config = {
value = mkIf (config.list != null)
(concatStringsSep ":" config.list);
};

};

in

{

options = {

environment.variables = mkOption {
default = {};
description = ''
A set of environment variables used in the global environment.
'';
type = types.attrsOf types.optionSet;
options = [ environOpts ];
};

environment.profiles = mkOption {
default = [];
description = ''
A list of profiles used to setup the global environment.
'';
type = types.listOf types.string;
};

environment.profileVariables = mkOption {
default = (p: {});
description = ''
A function which given a profile path should give back
a set of environment variables for that profile.
'';
# !!! this should be of the following type:
#type = types.functionTo (types.attrsOf (types.optionSet envVar));
# and envVar should be changed to something more like environOpts.
# Having unique `value' _or_ multiple `list' is much more useful
# than just sticking everything together with ':' unconditionally.
# Anyway, to have this type mentioned above
# types.optionSet needs to be transformed into a type constructor
# (it has a !!! mark on that in nixpkgs)
# for now we hack all this to be
type = types.functionTo (types.attrsOf (types.listOf types.string));
};

# !!! isn't there a better way?
environment.extraInit = mkOption {
default = "";
description = ''
Shell script code called during global environment initialisation
after all variables and profileVariables have been set.
This code is asumed to be shell-independent, which means you should
stick to pure sh without sh word split.
'';
type = types.lines;
};

environment.shellInit = mkOption {
default = "";
description = ''
Shell script code called during shell initialisation.
This code is asumed to be shell-independent, which means you should
stick to pure sh without sh word split.
'';
type = types.lines;
};

environment.loginShellInit = mkOption {
default = "";
description = ''
Shell script code called during login shell initialisation.
This code is asumed to be shell-independent, which means you should
stick to pure sh without sh word split.
'';
type = types.lines;
};

environment.interactiveShellInit = mkOption {
default = "";
description = ''
Shell script code called during interactive shell initialisation.
This code is asumed to be shell-independent, which means you should
stick to pure sh without sh word split.
'';
type = types.lines;
};

environment.shellAliases = mkOption {
default = {};
example = { ll = "ls -l"; };
description = ''
An attribute set that maps aliases (the top level attribute names in
this option) to command strings or directly to build outputs. The
aliases are added to all users' shells.
'';
type = types.attrs; # types.attrsOf types.stringOrPath;
};

environment.binsh = mkOption {
default = "${config.system.build.binsh}/bin/sh";
example = "\${pkgs.dash}/bin/dash";
type = with pkgs.lib.types; path;
description = ''
The shell executable that is linked system-wide to
<literal>/bin/sh</literal>. Please note that NixOS assumes all
over the place that shell to be Bash, so override the default
setting only if you know exactly what you're doing.
'';
};

environment.shells = mkOption {
default = [];
example = [ "/run/current-system/sw/bin/zsh" ];
description = ''
A list of permissible login shells for user accounts.
No need to mention <literal>/bin/sh</literal>
here, it is placed into this list implicitly.
'';
type = types.listOf types.path;
};

};

config = {

system.build.binsh = pkgs.bashInteractive;

environment.etc."shells".text =
''
${concatStringsSep "\n" cfg.shells}
/bin/sh
'';

environment.etc."environment".text =
''
${concatStringsSep "\n" (
(mapAttrsToList (n: v: ''export ${n}="${concatStringsSep ":" v}"'')
# This line is a kind of a hack because of !!! note above
(fold (mergeAttrsWithFunc concat) {} ([ (mapAttrs (n: v: [ v.value ]) cfg.variables) ] ++ map cfg.profileVariables cfg.profiles))))}
${cfg.extraInit}
# The setuid wrappers override other bin directories.
export PATH="${config.security.wrapperDir}:$PATH"
# ~/bin if it exists overrides other bin directories.
export PATH="$HOME/bin:$PATH"
'';

system.activationScripts.binsh = stringAfter [ "stdio" ]
''
# Create the required /bin/sh symlink; otherwise lots of things
# (notably the system() function) won't work.
mkdir -m 0755 -p /bin
ln -sfn "${cfg.binsh}" /bin/.sh.tmp
mv /bin/.sh.tmp /bin/sh # atomically replace /bin/sh
'';

};

}
24 changes: 0 additions & 24 deletions modules/config/shells.nix

This file was deleted.

7 changes: 2 additions & 5 deletions modules/config/timezone.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ with pkgs.lib;

config = {

environment.shellInit =
''
export TZDIR=/etc/zoneinfo
export TZ=${config.time.timeZone}
'';
environment.variables.TZDIR.value = "/etc/zoneinfo";
environment.variables.TZ.value = config.time.timeZone;

environment.etc.localtime.source = "${pkgs.tzdata}/share/zoneinfo/${config.time.timeZone}";

Expand Down
4 changes: 3 additions & 1 deletion modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
./config/nsswitch.nix
./config/power-management.nix
./config/pulseaudio.nix
./config/shells.nix
./config/shells-environment.nix
./config/swap.nix
./config/sysctl.nix
./config/system-path.nix
Expand Down Expand Up @@ -45,13 +45,15 @@
./programs/bash/bash.nix
./programs/bash/command-not-found.nix
./programs/blcr.nix
./programs/environment.nix
./programs/info.nix
./programs/shadow.nix
./programs/shell.nix
./programs/ssh.nix
./programs/ssmtp.nix
./programs/venus.nix
./programs/wvdial.nix
./programs/zsh/zsh.nix
./rename.nix
./security/apparmor.nix
./security/apparmor-suid.nix
Expand Down
6 changes: 2 additions & 4 deletions modules/profiles/installation-device.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ with pkgs.lib;
# Tell the Nix evaluator to garbage collect more aggressively.
# This is desirable in memory-constrained environments that don't
# (yet) have swap set up.
environment.shellInit =
''
export GC_INITIAL_HEAP_SIZE=100000
'';
environment.variables.GC_INITIAL_HEAP_SIZE.value = "100000";

};
}

0 comments on commit 3840e96

Please sign in to comment.