From b02a857c1ccbed8928dc69cf3dcd01079214bbec Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Wed, 12 Nov 2025 00:04:44 -0500 Subject: [PATCH] nixos/fish: fix indentation of generated files --- nixos/modules/programs/fish.nix | 16 ++++++++++++---- nixos/tests/fish.nix | 2 ++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/nixos/modules/programs/fish.nix b/nixos/modules/programs/fish.nix index 903752bc9a54..77131b159615 100644 --- a/nixos/modules/programs/fish.nix +++ b/nixos/modules/programs/fish.nix @@ -27,6 +27,14 @@ let envInteractiveShellInit = pkgs.writeText "interactiveShellInit" cfge.interactiveShellInit; + indentFishFile = + name: text: + pkgs.runCommand name { + nativeBuildInputs = [ cfg.package ]; + inherit text; + passAsFile = [ "text" ]; + } "fish_indent < $textPath > $out"; + sourceEnv = file: if cfg.useBabelfish then @@ -182,16 +190,16 @@ in }) { - etc."fish/nixos-env-preinit.fish".text = + etc."fish/nixos-env-preinit.fish".source = if cfg.useBabelfish then - '' + indentFishFile "nixos-env-preinit.fish" '' # source the NixOS environment config if [ -z "$__NIXOS_SET_ENVIRONMENT_DONE" ] source /etc/fish/setEnvironment.fish end '' else - '' + indentFishFile "nixos-env-preinit.fish" '' # This happens before $__fish_datadir/config.fish sets fish_function_path, so it is currently # unset. We set it and then completely erase it, leaving its configuration to $__fish_datadir/config.fish set fish_function_path ${pkgs.fishPlugins.foreign-env}/share/fish/vendor_functions.d $__fish_datadir/functions @@ -207,7 +215,7 @@ in } { - etc."fish/config.fish".text = '' + etc."fish/config.fish".source = indentFishFile "config.fish" '' # /etc/fish/config.fish: DO NOT EDIT -- this file has been generated automatically. # if we haven't sourced the general config, do it diff --git a/nixos/tests/fish.nix b/nixos/tests/fish.nix index 84ffd71f7ddc..75b2170167c8 100644 --- a/nixos/tests/fish.nix +++ b/nixos/tests/fish.nix @@ -24,5 +24,7 @@ machine.succeed( "fish -ic 'echo $fish_complete_path' | grep -q '/share/fish/completions /etc/fish/generated_completions /root/.cache/fish/generated_completions$'" ) + machine.wait_for_file("/etc/fish/config.fish") + config = machine.succeed("fish_indent -c /etc/fish/config.fish") ''; }