From 75575107a677baf10ee54b114f1105873086364c Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Mon, 2 Jan 2017 21:42:13 -0600 Subject: Add programs.fish module In nix-darwin, `config.system.build.setEnvironment is a string containing a script, not a filename, so our usage is a bit different from NixOS's. --- modules/programs/fish.nix | 144 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 modules/programs/fish.nix (limited to 'modules/programs') diff --git a/modules/programs/fish.nix b/modules/programs/fish.nix new file mode 100644 index 0000000..a92aca4 --- /dev/null +++ b/modules/programs/fish.nix @@ -0,0 +1,144 @@ +{ config, lib, pkgs, ...}: + +with lib; + +let + + cfge = config.environment; + + cfg = config.programs.fish; + + fishVariables = + mapAttrsToList (n: v: ''set -x ${n} "${v}"'') cfg.variables; + + shell = pkgs.runCommand pkgs.fish.name + { buildInputs = [ pkgs.makeWrapper ]; } + '' + source $stdenv/setup + + mkdir -p $out/bin + makeWrapper ${pkgs.fish}/bin/fish $out/bin/fish + ''; + + fishAliases = concatStringsSep "\n" ( + mapAttrsFlatten (k: v: "alias ${k} '${v}'") cfg.shellAliases + ); + +in + +{ + + options = { + + programs.fish = { + + enable = mkOption { + type = types.bool; + default = false; + description = '' + Whether to configure fish as an interactive shell. + ''; + }; + + variables = mkOption { + type = types.attrsOf (types.either types.str (types.listOf types.str)); + 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. + ''; + apply = mapAttrs (n: v: if isList v then concatStringsSep ":" v else v); + }; + + shellAliases = mkOption { + type = types.attrs; + default = cfge.shellAliases; + description = '' + Set of aliases for fish shell. See + for an option format description. + ''; + }; + + shellInit = mkOption { + type = types.lines; + default = ""; + description = '' + Shell Script code called during fish shell initialisation. + ''; + }; + + loginShellInit = mkOption { + type = types.lines; + default = ""; + description = '' + Shell script code called during fish login shell initialisation. + ''; + }; + + interactiveShellInit = mkOption { + type = types.lines; + default = ""; + description = '' + Shell script code called during interactive fish shell initialisation. + ''; + }; + + promptInit = mkOption { + type = types.lines; + default = ""; + description = '' + Shell script code used to initialise fish prompt. + ''; + }; + + }; + }; + + config = mkIf cfg.enable { + + environment.etc."fish/foreign-env/shellInit".text = cfge.shellInit; + environment.etc."fish/foreign-env/loginShellInit".text = cfge.loginShellInit; + environment.etc."fish/foreign-env/interactiveShellInit".text = cfge.interactiveShellInit; + + environment.etc."fish/config.fish".text = '' + # /etc/fish/config.fish: DO NOT EDIT -- this file has been generated automatically. + + set fish_function_path $fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions + + set PATH ${replaceStrings [":"] [" "] config.environment.systemPath} $PATH + + ${config.system.build.setEnvironment} + + fenv source /etc/fish/foreign-env/shellInit > /dev/null + + ${cfg.shellInit} + + ${concatStringsSep "\n" fishVariables} + + if status --is-login + fenv source /etc/fish/foreign-env/loginShellInit > /dev/null + ${cfg.loginShellInit} + end + + if status --is-interactive + ${fishAliases} + fenv source /etc/fish/foreign-env/interactiveShellInit > /dev/null + ${cfg.interactiveShellInit} + ${cfg.promptInit} + end + ''; + + # include programs that bring their own completions + # FIXME: environment.pathsToLink = [ "/share/fish/vendor_completions.d" ]; + + environment.systemPackages = [ pkgs.fish ]; + + environment.loginShell = mkDefault "${shell}/bin/fish -l"; + environment.variables.SHELL = mkDefault "${shell}/bin/fish"; + + }; + +} -- cgit v1.2.3 From 367a05488f7f454070d4fbdf1044e49866a1caa1 Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Tue, 24 Jan 2017 20:45:40 +0100 Subject: fish: use writeText for foreign-env --- modules/programs/fish.nix | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'modules/programs') diff --git a/modules/programs/fish.nix b/modules/programs/fish.nix index a92aca4..698bc32 100644 --- a/modules/programs/fish.nix +++ b/modules/programs/fish.nix @@ -4,12 +4,21 @@ with lib; let + cfg = config.programs.fish; cfge = config.environment; - cfg = config.programs.fish; + foreignEnv = pkgs.writeText "fish-foreign-env" '' + # TODO: environment.shellInit + ${cfge.extraInit} + ''; - fishVariables = - mapAttrsToList (n: v: ''set -x ${n} "${v}"'') cfg.variables; + loginForeignEnv = pkgs.writeText "fish-login-foreign-env" '' + # TODO: environment.loginShellInit + ''; + + interactiveForeignEnv = pkgs.writeText "fish-interactive-foreign-env" '' + ${cfge.interactiveShellInit} + ''; shell = pkgs.runCommand pkgs.fish.name { buildInputs = [ pkgs.makeWrapper ]; } @@ -24,6 +33,9 @@ let mapAttrsFlatten (k: v: "alias ${k} '${v}'") cfg.shellAliases ); + fishVariables = + mapAttrsToList (n: v: ''set -x ${n} "${v}"'') cfg.variables; + in { @@ -99,10 +111,6 @@ in config = mkIf cfg.enable { - environment.etc."fish/foreign-env/shellInit".text = cfge.shellInit; - environment.etc."fish/foreign-env/loginShellInit".text = cfge.loginShellInit; - environment.etc."fish/foreign-env/interactiveShellInit".text = cfge.interactiveShellInit; - environment.etc."fish/config.fish".text = '' # /etc/fish/config.fish: DO NOT EDIT -- this file has been generated automatically. @@ -112,20 +120,22 @@ in ${config.system.build.setEnvironment} - fenv source /etc/fish/foreign-env/shellInit > /dev/null - + fenv source ${foreignEnv} ${cfg.shellInit} ${concatStringsSep "\n" fishVariables} if status --is-login - fenv source /etc/fish/foreign-env/loginShellInit > /dev/null + # TODO: environment.loginShellInit ${cfg.loginShellInit} end if status --is-interactive ${fishAliases} - fenv source /etc/fish/foreign-env/interactiveShellInit > /dev/null + ${optionalString (cfge.interactiveShellInit != "") '' + fenv source ${interactiveForeignEnv} + ''} + ${cfg.interactiveShellInit} ${cfg.promptInit} end -- cgit v1.2.3