From 4e92ec84f93a293042a64c3ed56ac8aee62fb6e1 Mon Sep 17 00:00:00 2001 From: Joakim Holm Date: Thu, 27 Jan 2022 19:15:45 +0100 Subject: [PATCH] ion: Add module (#2625) Co-authored-by: Nicolas Berbiche Co-authored-by: Matthieu Coudron --- .github/CODEOWNERS | 2 ++ modules/modules.nix | 1 + modules/programs/exa.nix | 1 + modules/programs/ion.nix | 59 +++++++++++++++++++++++++++++++++++ modules/programs/starship.nix | 14 +++++++++ 5 files changed, 77 insertions(+) create mode 100644 modules/programs/ion.nix diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index ade52190..3e9c649a 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -421,3 +421,5 @@ Makefile @thiagokokada /modules/services/swayidle.nix @c0deaddict /tests/modules/services/swayidle @c0deaddict + +/modules/programs/ion.nix @jo1gi diff --git a/modules/modules.nix b/modules/modules.nix index dc5921fe..a8c3e36b 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -80,6 +80,7 @@ let ./programs/i3status-rust.nix ./programs/i3status.nix ./programs/info.nix + ./programs/ion.nix ./programs/irssi.nix ./programs/java.nix ./programs/jq.nix diff --git a/modules/programs/exa.nix b/modules/programs/exa.nix index ee497999..a7dfeb2b 100644 --- a/modules/programs/exa.nix +++ b/modules/programs/exa.nix @@ -32,5 +32,6 @@ in { programs.fish.shellAliases = mkIf cfg.enableAliases aliases; + programs.ion.shellAliases = mkIf cfg.enableAliases aliases; }; } diff --git a/modules/programs/ion.nix b/modules/programs/ion.nix new file mode 100644 index 00000000..0bda85c0 --- /dev/null +++ b/modules/programs/ion.nix @@ -0,0 +1,59 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.programs.ion; + + aliasesStr = concatStringsSep "\n" + (mapAttrsToList (k: v: "alias ${k} = ${escapeShellArg v}") + cfg.shellAliases); +in { + meta.maintainers = [ maintainers.jo1gi ]; + + options.programs.ion = { + enable = mkEnableOption "the Ion Shell. Compatible with Redox and Linux"; + + package = mkOption { + type = types.package; + default = pkgs.ion; + defaultText = literalExpression "pkgs.ion"; + description = '' + The ion package to install. May be used to change the version. + ''; + }; + + initExtra = mkOption { + type = types.lines; + default = ""; + description = '' + Ion script which is called during ion initialization. + ''; + }; + + shellAliases = mkOption { + type = with types; attrsOf str; + default = { }; + example = literalExpression '' + { + g = "git"; + } + ''; + description = '' + An attribute set that maps aliases (the top level attribute names + in this option) to command strings or directly to build outputs. + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + xdg.configFile."ion/initrc".text = '' + # Aliases + ${aliasesStr} + + ${cfg.initExtra} + ''; + }; +} diff --git a/modules/programs/starship.nix b/modules/programs/starship.nix index 85b41413..9aac5354 100644 --- a/modules/programs/starship.nix +++ b/modules/programs/starship.nix @@ -81,6 +81,14 @@ in { Whether to enable Fish integration. ''; }; + + enableIonIntegration = mkOption { + default = true; + type = types.bool; + description = '' + Whether to enable Ion integration. + ''; + }; }; config = mkIf cfg.enable { @@ -107,5 +115,11 @@ in { eval (${starshipCmd} init fish) end ''; + + programs.ion.initExtra = mkIf cfg.enableIonIntegration '' + if test $TERM != "dumb" && not exists -s INSIDE_EMACS || test $INSIDE_EMACS = "vterm" + eval $(${starshipCmd} init ion) + end + ''; }; }