diff --git a/modules/modules.nix b/modules/modules.nix index dbeebfbf7..932287faa 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -254,6 +254,7 @@ let ./programs/wpaperd.nix ./programs/xmobar.nix ./programs/xplr.nix + ./programs/xonsh.nix ./programs/yambar.nix ./programs/yazi.nix ./programs/yt-dlp.nix diff --git a/modules/programs/xonsh.nix b/modules/programs/xonsh.nix new file mode 100644 index 000000000..58e4eb27b --- /dev/null +++ b/modules/programs/xonsh.nix @@ -0,0 +1,64 @@ +{ config, lib, pkgs, ... }: +let + cfg = config.programs.xonsh; + inherit (lib) types mkOption; +in { + options.programs.xonsh = { + enable = lib.mkEnableOption "xonsh"; + + package = lib.mkPackageOption pkgs "xonsh" { }; + finalPackage = lib.mkOption { + type = types.package; + internal = true; + description = "Package that will actually get installed"; + }; + xonshrc = mkOption { + type = types.lines; + default = ""; + description = '' + The contents of .xonshrc + ''; + }; + pythonPackages = mkOption { + type = types.raw; + default = pkgs.pythonPackages; + defaultText = "pkgs.pythonPackages"; + description = '' + The pythonPackages set extraPackages are taken from + ''; + }; + shellAliases = mkOption { + type = with types; attrsOf (listOf str); + default = { }; + example = { ll = [ "ls" "-l" ]; }; + description = '' + An attribute set that maps aliases (the top level attribute names in + this option) to commands + ''; + }; + extraPackages = mkOption { + type = with types; functionTo (listOf package); + default = _: [ ]; + defaultText = "_: []"; + description = '' + List of python packages and xontrib to make avaiable + ''; + }; + }; + config = lib.mkIf cfg.enable { + home.packages = [ cfg.finalPackage ]; + programs.xonsh = { + xonshrc = lib.mkMerge + (lib.mapAttrsToList (n: v: "aliases['${n}']=${builtins.toJSON v}") + cfg.shellAliases); + shellAliases = lib.mapAttrs (n: v: lib.mkDefault (lib.splitString " " v)) + config.home.shellAliases; + finalPackage = + (cfg.package.override (old: { inherit (cfg) extraPackages; })); + }; + xdg.configFile."xonsh/rc.xsh" = { + enable = cfg.xonshrc != ""; + text = cfg.xonshrc; + }; + }; +}