aboutsummaryrefslogtreecommitdiff
path: root/modules/targets/generic-linux.nix
blob: bdb27926fbcfed9b5fa9f89fd58ece82c7934a8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{ config, lib, pkgs, ... }:

with lib;

let

  profileDirectory = config.home.profileDirectory;

in {
  options.targets.genericLinux.enable = mkEnableOption "" // {
    description = ''
      Whether to enable settings that make Home Manager work better on
      GNU/Linux distributions other than NixOS.
    '';
  };

  config = mkIf config.targets.genericLinux.enable {
    home.sessionVariables = let
      profiles =
        [ "\${NIX_STATE_DIR:-/nix/var/nix}/profiles/default" profileDirectory ];
      dataDirs =
        concatStringsSep ":" (map (profile: "${profile}/share") profiles);
    in { XDG_DATA_DIRS = "${dataDirs}\${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS"; };

    home.sessionVariablesExtra = ''
      . "${pkgs.nix}/etc/profile.d/nix.sh"
    '';

    # We need to source both nix.sh and hm-session-vars.sh as noted in
    # https://github.com/rycee/home-manager/pull/797#issuecomment-544783247
    programs.bash.initExtra = ''
      . "${pkgs.nix}/etc/profile.d/nix.sh"
      . "${profileDirectory}/etc/profile.d/hm-session-vars.sh"
    '';

    systemd.user.sessionVariables = {
      NIX_PATH = "$HOME/.nix-defexpr/channels\${NIX_PATH:+:}$NIX_PATH";
    };
  };
}