diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 2d2c8dc01..82433473f 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -78,6 +78,9 @@ /modules/programs/noti.nix @marsam +/modules/programs/nushell.nix @Philipp-M +/tests/modules/programs/nushell @Philipp-M + /modules/programs/obs-studio.nix @adisbladis /modules/programs/opam.nix @marsam diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 3009ae7bb..608fcc2b2 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1604,6 +1604,13 @@ in A new module is available: 'programs.ne' ''; } + + { + time = "2020-07-24T15:03:11+00:00"; + message = '' + A new module is available: 'programs.nushell'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index a7054f381..6d24cb672 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -95,6 +95,7 @@ let (loadModule ./programs/newsboat.nix { }) (loadModule ./programs/noti.nix { }) (loadModule ./programs/notmuch.nix { }) + (loadModule ./programs/nushell.nix { }) (loadModule ./programs/obs-studio.nix { }) (loadModule ./programs/offlineimap.nix { }) (loadModule ./programs/opam.nix { }) diff --git a/modules/programs/nushell.nix b/modules/programs/nushell.nix new file mode 100644 index 000000000..1eb42f951 --- /dev/null +++ b/modules/programs/nushell.nix @@ -0,0 +1,68 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.nushell; + + configFile = config: + pkgs.runCommand "config.toml" { + buildInputs = [ pkgs.remarshal ]; + preferLocalBuild = true; + allowSubstitutes = false; + } '' + remarshal -if json -of toml \ + < ${pkgs.writeText "config.json" (builtins.toJSON config)} \ + > $out + ''; + +in { + meta.maintainers = [ maintainers.Philipp-M ]; + + options.programs.nushell = { + enable = mkEnableOption "nushell"; + + package = mkOption { + type = types.package; + default = pkgs.nushell; + defaultText = literalExample "pkgs.nushell"; + description = "The package to use for nushell."; + }; + + settings = mkOption { + type = with types; + let + prim = oneOf [ bool int str ]; + primOrPrimAttrs = either prim (attrsOf prim); + entry = either prim (listOf primOrPrimAttrs); + entryOrAttrsOf = t: either entry (attrsOf t); + entries = entryOrAttrsOf (entryOrAttrsOf entry); + in attrsOf entries // { description = "Nushell configuration"; }; + default = { }; + example = literalExample '' + { + edit_mode = "vi"; + startup = [ "alias la [] { ls -a }" "alias e [msg] { echo $msg }" ]; + key_timeout = 10; + completion_mode = "circular"; + no_auto_pivot = true; + } + ''; + description = '' + Configuration written to + ~/.config/nushell/config.toml. + + See for the full list + of options. + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + xdg.configFile."nu/config.toml" = + mkIf (cfg.settings != { }) { source = configFile cfg.settings; }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index cad8cd044..bad49546e 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -56,6 +56,7 @@ import nmt { ./modules/programs/ne ./modules/programs/neomutt ./modules/programs/newsboat + ./modules/programs/nushell ./modules/programs/qutebrowser ./modules/programs/readline ./modules/programs/powerline-go diff --git a/tests/modules/programs/nushell/default.nix b/tests/modules/programs/nushell/default.nix new file mode 100644 index 000000000..5b3bfa1a5 --- /dev/null +++ b/tests/modules/programs/nushell/default.nix @@ -0,0 +1 @@ +{ nushell-settings = ./settings.nix; } diff --git a/tests/modules/programs/nushell/settings-expected.toml b/tests/modules/programs/nushell/settings-expected.toml new file mode 100644 index 000000000..87c5de250 --- /dev/null +++ b/tests/modules/programs/nushell/settings-expected.toml @@ -0,0 +1,5 @@ +completion_mode = "circular" +edit_mode = "vi" +key_timeout = 10 +no_auto_pivot = true +startup = ["alias la [] { ls -a }", "alias e [msg] { echo $msg }"] diff --git a/tests/modules/programs/nushell/settings.nix b/tests/modules/programs/nushell/settings.nix new file mode 100644 index 000000000..09c192b3b --- /dev/null +++ b/tests/modules/programs/nushell/settings.nix @@ -0,0 +1,34 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.nushell = { + enable = true; + + settings = mkMerge [ + { + edit_mode = "vi"; + startup = [ "alias la [] { ls -a }" ]; + completion_mode = "circular"; + key_timeout = 10; + } + + { + startup = [ "alias e [msg] { echo $msg }" ]; + no_auto_pivot = true; + } + ]; + }; + + nixpkgs.overlays = + [ (self: super: { nushell = pkgs.writeScriptBin "dummy-nushell" ""; }) ]; + + nmt.script = '' + assertFileContent \ + home-files/.config/nu/config.toml \ + ${./settings-expected.toml} + ''; + }; +}