# nixos-config - My current NixOS configuration # # Copyright (C) 2025 Benedikt Peetz # SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of my nixos-config. # # You should have received a copy of the License along with this program. # If not, see . { config, lib, pkgs, sources, ... }: let cfg = config.soispha.programs.direnv; direnvCfg = config.home-manager.users.soispha.programs.direnv; inherit (sources) devshells nixpkgs; pre-cache = pkgs.runCommand "pre-cache.sh" {} '' cat "${./pre-cache.sh}" > $out substituteInPlace $out \ --replace-fail "%DEVSHELLS_REPO%" "${devshells}" \ --replace-fail "%DEVSHELLS_REPO_REF%" "${devshells.sourceInfo.rev}.${builtins.readFile "${nixpkgs}/.git-revision"}" ''; landrun-fish = pkgs.writeShellApplication { name = "landrun-fish"; text = builtins.readFile ./landrun-fish.sh; inheritPath = true; runtimeInputs = [ pkgs.landrun ]; }; direnvPkg = lib.getExe direnvCfg.package; in { options.soispha.programs.direnv = { enable = lib.mkEnableOption "direnv"; }; config = lib.mkIf cfg.enable { soispha.programs.fish.integrations.direnv = # fish '' set --global SHOULD_SANDBOX_DIRENV function _direnv_export_eval ${direnvPkg} export fish | source end function _direnv_hook --on-event fish_preexec --on-variable PWD if not set --query IN_DIRENV_SANDBOX; and set --query SHOULD_SANDBOX_DIRENV; and ${direnvPkg} status | grep 'Found RC path' --invert-match | grep 'No .envrc or .env loaded' --quiet # We found a rc path, but none are loaded. So we can start our shell. ${lib.getExe landrun-fish} --interactive --command='_direnv_export_eval' else _direnv_export_eval end end ''; home-manager.users.soispha = { programs.direnv = { enable = true; package = pkgs.direnv-patched; nix-direnv = { enable = true; package = pkgs.nix-direnv.override {nix = config.nix.package;}; }; # Handled by myself (and the script is overridden) enableBashIntegration = true; enableZshIntegration = true; enableFishIntegration = false; config = { warn_timeout = 0; # NOTE: Something variable is undeclared in the my default loaded stuff :/. <2026-08-18> # strict_env = true; # disable_stdin = true; }; }; xdg.configFile = { "direnv/lib/hm-pre-cache.sh" = { source = pre-cache; }; }; }; }; }