From 9d2272b3df123aed66244a372fe172e21815d48c Mon Sep 17 00:00:00 2001 From: Jack O'Sullivan Date: Sun, 20 Feb 2022 23:55:51 +0000 Subject: [PATCH] Use fish instead of bash as default shell --- home-manager/modules/common.nix | 58 ++++++++++++++++++++++++++++++--- nixos/modules/common.nix | 16 ++++++--- nixos/modules/user.nix | 3 ++ 3 files changed, 68 insertions(+), 9 deletions(-) diff --git a/home-manager/modules/common.nix b/home-manager/modules/common.nix index 427a1d0..960bf01 100644 --- a/home-manager/modules/common.nix +++ b/home-manager/modules/common.nix @@ -14,6 +14,9 @@ in description = "Whether home-manager is running inside a NixOS system or not."; }; + shell = mkOpt' str null "User's shell (so NixOS or others can set it externally)."; + fishCompletionsFrequency = mkOpt' (nullOr str) "daily" "How often to generate fish completions from manpages."; + ssh = { authKeys = { literal = mkOpt' (listOf singleLineStr) [ ] "List of OpenSSH keys to allow"; @@ -42,6 +45,8 @@ in my = { isStandalone = !(args ? osConfig); + shell = mkDefault "${config.programs.fish.package}/bin/fish"; + ssh = { matchBlocks = { nix-dev-vm = { @@ -99,7 +104,10 @@ in }; bash = { - # This not only installs bash but has home-manager control .bashrc and friends + # This does not install bash but has home-manager control .bashrc and friends + # Bash has some really weird behaviour with non-login and non-interactive shells, particularly around which + # of profile and bashrc are loaded when. This causes issues with PATH not being set correctly for + # non-interactive SSH... enable = mkDefault true; initExtra = '' @@ -107,6 +115,25 @@ in cd "$(nix eval "''${@:2}" --impure --raw --expr "builtins.getFlake \"$1\"")" } ''; + shellAliases = { + hm = "home-manager"; + }; + }; + + fish = { + enable = mkDefault true; + functions = { + # Silence the default greeting + fish_greeting = ":"; + flake-src = { + description = "cd into a flake reference's source directory"; + body = ''cd (nix eval $argv[2..] --impure --raw --expr "builtins.getFlake $argv[1]")''; + }; + }; + shellAbbrs = { + hm = "home-manager"; + k = "kubectl"; + }; }; ssh = { @@ -161,9 +188,6 @@ in sessionVariables = { EDITOR = "vim"; }; - shellAliases = { - hm = "home-manager"; - }; language.base = mkDefault "en_IE.UTF-8"; }; @@ -192,5 +216,31 @@ in ]; }; }) + (mkIf pkgs.stdenv.isLinux (mkMerge [ + (mkIf (config.my.isStandalone && config.programs.fish.enable && config.my.fishCompletionsFrequency != null) { + systemd.user = { + services.fish-update-completions = { + Unit.Description = "fish completions update"; + + Service = { + Type = "oneshot"; + ExecStart = "${config.programs.fish.package}/bin/fish -c fish_update_completions"; + }; + }; + + timers.fish-update-completions = { + Unit.Description = "fish completions update timer"; + + Timer = { + OnCalendar = config.my.fishCompletionsFrequency; + Persistent = true; + Unit = "fish-update-completions.service"; + }; + + Install.WantedBy = [ "timers.target" ]; + }; + }; + }) + ])) ]; } diff --git a/nixos/modules/common.nix b/nixos/modules/common.nix index 0575c36..4c24ddd 100644 --- a/nixos/modules/common.nix +++ b/nixos/modules/common.nix @@ -24,6 +24,11 @@ in config = mkMerge [ { + system = { + stateVersion = "21.11"; + configurationRevision = with inputs; mkIf (self ? rev) self.rev; + }; + home-manager = { # Installs packages in the system config instead of in the local profile on activation useUserPackages = mkDefault true; @@ -105,6 +110,12 @@ in vim ]; + programs = { + # This will enable generating completions at build time and prevent home-manager fish from generating them + # locally + fish.enable = mkDefault true; + }; + services = { kmscon = { # As it turns out, kmscon hasn't been updated in years and has some bugs... @@ -124,11 +135,6 @@ in passwordAuthentication = mkDefault false; }; }; - - system = { - stateVersion = "21.11"; - configurationRevision = with inputs; mkIf (self ? rev) self.rev; - }; } (mkIf config.services.kmscon.enable { fonts.fonts = with pkgs; [ diff --git a/nixos/modules/user.nix b/nixos/modules/user.nix index 11852c0..3c0b9e2 100644 --- a/nixos/modules/user.nix +++ b/nixos/modules/user.nix @@ -32,6 +32,9 @@ in uid = mkDefault 1000; extraGroups = mkDefault [ "wheel" ]; password = mkDefault "hunter2"; # TODO: secrets... + shell = + let shell = cfg.homeConfig.my.shell; + in mkIf (shell != null) (mkDefault' shell); openssh.authorizedKeys.keyFiles = [ lib.my.authorizedKeys ]; }; # In order for this option to evaluate on its own, home-manager expects the `name` (which is derived from the