Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: nushell module w/ xdg.enable = true; on macOS has incorrect env and nu variables #6484

Open
2 tasks done
rykugur opened this issue Feb 17, 2025 · 1 comment
Open
2 tasks done
Assignees
Labels
bug triage Issues or feature request that have not been triaged yet

Comments

@rykugur
Copy link

rykugur commented Feb 17, 2025

Are you following the right branch?

  • My Nixpkgs and Home Manager versions are in sync

Is there an existing issue for this?

  • I have searched the existing issues

Issue description

I got a new MacBook the other day, but I also experienced this same issue on my work MacBook. I do not experience this issue on nixOS with the same HM module below.

With xdg.enable = false; (or commented out), my nushell config files get written to ~/Library/Application Support/nushell.

With xdg.enable = true;', my nushell config files get written to ~/.config/nushell.

Based on my reading of the HM module nix file, this is working as expected. In the former case above, everything (my config) works just fine. But I want to enable XDG for other apps that utilize it.

In the latter case, while the files show up in the right location:

Image

the only env variable for XDG that seems to get set is XDG_DATA_DIRS:

Image

in addition, my $nu.data-dir and $nu.config-dir variables are incorrect:

Image

Config files

Here's my nushell HM module:

{ config, lib, pkgs, ... }:
let
  cfg = config.rhx.nushell;
  nu-scripts = pkgs.fetchFromGitHub {
    owner = "nushell";
    repo = "nu_scripts";
    rev = "e380c8a355b4340c26dc51c6be7bed78f87b0c71";
    sha256 = "sha256-b2AeWiHRz1LbiGR1gOJHBV3H56QP7h8oSTzg+X4Shk8=";
  };
  # nupm = pkgs.fetchFromGitHub {
  #   owner = "nushell";
  #   repo = "nupm";
  #   rev = "7e3e5779ff86a1b8dadcf7a90eee2e3dcfe449df";
  #   sha256 = "sha256-BNFBQ9kK2/P7mjdBqMj/8cbBPVogK0n1qcx6dx9mer8=";
  # };
in {
  options.rhx.nushell = {
    enable = lib.mkEnableOption "Enable nushell home-manager module.";
  };

  config = lib.mkIf cfg.enable {
    programs.nushell = {
      enable = true;
      extraEnv = ''
        $env.LOCAL_CONFIG_FILE = $"($nu.data-dir)/vendor/autoload/config.nu"
        $env.DOTFILES_DIR = $"($env.HOME)/.dotfiles"
        $env.config.table.show_empty = false
        source ~/.dotfiles/configs/nu/env.nu
      '';
      extraConfig = ''
        source ${nu-scripts}/themes/nu-themes/catppuccin-mocha.nu
        source ${nu-scripts}/custom-completions/adb/adb-completions.nu
        source ${nu-scripts}/custom-completions/bat/bat-completions.nu
        source ${nu-scripts}/custom-completions/curl/curl-completions.nu
        source ${nu-scripts}/custom-completions/docker/docker-completions.nu
        source ${nu-scripts}/custom-completions/git/git-completions.nu
        source ${nu-scripts}/custom-completions/just/just-completions.nu
        source ${nu-scripts}/custom-completions/nix/nix-completions.nu
        source ${nu-scripts}/custom-completions/npm/npm-completions.nu
        source ${nu-scripts}/custom-completions/pnpm/pnpm-completions.nu
        source ${nu-scripts}/custom-completions/rg/rg-completions.nu
        source ${nu-scripts}/custom-completions/ssh/ssh-completions.nu
        source ${nu-scripts}/custom-completions/zellij/zellij-completions.nu
        source ${nu-scripts}/custom-menus/zoxide-menu.nu
        $env.config.hooks.pre_prompt = (
          $env.config.hooks.pre_prompt | append (source ${nu-scripts}/nu-hooks/nu-hooks/direnv/config.nu)
        )
        source ~/.dotfiles/configs/nu/config.nu
      '';
    };

    programs.direnv = {
      enable = true;
      enableNushellIntegration = true;
      nix-direnv.enable = true;
    };

    # programs.carapace = {
    #   enable = true;
    #   enableBashIntegration = false;
    #   enableNushellIntegration = true;
    #   enableZshIntegration = false;
    # };

    programs.starship = { enableNushellIntegration = true; };

    # programs.zoxide = {
    #   enable = true;
    #   enableNushellIntegration = true;
    # };
  };
}

Maintainer CC

@Philipp-M
@JoaquinTrinanes
@aidalgol

System information

I installed nix w/ the Determinate installer, per the instructions in the nix-darwin repo. I chose the vanilla nix install.

~/.config/nushell> nix-shell -p nix-info --run "nix-info -m"
 - system: `"aarch64-darwin"`
 - host os: `Darwin 24.3.0, macOS 15.3.1`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.24.12`
 - nixpkgs: `/nix/store/k8nkf470zpidpa5nh76lh2x6rxfzpwa4-source`
@rykugur rykugur added bug triage Issues or feature request that have not been triaged yet labels Feb 17, 2025
@rykugur
Copy link
Author

rykugur commented Feb 20, 2025

I tried setting XDG_CONFIG_HOME via both system.environmentVariables and home.sessionVariables, neither worked.

On my work MacBook, I worked around this issue (I think, it was a while ago and was a hack I've since mostly forgotten) by creating an environment.plist file in ~/Library/LaunchAgents/ that exported the XDG_CONFIG_HOME variable to /Users/{user}/.config. After a reboot, this seems to have worked in that nushell is now sourcing my config files in ~/.config, however, $nu.data-dir and other $nu.* variables are still set to ~/Library. Maybe this is a nushell bug?

EDIT: Another reboot and my config was not being sourced until I set xdg.enable = false; and rebuilt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug triage Issues or feature request that have not been triaged yet
Projects
None yet
Development

No branches or pull requests

4 participants