From 287cbbbf80d460cd07ef66e05b92565b4b1eee6e Mon Sep 17 00:00:00 2001 From: jaredmontoya <49511278+jaredmontoya@users.noreply.github.com> Date: Fri, 21 Mar 2025 20:13:56 +0100 Subject: [PATCH] nix-your-shell: build-time nushell config generation --- modules/programs/nix-your-shell.nix | 15 +++++++------ .../programs/nix-your-shell/enable-shells.nix | 21 ++++++++----------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/modules/programs/nix-your-shell.nix b/modules/programs/nix-your-shell.nix index 05a6bfcbd..bcbc58bd3 100644 --- a/modules/programs/nix-your-shell.nix +++ b/modules/programs/nix-your-shell.nix @@ -25,22 +25,21 @@ in { programs = { fish.interactiveShellInit = lib.mkIf cfg.enableFishIntegration '' - ${cfg.package}/bin/nix-your-shell fish | source + ${lib.getExe cfg.package} fish | source ''; nushell = lib.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 - ''; - extraConfig = '' - source ${config.xdg.cacheHome}/nix-your-shell/init.nu + source ${ + pkgs.runCommand "nix-your-shell-nushell-config" { } '' + ${lib.getExe cfg.package} nu >> "$out" + '' + } ''; }; zsh.initContent = lib.mkIf cfg.enableZshIntegration '' - ${cfg.package}/bin/nix-your-shell zsh | source /dev/stdin + ${lib.getExe cfg.package} zsh | source /dev/stdin ''; }; }; diff --git a/tests/modules/programs/nix-your-shell/enable-shells.nix b/tests/modules/programs/nix-your-shell/enable-shells.nix index 8c136da4d..cb242aed1 100644 --- a/tests/modules/programs/nix-your-shell/enable-shells.nix +++ b/tests/modules/programs/nix-your-shell/enable-shells.nix @@ -1,4 +1,4 @@ -{ pkgs, config, ... }: +{ lib, pkgs, realPkgs, config, ... }: { programs = { @@ -13,6 +13,8 @@ zsh.enable = true; }; + _module.args.pkgs = lib.mkForce realPkgs; + nmt.script = let nushellConfigDir = if pkgs.stdenv.isDarwin && !config.xdg.enable then "home-files/Library/Application Support/nushell" @@ -20,23 +22,18 @@ "home-files/.config/nushell"; in '' assertFileExists home-files/.config/fish/config.fish - assertFileContains \ + assertFileRegex \ home-files/.config/fish/config.fish \ - '@nix-your-shell@/bin/nix-your-shell fish | source' + '/nix/store/[^/]*-nix-your-shell-[^/]*/bin/nix-your-shell fish | source' assertFileExists ${nushellConfigDir}/config.nu - assertFileContains \ + assertFileRegex \ ${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 nu | save --force ${config.xdg.cacheHome}/nix-your-shell/init.nu' + 'source /nix/store/[^/]*-nix-your-shell-nushell-config' assertFileExists home-files/.zshrc - assertFileContains \ + assertFileRegex \ home-files/.zshrc \ - '@nix-your-shell@/bin/nix-your-shell zsh | source /dev/stdin' + '/nix/store/[^/]*-nix-your-shell-[^/]*/bin/nix-your-shell zsh | source /dev/stdin' ''; }