fork/home-manager

git clone https://git.julia.blue/fork/home-manager

David Arnoldtargets/generic-linux: use the correct nix package183a62f3

master
3.2 KiB107 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.targets.genericLinux;
8
9  profileDirectory = config.home.profileDirectory;
10
11  nixPkg = if config.nix.package == null then pkgs.nix else config.nix.package;
12
13in {
14  imports = [
15    (mkRenamedOptionModule [ "targets" "genericLinux" "extraXdgDataDirs" ] [
16      "xdg"
17      "systemDirs"
18      "data"
19    ])
20  ];
21
22  options.targets.genericLinux = {
23    enable = mkEnableOption "" // {
24      description = ''
25        Whether to enable settings that make Home Manager work better on
26        GNU/Linux distributions other than NixOS.
27      '';
28    };
29  };
30
31  config = mkIf cfg.enable {
32    assertions = [
33      (hm.assertions.assertPlatform "targets.genericLinux" pkgs platforms.linux)
34    ];
35
36    xdg.systemDirs.data = [
37      # Nix profiles
38      "\${NIX_STATE_DIR:-/nix/var/nix}/profiles/default/share"
39      "${profileDirectory}/share"
40
41      # Distribution-specific
42      "/usr/share/ubuntu"
43      "/usr/local/share"
44      "/usr/share"
45      "/var/lib/snapd/desktop"
46    ];
47
48    # We need to append system-wide FHS directories due to the default prefix
49    # resolving to the Nix store.
50    # https://github.com/nix-community/home-manager/pull/2891#issuecomment-1101064521
51    home.sessionVariables = {
52      XCURSOR_PATH = "$XCURSOR_PATH\${XCURSOR_PATH:+:}" + concatStringsSep ":" [
53        "${config.home.profileDirectory}/share/icons"
54        "/usr/share/icons"
55        "/usr/share/pixmaps"
56      ];
57    };
58
59    home.sessionVariablesExtra = ''
60      . "${nixPkg}/etc/profile.d/nix.sh"
61
62      # reset TERM with new TERMINFO available (if any)
63      export TERM="$TERM"
64    '';
65
66    # We need to source both nix.sh and hm-session-vars.sh as noted in
67    # https://github.com/nix-community/home-manager/pull/797#issuecomment-544783247
68    programs.bash.initExtra = ''
69      . "${nixPkg}/etc/profile.d/nix.sh"
70      . "${profileDirectory}/etc/profile.d/hm-session-vars.sh"
71    '';
72
73    programs.zsh.envExtra = ''
74      # Make system functions available to zsh
75      () {
76        setopt LOCAL_OPTIONS CASE_GLOB EXTENDED_GLOB
77
78        local system_fpaths=(
79            # Package default
80            /usr/share/zsh/site-functions(/-N)
81
82            # Debian
83            /usr/share/zsh/functions/**/*(/-N)
84            /usr/share/zsh/vendor-completions/(/-N)
85            /usr/share/zsh/vendor-functions/(/-N)
86        )
87        fpath=(''${fpath} ''${system_fpaths})
88      }
89    '';
90
91    systemd.user.sessionVariables = let
92      # https://github.com/archlinux/svntogit-packages/blob/packages/ncurses/trunk/PKGBUILD
93      # https://salsa.debian.org/debian/ncurses/-/blob/master/debian/rules
94      # https://src.fedoraproject.org/rpms/ncurses/blob/main/f/ncurses.spec
95      # https://gitweb.gentoo.org/repo/gentoo.git/tree/sys-libs/ncurses/ncurses-6.2-r1.ebuild
96      distroTerminfoDirs = concatStringsSep ":" [
97        "/etc/terminfo" # debian, fedora, gentoo
98        "/lib/terminfo" # debian
99        "/usr/share/terminfo" # package default, all distros
100      ];
101    in {
102      NIX_PATH = "$HOME/.nix-defexpr/channels\${NIX_PATH:+:}$NIX_PATH";
103      TERMINFO_DIRS =
104        "${profileDirectory}/share/terminfo:$TERMINFO_DIRS\${TERMINFO_DIRS:+:}${distroTerminfoDirs}";
105    };
106  };
107}