nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
6.63k stars 1.74k forks source link

issue: XDG_XXX env vars are NOT getting created #5644

Open sim4life opened 1 month ago

sim4life commented 1 month ago

Are you following the right branch?

Is there an existing issue for this?

Issue description

Using WSL inside powershell, I installed home-manager v24.05 using curl and used Nixpkgs v24.05 channel. Then edited ~/.config/home-manager/home.nix and added: xdg.enable = true;

Afterwards, on the command line I run home-manager switch; I get XDG_RUNTIME_DIR and non-standard value of XDG_DATA_DIRS but I don't get to have other XDG_XXX environment variables created and assigned with proper values.

my ~/.config/home-manager/home.nix is:

{ config, pkgs, ... }:

{
  # Home Manager needs a bit of information about you and the paths it should
  # manage.
  home.username = "username";
  home.homeDirectory = "/home/username";
  # Enable XDG
  xdg.enable = true;

  home.stateVersion = "24.05"; # Please read the comment before changing.

  programs.gpg.enable = true;

  programs.ssh = {
    enable = true;

    matchBlocks = {
      bserv = {
        port = 22;
        hostname =  "106.403.111.118";
        user = "username-c";
        identityFile = "${config.home.homeDirectory}/.ssh/id_ssh";
      };
    };
  };

  programs.git = {
    enable = true;
    includes = [
      { path = "~/.git/.config-global"; }
      {
        path = "~/.git/.config-pri";
        condition = "gitdir:wa/pri/";
      }
    ];
    aliases = {
      ap = "add -p";
      aa = "add -A";
    };

    extraConfig = {
      core = {
        whitespace = "trailing-space,space-before-tab";
      };
    };
  };

  # The home.packages option allows you to install Nix packages into your
  # environment.
  home.packages = [
    # # Adds the 'hello' command to your environment. It prints a friendly
    # # "Hello, world!" when run.
    # pkgs.hello
    pkgs.openssh
    pkgs.curl
    pkgs.git
    pkgs.rsync
    pkgs.neovim
    pkgs.gpg-tui
    pkgs.xplr
    pkgs.wl-clipboard

    pkgs.cryptsetup
    pkgs.lvm2

    pkgs.difftastic
    pkgs.ripgrep-all
    pkgs.eza
    pkgs.fd
    pkgs.sd
    pkgs.bat
    pkgs.fastfetch

    pkgs.just
    pkgs.nushell

    pkgs.ansible

  ];

  home.file = {};

  # Let Home Manager install and manage itself.
  programs.home-manager.enable = true;
}

Any simple fix?

Maintainer CC

@ryce

System information

these 14 paths will be fetched (57.30 MiB download, 261.94 MiB unpacked):
  /nix/store/7v7g86ml0ri171gfcrs1d442px5bi1p3-binutils-2.41
  /nix/store/q5rp547zxf3mdah2v6dnp01iqq0lc8iz-binutils-2.41-lib
  /nix/store/bl7gf4crmr480jfm8raswv9xn2v1qwiw-binutils-wrapper-2.41
  /nix/store/fmg7v8k7ada9fnjsbav53pww340ikzls-expand-response-params
  /nix/store/llmjvk4i2yncv8xqdvs4382wr3kgdmvp-gcc-13.2.0
  /nix/store/r73z9i18vbjcph7k2f3isrysxzx6sqjx-gcc-wrapper-13.2.0
  /nix/store/0c5jp9d9h9818arr6s21xibgjl1ybql0-glibc-2.39-52-dev
  /nix/store/29baz8rp931kd6qniimm88p24sy2gsrq-gmp-6.3.0
  /nix/store/x47hg342iyiw50c1fhqjzz4n0rqy3dhh-isl-0.20
  /nix/store/yjrfh1bwblm9i2vdx8bda20j5c7pc8k2-libmpc-1.3.1
  /nix/store/m8852yw4iwgr173aa75jmc15gglcf24d-linux-headers-6.7
  /nix/store/zcw5dr0s4j986vsymhgrn2i2wy7pq7kv-mpfr-4.2.1
  /nix/store/ajkm0q5dak3nvqawpdafb62d708bqhrk-nix-info
  /nix/store/dd7nxjnni7nzm0846fq5xrm89ais5lwz-stdenv-linux
copying path '/nix/store/ajkm0q5dak3nvqawpdafb62d708bqhrk-nix-info' from 'https://cache.nixos.org'...
copying path '/nix/store/fmg7v8k7ada9fnjsbav53pww340ikzls-expand-response-params' from 'https://cache.nixos.org'...
copying path '/nix/store/m8852yw4iwgr173aa75jmc15gglcf24d-linux-headers-6.7' from 'https://cache.nixos.org'...
copying path '/nix/store/29baz8rp931kd6qniimm88p24sy2gsrq-gmp-6.3.0' from 'https://cache.nixos.org'...
copying path '/nix/store/q5rp547zxf3mdah2v6dnp01iqq0lc8iz-binutils-2.41-lib' from 'https://cache.nixos.org'...
copying path '/nix/store/x47hg342iyiw50c1fhqjzz4n0rqy3dhh-isl-0.20' from 'https://cache.nixos.org'...
copying path '/nix/store/zcw5dr0s4j986vsymhgrn2i2wy7pq7kv-mpfr-4.2.1' from 'https://cache.nixos.org'...
copying path '/nix/store/7v7g86ml0ri171gfcrs1d442px5bi1p3-binutils-2.41' from 'https://cache.nixos.org'...
copying path '/nix/store/yjrfh1bwblm9i2vdx8bda20j5c7pc8k2-libmpc-1.3.1' from 'https://cache.nixos.org'...
copying path '/nix/store/0c5jp9d9h9818arr6s21xibgjl1ybql0-glibc-2.39-52-dev' from 'https://cache.nixos.org'...
copying path '/nix/store/llmjvk4i2yncv8xqdvs4382wr3kgdmvp-gcc-13.2.0' from 'https://cache.nixos.org'...
copying path '/nix/store/bl7gf4crmr480jfm8raswv9xn2v1qwiw-binutils-wrapper-2.41' from 'https://cache.nixos.org'...
copying path '/nix/store/r73z9i18vbjcph7k2f3isrysxzx6sqjx-gcc-wrapper-13.2.0' from 'https://cache.nixos.org'...
copying path '/nix/store/dd7nxjnni7nzm0846fq5xrm89ais5lwz-stdenv-linux' from 'https://cache.nixos.org'...
 - system: `"x86_64-linux"`
 - host os: `Linux 5.15.153.1-microsoft-standard-WSL2, Ubuntu, 22.04.4 LTS (Jammy Jellyfish), nobuild`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.23.3`
 - nixpkgs: `/home/shah/.nix-defexpr/channels/nixpkgs`
sim4life commented 1 month ago

The solution was to write in home.nix:

programs.bash.enable = true;

It wasn't mentioned anywhere in Home-Manager Manual or Appendix. Perhaps it can be added to this document: Home Manager Manual

It can easily save precious hours/days of busy developers, whom are making use of Nix home-manager to maintain their work machines.

Liassica commented 1 month ago

The manual mentions that session variables have to be manually sourced if Home Manager isn't managing your shell configuration: https://nix-community.github.io/home-manager/index.xhtml#_why_are_the_session_variables_not_set

bestlem commented 1 month ago

@Liassica Yes but @sim4life "s point is that the alternative ie set programs.bash.enable = true; is not explicitly documented.

The implicit reference is

If you do not plan on having Home Manager manage your shell configuration

Now if you know Home manager you know that this includes enabling shells. If you are a beginner then this implication just means nothing.