summary refs log tree commit diff
path: root/nixos/modules/programs/fish.nix
diff options
context:
space:
mode:
authorJakob Gillich <jakob@gillich.me>2015-12-25 01:17:42 +0100
committerJakob Gillich <jakob@gillich.me>2015-12-26 06:25:23 +0100
commitac7e9231048e76012961fbabf5a03adcb7c36470 (patch)
treefa5e03576ab5f216c176854cb8ea945b3def56f1 /nixos/modules/programs/fish.nix
parentca277c2257ff981b47ad4b025712cc4f549267c8 (diff)
downloadnixpkgs-ac7e9231048e76012961fbabf5a03adcb7c36470.tar
nixpkgs-ac7e9231048e76012961fbabf5a03adcb7c36470.tar.gz
nixpkgs-ac7e9231048e76012961fbabf5a03adcb7c36470.tar.bz2
nixpkgs-ac7e9231048e76012961fbabf5a03adcb7c36470.tar.lz
nixpkgs-ac7e9231048e76012961fbabf5a03adcb7c36470.tar.xz
nixpkgs-ac7e9231048e76012961fbabf5a03adcb7c36470.tar.zst
nixpkgs-ac7e9231048e76012961fbabf5a03adcb7c36470.zip
fish: add module to support it as default shell
* Patched fish to load /etc/fish/config.fish if it exists (by default,
  it only loads config relative to itself)
* Added fish-foreign-env package to parse the system environment

closes #5331
Diffstat (limited to 'nixos/modules/programs/fish.nix')
-rw-r--r--nixos/modules/programs/fish.nix114
1 files changed, 114 insertions, 0 deletions
diff --git a/nixos/modules/programs/fish.nix b/nixos/modules/programs/fish.nix
new file mode 100644
index 00000000000..b4259f7ec87
--- /dev/null
+++ b/nixos/modules/programs/fish.nix
@@ -0,0 +1,114 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+
+  cfge = config.environment;
+
+  cfg = config.programs.fish;
+
+  fishAliases = concatStringsSep "\n" (
+    mapAttrsFlatten (k: v: "alias ${k} '${v}'") cfg.shellAliases
+  );
+
+in
+
+{
+
+  options = {
+
+    programs.fish = {
+
+      enable = mkOption {
+        default = false;
+        description = ''
+          Whether to configure fish as an interactive shell.
+        '';
+        type = types.bool;
+      };
+
+      shellAliases = mkOption {
+        default = config.environment.shellAliases;
+        description = ''
+          Set of aliases for fish shell. See <option>environment.shellAliases</option>
+          for an option format description.
+        '';
+        type = types.attrs;
+      };
+
+      shellInit = mkOption {
+        default = "";
+        description = ''
+          Shell script code called during fish shell initialisation.
+        '';
+        type = types.lines;
+      };
+
+      loginShellInit = mkOption {
+        default = "";
+        description = ''
+          Shell script code called during fish login shell initialisation.
+        '';
+        type = types.lines;
+      };
+
+      interactiveShellInit = mkOption {
+        default = "";
+        description = ''
+          Shell script code called during interactive fish shell initialisation.
+        '';
+        type = types.lines;
+      };
+
+      promptInit = mkOption {
+        default = "";
+        description = ''
+          Shell script code used to initialise fish prompt.
+        '';
+        type = types.lines;
+      };
+
+    };
+
+  };
+
+  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
+
+      fenv source ${config.system.build.setEnvironment} 1> /dev/null
+      fenv source /etc/fish/foreign-env/shellInit 1> /dev/null
+
+      ${cfg.shellInit}
+
+      if builtin status --is-login
+        fenv source /etc/fish/foreign-env/loginShellInit 1> /dev/null
+        ${cfg.loginShellInit}
+      end
+
+      if builtin status --is-interactive
+        ${fishAliases}
+        fenv source /etc/fish/foreign-env/interactiveShellInit 1> /dev/null
+        ${cfg.interactiveShellInit}
+      end
+    '';
+
+    environment.systemPackages = [ pkgs.fish ];
+
+    environment.shells = [
+      "/run/current-system/sw/bin/fish"
+      "/var/run/current-system/sw/bin/fish"
+      "${pkgs.fish}/bin/fish"
+    ];
+
+  };
+
+}