summary refs log tree commit diff
path: root/nixos/modules/programs
diff options
context:
space:
mode:
authorPatrick Callahan <pxcallahan@gmail.com>2017-03-25 01:37:07 -0700
committerJörg Thalheim <joerg@thalheim.io>2017-05-10 10:16:10 +0100
commit3f6d21bafc50d788d570a74dad957e792cea855d (patch)
treefe0689eb3abbb8182017ec4be48c28bfd7a24454 /nixos/modules/programs
parent3d37af3e8b4f0a363464b77105cb2f36ad1e5408 (diff)
downloadnixlib-3f6d21bafc50d788d570a74dad957e792cea855d.tar
nixlib-3f6d21bafc50d788d570a74dad957e792cea855d.tar.gz
nixlib-3f6d21bafc50d788d570a74dad957e792cea855d.tar.bz2
nixlib-3f6d21bafc50d788d570a74dad957e792cea855d.tar.lz
nixlib-3f6d21bafc50d788d570a74dad957e792cea855d.tar.xz
nixlib-3f6d21bafc50d788d570a74dad957e792cea855d.tar.zst
nixlib-3f6d21bafc50d788d570a74dad957e792cea855d.zip
fish: resolve NixOS-related initialization problems
Diffstat (limited to 'nixos/modules/programs')
-rw-r--r--nixos/modules/programs/fish.nix83
1 files changed, 74 insertions, 9 deletions
diff --git a/nixos/modules/programs/fish.nix b/nixos/modules/programs/fish.nix
index a99c98e166dc..eb969ee1ce0c 100644
--- a/nixos/modules/programs/fish.nix
+++ b/nixos/modules/programs/fish.nix
@@ -27,6 +27,30 @@ in
         '';
         type = types.bool;
       };
+      
+      vendor.config.enable = mkOption {
+        type = types.bool;
+        default = true;
+        description = ''
+          Whether fish should source configuration snippets provided by other packages.
+        '';
+      };
+
+      vendor.completions.enable = mkOption {
+        type = types.bool;
+        default = true;
+        description = ''
+          Whether fish should use completion files provided by other packages.
+        '';
+      };
+      
+      vendor.functions.enable = mkOption {
+        type = types.bool;
+        default = true;
+        description = ''
+          Whether fish should autoload fish functions provided by other packages.
+        '';
+      };
 
       shellAliases = mkOption {
         default = config.environment.shellAliases;
@@ -79,31 +103,72 @@ in
     environment.etc."fish/foreign-env/loginShellInit".text = cfge.loginShellInit;
     environment.etc."fish/foreign-env/interactiveShellInit".text = cfge.interactiveShellInit;
 
+    environment.etc."fish/nixos-env-preinit.fish".text = ''
+      # avoid clobbering the environment if it's been set by a parent shell
+
+      # This happens before $__fish_datadir/config.fish sets fish_function_path, so it is currently
+      # unset. We set it and then completely erase it, leaving its configuration to $__fish_datadir/config.fish
+      set fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions $__fish_datadir/functions
+      
+      # source the NixOS environment config
+      fenv source ${config.system.build.setEnvironment}
+
+      # clear fish_function_path so that it will be correctly set when we return to $__fish_datadir/config.fish
+      set -e fish_function_path
+    '';
+
     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
-
-      fenv source ${config.system.build.setEnvironment} > /dev/null ^&1
-      fenv source /etc/fish/foreign-env/shellInit > /dev/null
+      # if our parent shell didn't source the general config, do it
+      if not set -q __fish_nixos_general_config_sourced
+        set fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions $fish_function_path
+        fenv source /etc/fish/foreign-env/shellInit > /dev/null
+        set -e fish_function_path[1]
+        
+        ${cfg.shellInit}
 
-      ${cfg.shellInit}
+        # and leave a note to our children to spare them the same work
+        set -gx __fish_nixos_general_config_sourced 1
+      end
 
-      if status --is-login
+      # if our parent shell didn't source the login config, do it
+      status --is-login; and not set -q __fish_nixos_login_config_sourced
+      and begin
+        set fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions $fish_function_path
         fenv source /etc/fish/foreign-env/loginShellInit > /dev/null
+        set -e fish_function_path[1]
+        
         ${cfg.loginShellInit}
+
+        # and leave a note to our children to spare them the same work
+        set -gx __fish_nixos_login_config_sourced 1
       end
 
-      if status --is-interactive
+      # if our parent shell didn't source the interactive config, do it
+      status --is-interactive; and not set -q __fish_nixos_interactive_config_sourced
+      and begin
         ${fishAliases}
+        
+
+        set fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions $fish_function_path
         fenv source /etc/fish/foreign-env/interactiveShellInit > /dev/null
+        set -e fish_function_path[1]
+        
+        ${cfg.promptInit}
         ${cfg.interactiveShellInit}
+
+        # and leave a note to our children to spare them the same work
+        set -gx __fish_nixos_interactive_config_sourced 1
       end
     '';
 
     # include programs that bring their own completions
-    environment.pathsToLink = [ "/share/fish/vendor_completions.d" ];
-
+    environment.pathsToLink = []
+      ++ optional cfg.vendor.config.enable "/share/fish/vendor_conf.d"
+      ++ optional cfg.vendor.completions.enable "/share/fish/vendor_completions.d"
+      ++ optional cfg.vendor.functions.enable "/share/fish/vendor_functions.d";
+    
     environment.systemPackages = [ pkgs.fish ];
 
     environment.shells = [