From 8847063948bc7d2136b1d52fb58af63166e84421 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 13 Jul 2025 16:07:25 -0400 Subject: [PATCH] Install direnv. --- nix/configuration/configuration.nix | 3 +- nix/configuration/hosts/odo/default.nix | 1 + nix/configuration/hosts/quark/default.nix | 1 + nix/configuration/roles/direnv/default.nix | 55 ++++++++++++++++++++++ nix/configuration/roles/zsh/default.nix | 12 +++++ 5 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 nix/configuration/roles/direnv/default.nix diff --git a/nix/configuration/configuration.nix b/nix/configuration/configuration.nix index 7ce42e5..bf55f68 100644 --- a/nix/configuration/configuration.nix +++ b/nix/configuration/configuration.nix @@ -16,6 +16,7 @@ ./roles/boot ./roles/chromecast ./roles/chromium + ./roles/direnv ./roles/distributed_build ./roles/docker ./roles/ecc @@ -142,7 +143,7 @@ # Runs nix-collect-garbage --delete-older-than 5d automatic = true; persistent = true; - dates = "weekly"; + dates = "monthly"; # randomizedDelaySec = "14m"; options = "--delete-older-than 30d"; }; diff --git a/nix/configuration/hosts/odo/default.nix b/nix/configuration/hosts/odo/default.nix index 8ddbf38..18c22ff 100644 --- a/nix/configuration/hosts/odo/default.nix +++ b/nix/configuration/hosts/odo/default.nix @@ -64,6 +64,7 @@ me.bluetooth.enable = true; me.chromecast.enable = true; me.chromium.enable = true; + me.direnv.enable = true; me.docker.enable = true; me.ecc.enable = true; me.emacs_flavor = "full"; diff --git a/nix/configuration/hosts/quark/default.nix b/nix/configuration/hosts/quark/default.nix index b20526f..3ab36c7 100644 --- a/nix/configuration/hosts/quark/default.nix +++ b/nix/configuration/hosts/quark/default.nix @@ -59,6 +59,7 @@ me.bluetooth.enable = true; me.chromecast.enable = true; me.chromium.enable = true; + me.direnv.enable = true; me.docker.enable = true; me.ecc.enable = true; me.emacs_flavor = "full"; diff --git a/nix/configuration/roles/direnv/default.nix b/nix/configuration/roles/direnv/default.nix new file mode 100644 index 0000000..c184172 --- /dev/null +++ b/nix/configuration/roles/direnv/default.nix @@ -0,0 +1,55 @@ +{ + config, + lib, + pkgs, + ... +}: + +let + direnv_zsh_hook = pkgs.writeTextFile { + name = "direnv_zsh_hook.zsh"; + text = '' + eval "$(direnv hook zsh)" + ''; + }; +in +{ + imports = [ ]; + + options.me = { + direnv.enable = lib.mkOption { + type = lib.types.bool; + default = false; + example = true; + description = "Whether we want to install direnv."; + }; + }; + + config = lib.mkIf config.me.direnv.enable ( + lib.mkMerge [ + { + environment.systemPackages = with pkgs; [ + direnv + nix-direnv + ]; + + me.zsh.includes = [ direnv_zsh_hook ]; + + environment.persistence."/persist" = lib.mkIf (!config.me.buildingIso) { + hideMounts = true; + users.talexander = { + directories = [ + { + # List of allowed directories from `direnv allow`. + directory = ".local/share/direnv"; + user = "talexander"; + group = "talexander"; + mode = "0755"; + } + ]; + }; + }; + } + ] + ); +} diff --git a/nix/configuration/roles/zsh/default.nix b/nix/configuration/roles/zsh/default.nix index 1a7478d..518fdda 100644 --- a/nix/configuration/roles/zsh/default.nix +++ b/nix/configuration/roles/zsh/default.nix @@ -49,6 +49,8 @@ let source ${pkgs.zsh-histdb}/share/zsh/plugins/zsh-histdb/histdb-interactive.zsh bindkey '^r' _histdb-isearch + + ${lib.concatMapStringsSep "\n" (item: "source ${item}") config.me.zsh.includes} ''; }; in @@ -62,6 +64,16 @@ in example = true; description = "Whether we want to install zsh."; }; + zsh.includes = lib.mkOption { + type = lib.types.listOf lib.types.package; + default = [ ]; + example = lib.literalExpression '' + [ (pkgs.writeTextFile { + name = "launch-kanshi.conf"; + text = "exec kanshi"; + }) ]''; + description = "List of zshrc files to import."; + }; }; config = lib.mkIf config.me.zsh.enable (