diff --git a/share/modules/nixos-shell-config.nix b/share/modules/nixos-shell-config.nix index c0e8794..0638a45 100644 --- a/share/modules/nixos-shell-config.nix +++ b/share/modules/nixos-shell-config.nix @@ -106,6 +106,47 @@ in { xterm # for resize command ]; + extraSetup = lib.optionalString cfg.terminfo.fixFSCaseConflicts '' + nixosShell::symlinkToDir() ( + # this function runs in a subshell to make shopt local to this function + shopt -s nullglob + + local target="$1" + + if ! [[ -L "$target" && -d "$target" ]]; then + return + fi + + local linkTo="$(readlink "$target")" + rm "$target" + mkdir "$target" + + local files=( "$linkTo/"{.,}* ) + if (( ''${#files[@]} > 0 )); then + cp -s "''${files[@]}" "$target/" + fi + ) + + nixosShell::fixTerminfoFSCaseConflicts() { + nixosShell::symlinkToDir "$out" + nixosShell::symlinkToDir "$out/share" + nixosShell::symlinkToDir "$out/share/terminfo" + pushd "$out/share/terminfo" + + local c + for c in {a..z}; do + if [[ -d "$c" && -d "''${c@U}" && ! "$c" -ef ''${c@U} ]]; then + nixosShell::symlinkToDir "''${c@U}" + cp "$c/"* "''${c@U}/" + fi + done + + popd + } + + nixosShell::fixTerminfoFSCaseConflicts + ''; + loginShellInit = let pwd = builtins.getEnv "PWD"; diff --git a/share/modules/nixos-shell.nix b/share/modules/nixos-shell.nix index b32b7fd..4d679a3 100644 --- a/share/modules/nixos-shell.nix +++ b/share/modules/nixos-shell.nix @@ -1,5 +1,8 @@ { lib, pkgs, modulesPath, config, options, extendModules, ... }: +let + isDarwin = options.virtualisation.host.pkgs.isDefined && config.virtualisation.host.pkgs.stdenv.hostPlatform.isDarwin; +in { imports = [ "${toString modulesPath}/virtualisation/qemu-vm.nix" @@ -65,6 +68,15 @@ default = {}; }; }; + + terminfo.fixFSCaseConflicts = mkOption { + type = types.bool; + default = isDarwin; + description = '' + Whether to apply workaround for broken terminfo lookup on hosts with case insensitive file + systems. + ''; + }; }; config = let