From 55bfb8a4fb0ca4b2592d842a87d553e96928a76d Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Fri, 29 Nov 2024 01:53:13 -0800 Subject: [PATCH] OSShells, refactor shells to single option --- nixosModules/apps/shells/app.nix | 34 +++++++++++++++++----- nixosModules/apps/shells/fish/default.nix | 15 ---------- nixosModules/apps/shells/fish/shell.nix | 7 +++++ nixosModules/apps/shells/xonsh/default.nix | 15 ---------- nixosModules/apps/shells/xonsh/shell.nix | 7 +++++ nixosModules/apps/shells/zsh/default.nix | 20 ------------- nixosModules/apps/shells/zsh/shell.nix | 13 +++++++++ 7 files changed, 54 insertions(+), 57 deletions(-) delete mode 100644 nixosModules/apps/shells/fish/default.nix create mode 100644 nixosModules/apps/shells/fish/shell.nix delete mode 100644 nixosModules/apps/shells/xonsh/default.nix create mode 100644 nixosModules/apps/shells/xonsh/shell.nix delete mode 100644 nixosModules/apps/shells/zsh/default.nix create mode 100644 nixosModules/apps/shells/zsh/shell.nix diff --git a/nixosModules/apps/shells/app.nix b/nixosModules/apps/shells/app.nix index 6eab99e..66092fd 100644 --- a/nixosModules/apps/shells/app.nix +++ b/nixosModules/apps/shells/app.nix @@ -1,9 +1,29 @@ -{ ... }: +{ config, pkgs, lib, ... }: let + fs = lib.fileset; + shellFilter = {name, ...}: name == "shell.nix"; + shellImports = fs.toList (fs.fileFilter shellFilter ./.); + shellNames = map ( + path: let + splitPath = lib.strings.splitString "/" path; + splitPathLen = builtins.length splitPath; + in builtins.elemAt splitPath (splitPathLen - 2) + ) shellImports; +in { + imports = shellImports; -{ - imports = [ - ./fish - ./xonsh - ./zsh - ]; + options.shell = let + shellNameEnum = lib.types.enum shellNames; + in { + defaultShell = lib.mkOption { + type = shellNameEnum; + }; + enabledShells = lib.mkOption { + type = lib.types.listOf shellNameEnum; + }; + }; + + config = { + users.defaultUserShell = pkgs."${config.shell.defaultShell}"; + environment.shells = map (shell: pkgs."${shell}") config.shell.enabledShells; + }; } diff --git a/nixosModules/apps/shells/fish/default.nix b/nixosModules/apps/shells/fish/default.nix deleted file mode 100644 index 1e17b4e..0000000 --- a/nixosModules/apps/shells/fish/default.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ config, pkgs, lib, ... }: - -{ - options = { - fish.enable = lib.mkEnableOption "Enables fish"; - fish.setDefault = lib.mkEnableOption - "Sets fish as the default user's shell"; - }; - - config = lib.mkIf config.fish.enable { - programs.fish.enable = true; - users.defaultUserShell = lib.mkIf config.fish.setDefault pkgs.fish; - environment.shells = with pkgs; [ fish ]; - }; -} diff --git a/nixosModules/apps/shells/fish/shell.nix b/nixosModules/apps/shells/fish/shell.nix new file mode 100644 index 0000000..93d7b4a --- /dev/null +++ b/nixosModules/apps/shells/fish/shell.nix @@ -0,0 +1,7 @@ +{ config, lib, ... }: + +{ + config = lib.mkIf (config.shell.defaultShell == "fish") { + programs.fish.enable = true; + }; +} diff --git a/nixosModules/apps/shells/xonsh/default.nix b/nixosModules/apps/shells/xonsh/default.nix deleted file mode 100644 index 4d4215c..0000000 --- a/nixosModules/apps/shells/xonsh/default.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ config, pkgs, lib, ... }: - -{ - options = { - xonsh.enable = lib.mkEnableOption "Enables xonsh"; - xonsh.setDefault = lib.mkEnableOption - "Sets xonsh as the default user's shell"; - }; - - config = lib.mkIf config.xonsh.enable { - programs.xonsh.enable = true; - users.defaultUserShell = lib.mkIf config.xonsh.setDefault pkgs.xonsh; - environment.shells = with pkgs; [ xonsh ]; - }; -} diff --git a/nixosModules/apps/shells/xonsh/shell.nix b/nixosModules/apps/shells/xonsh/shell.nix new file mode 100644 index 0000000..2f39a02 --- /dev/null +++ b/nixosModules/apps/shells/xonsh/shell.nix @@ -0,0 +1,7 @@ +{ config, lib, ... }: + +{ + config = lib.mkIf (config.shell.defaultShell == "xonsh") { + programs.xonsh.enable = true; + }; +} diff --git a/nixosModules/apps/shells/zsh/default.nix b/nixosModules/apps/shells/zsh/default.nix deleted file mode 100644 index 93d33f7..0000000 --- a/nixosModules/apps/shells/zsh/default.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ config, pkgs, lib, ... }: - -{ - options = { - zsh.enable = lib.mkEnableOption "Enables zsh"; - zsh.setDefault = lib.mkEnableOption "Sets zsh as the default user's shell"; - }; - - config = lib.mkIf config.zsh.enable { - programs.zsh = { - enable = true; - enableCompletion = true; - autosuggestions.enable = true; - histFile = "$HOME/.config/zsh/history"; - histSize = 2000; - }; - users.defaultUserShell = lib.mkIf config.zsh.setDefault pkgs.zsh; - environment.shells = with pkgs; [ zsh ]; - }; -} diff --git a/nixosModules/apps/shells/zsh/shell.nix b/nixosModules/apps/shells/zsh/shell.nix new file mode 100644 index 0000000..979878f --- /dev/null +++ b/nixosModules/apps/shells/zsh/shell.nix @@ -0,0 +1,13 @@ +{ config, lib, ... }: + +{ + config = lib.mkIf (config.shell.defaultShell == "zsh") { + programs.zsh = { + enable = true; + enableCompletion = true; + autosuggestions.enable = true; + histFile = "$HOME/.config/zsh/history"; + histSize = 2000; + }; + }; +}