summaryrefslogtreecommitdiffstats
path: root/lass/3modules/per-user.nix
blob: f8d357ce230b471ec1b29d3a3e88324effdb8f05 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
{ config, lib, pkgs, ... }:

with config.krebs.lib;
let
  cfg = config.lass.per-user;

  out = {
    options.lass.per-user = api;
    config = imp;
  };

  api = mkOption {
    type = with types; attrsOf (submodule {
      options = {
        packages = mkOption {
          type = listOf path;
          default = [];
        };
      };
    });
    default = {};
  };

  imp = {
    #
    # TODO only shellInit and use well-known paths
    #
    environment.shellInit = ''
      if test -e ${user-profiles}/"$LOGNAME"; then
        . ${user-profiles}/"$LOGNAME"
      fi
    '';
    environment.interactiveShellInit = ''
      if test -e ${user-profiles}/"$LOGNAME"; then
        . ${user-profiles}/"$LOGNAME"
      fi
    '';
    environment.profileRelativeEnvVars.PATH = mkForce [ "/bin" ];
  };

  user-profiles = pkgs.runCommand "user-profiles" {} ''
    mkdir $out
    ${concatStrings (mapAttrsToList (logname: { packages, ... }: ''
      cat > $out/${logname} <<\EOF
      ${optionalString (length packages > 0) (
        let path = makeSearchPath "bin" packages; in
        ''export PATH="$PATH":${escapeShellArg path}''
      )}
      EOF
    '') cfg)}
  '';

in out