2021-03-13 01:01:00 +01:00
|
|
|
{ config, lib, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.my.home.direnv;
|
|
|
|
in
|
2021-02-19 22:19:20 +01:00
|
|
|
{
|
2022-04-13 10:04:38 +02:00
|
|
|
options.my.home.direnv = with lib; {
|
|
|
|
enable = my.mkDisableOption "direnv configuration";
|
|
|
|
|
|
|
|
defaultFlake = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "pkgs";
|
|
|
|
example = "nixpkgs";
|
|
|
|
description = ''
|
|
|
|
Which flake from the registry should be used for
|
|
|
|
<command>use pkgs</command> by default.
|
|
|
|
'';
|
|
|
|
};
|
2021-03-13 01:01:00 +01:00
|
|
|
};
|
|
|
|
|
2022-04-12 17:01:11 +02:00
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
programs.direnv = {
|
2021-06-27 00:54:55 +02:00
|
|
|
enable = true;
|
2022-04-12 17:01:11 +02:00
|
|
|
nix-direnv = {
|
|
|
|
# A better `use_nix`
|
|
|
|
enable = true;
|
|
|
|
};
|
2021-06-27 00:54:55 +02:00
|
|
|
};
|
2022-04-12 17:01:11 +02:00
|
|
|
|
|
|
|
xdg.configFile =
|
|
|
|
let
|
|
|
|
libDir = ./lib;
|
|
|
|
contents = builtins.readDir libDir;
|
|
|
|
names = lib.attrNames contents;
|
|
|
|
files = lib.filter (name: contents.${name} == "regular") names;
|
|
|
|
linkLibFile = name:
|
|
|
|
lib.nameValuePair
|
|
|
|
"direnv/lib/${name}"
|
|
|
|
{ source = libDir + "/${name}"; };
|
|
|
|
in
|
|
|
|
lib.my.genAttrs' files linkLibFile;
|
2022-04-13 10:04:38 +02:00
|
|
|
|
|
|
|
home.sessionVariables = {
|
|
|
|
DIRENV_DEFAULT_FLAKE = cfg.defaultFlake;
|
|
|
|
};
|
2021-02-19 22:19:20 +01:00
|
|
|
};
|
|
|
|
}
|