OSShells, refactor shells to single option

This commit is contained in:
Julia Lange 2024-11-29 01:53:13 -08:00
parent db7f132f6e
commit 55bfb8a4fb
Signed by: Julia
SSH key fingerprint: SHA256:KI8YxpkPRbnDRkXPgCuQCVz181++Vy7NAvmQj8alOhM
7 changed files with 54 additions and 57 deletions

View file

@ -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;
};
}

View file

@ -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 ];
};
}

View file

@ -0,0 +1,7 @@
{ config, lib, ... }:
{
config = lib.mkIf (config.shell.defaultShell == "fish") {
programs.fish.enable = true;
};
}

View file

@ -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 ];
};
}

View file

@ -0,0 +1,7 @@
{ config, lib, ... }:
{
config = lib.mkIf (config.shell.defaultShell == "xonsh") {
programs.xonsh.enable = true;
};
}

View file

@ -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 ];
};
}

View file

@ -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;
};
};
}