From dd651e30f340d823bb9e72e3573c300cea3cca13 Mon Sep 17 00:00:00 2001 From: Bernardo Meurer Date: Mon, 9 Dec 2024 11:32:42 -0500 Subject: [PATCH] nix-your-shell: add nom (nix-output-monitor) support `nix-your-shell` has a feature where you can pass `--nom` to it in order to have it use `nix-output-monitor` monitor by default for `nix` invocations. This commit adds support for that in the relevant module. --- modules/programs/nix-your-shell.nix | 21 ++++++-- .../programs/nix-your-shell/default.nix | 5 +- .../programs/nix-your-shell/enable-nom.nix | 49 +++++++++++++++++++ 3 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 tests/modules/programs/nix-your-shell/enable-nom.nix diff --git a/modules/programs/nix-your-shell.nix b/modules/programs/nix-your-shell.nix index 20b5fd19e..47ae51503 100644 --- a/modules/programs/nix-your-shell.nix +++ b/modules/programs/nix-your-shell.nix @@ -27,20 +27,29 @@ in { enableZshIntegration = mkEnableOption "Zsh integration" // { default = true; }; + + enableNom = mkEnableOption "nom (nix-output-monitor) integration"; }; config = mkIf cfg.enable { - home.packages = [ cfg.package ]; + home.packages = [ cfg.package ] + ++ (optionals cfg.enableNom [ pkgs.nix-output-monitor ]); - programs = { + programs = let + argsForShell = shell: + concatStringsSep " " + ([ ] ++ (optional cfg.enableNom "--nom") ++ [ "${shell}" ]); + in { fish.interactiveShellInit = mkIf cfg.enableFishIntegration '' - ${cfg.package}/bin/nix-your-shell fish | source + ${cfg.package}/bin/nix-your-shell ${argsForShell "fish"} | source ''; nushell = mkIf cfg.enableNushellIntegration { extraEnv = '' mkdir ${config.xdg.cacheHome}/nix-your-shell - ${cfg.package}/bin/nix-your-shell nu | save --force ${config.xdg.cacheHome}/nix-your-shell/init.nu + ${cfg.package}/bin/nix-your-shell ${ + argsForShell "nu" + } | save --force ${config.xdg.cacheHome}/nix-your-shell/init.nu ''; extraConfig = '' @@ -49,7 +58,9 @@ in { }; zsh.initExtra = mkIf cfg.enableZshIntegration '' - ${cfg.package}/bin/nix-your-shell zsh | source /dev/stdin + ${cfg.package}/bin/nix-your-shell ${ + argsForShell "zsh" + } | source /dev/stdin ''; }; }; diff --git a/tests/modules/programs/nix-your-shell/default.nix b/tests/modules/programs/nix-your-shell/default.nix index 06d2f688c..d8173dc0f 100644 --- a/tests/modules/programs/nix-your-shell/default.nix +++ b/tests/modules/programs/nix-your-shell/default.nix @@ -1 +1,4 @@ -{ nix-your-shell-enable-shells = ./enable-shells.nix; } +{ + nix-your-shell-enable-shells = ./enable-shells.nix; + nix-your-shell-enable-nom = ./enable-nom.nix; +} diff --git a/tests/modules/programs/nix-your-shell/enable-nom.nix b/tests/modules/programs/nix-your-shell/enable-nom.nix new file mode 100644 index 000000000..a32faa45c --- /dev/null +++ b/tests/modules/programs/nix-your-shell/enable-nom.nix @@ -0,0 +1,49 @@ +{ pkgs, config, ... }: + +{ + programs = { + nix-your-shell = { + enable = true; + enableFishIntegration = true; + enableNushellIntegration = true; + enableZshIntegration = true; + enableNom = true; + }; + fish.enable = true; + nushell.enable = true; + zsh.enable = true; + }; + + test.stubs = { + nix-your-shell = { }; + nushell = { }; + zsh = { }; + }; + + nmt.script = let + nushellConfigDir = if pkgs.stdenv.isDarwin && !config.xdg.enable then + "home-files/Library/Application Support/nushell" + else + "home-files/.config/nushell"; + in '' + assertFileExists home-files/.config/fish/config.fish + assertFileContains \ + home-files/.config/fish/config.fish \ + '@nix-your-shell@/bin/nix-your-shell --nom fish | source' + + assertFileExists ${nushellConfigDir}/config.nu + assertFileContains \ + ${nushellConfigDir}/config.nu \ + 'source ${config.xdg.cacheHome}/nix-your-shell/init.nu' + + assertFileExists ${nushellConfigDir}/env.nu + assertFileContains \ + ${nushellConfigDir}/env.nu \ + '@nix-your-shell@/bin/nix-your-shell --nom nu | save --force ${config.xdg.cacheHome}/nix-your-shell/init.nu' + + assertFileExists home-files/.zshrc + assertFileContains \ + home-files/.zshrc \ + '@nix-your-shell@/bin/nix-your-shell --nom zsh | source /dev/stdin' + ''; +}