From ce690db770d88decba4d279b05a4ef2af7a67204 Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Wed, 19 Oct 2016 23:25:15 +0200 Subject: [PATCH] added support for environment.variables --- config.nix | 11 +++++++++-- modules/environment.nix | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/config.nix b/config.nix index 75a8bcda..c4d5a8ff 100644 --- a/config.nix +++ b/config.nix @@ -14,6 +14,7 @@ let }; config = + { config, lib, pkgs, ... }: { environment.systemPackages = [ pkgs.lnl.vim @@ -30,14 +31,16 @@ let pkgs.nox ]; - environment.etc."profile".text = '' - export HOMEBREW_CASK_OPTS="--appdir=/Applications/cask" + environment.variables.HOMEBREW_CASK_OPTS = "--appdir=/Applications/cask"; + environment.etc."profile".text = '' conf=$HOME/src/nixpkgs-config pkgs=$HOME/.nix-defexpr/nixpkgs alias ls='ls -G' alias l='ls -hl' + + source ${config.system.build.setEnvironment} ''; environment.etc."tmux.conf".text = '' @@ -49,6 +52,8 @@ let set -g base-index 1 set -g renumber-windows on + setw -g mode-keys vi + bind c new-window -c '#{pane_current_path}' bind % split-window -v -c '#{pane_current_path}' bind '"' split-window -h -c '#{pane_current_path}' @@ -102,6 +107,8 @@ in { set et sw=2 ts=2 set bs=indent,start + set nowrap + set list set listchars=tab:»·,trail:·,extends:⟩,precedes:⟨ set fillchars+=vert:\ ,stl:\ ,stlnc:\ diff --git a/modules/environment.nix b/modules/environment.nix index 68c5677f..ace1b1c4 100644 --- a/modules/environment.nix +++ b/modules/environment.nix @@ -6,6 +6,12 @@ let cfg = config.environment; + exportVariables = + mapAttrsToList (n: v: ''export ${n}="${v}"'') cfg.variables; + + exportedEnvVars = + concatStringsSep "\n" exportVariables; + in { options = { @@ -31,10 +37,28 @@ in { description = "List of additional package outputs to be symlinked into /run/current-system/sw."; }; + environment.variables = mkOption { + default = {}; + description = '' + A set of environment variables used in the global environment. + These variables will be set on shell initialisation. + The value of each variable can be either a string or a list of + strings. The latter is concatenated, interspersed with colon + characters. + ''; + type = types.attrsOf (types.loeOf types.str); + apply = mapAttrs (n: v: if isList v then concatStringsSep ":" v else v); + }; + + }; config = { + system.build.setEnvironment = pkgs.writeText "set-environment" '' + ${exportedEnvVars} + ''; + system.path = pkgs.buildEnv { name = "system-path"; paths = cfg.systemPackages;