{ inputs, pkgs, lib, config, ... }: let gitEnabled = config.mod.git.enable; goEnabled = config.mod.go.enable; vpnEnabled = config.mod.vpn.enable; in { home-manager.users.alex = { # Ensure bashInteractive is first in PATH inside nix devshells. # stdenv provides a non-interactive bash that breaks Copilot shell commands. # Adding bashInteractive to home.packages alone isn't enough because devshell # packages are prepended to PATH. This precmd hook runs after direnv's hook # and re-prepends bashInteractive so it takes priority. programs.zsh.initContent = '' _ensure_bash_interactive() { [[ "$PATH" == "${pkgs.bashInteractive}/bin:"* ]] || export PATH="${pkgs.bashInteractive}/bin:$PATH" } precmd_functions+=(_ensure_bash_interactive) # Source the zsh-specific rc file that nix-direnv emits ($DIRENV_ZSH_RC) # so devshell completions and zsh setup are picked up. direnv itself only # exports env vars, so without this hook the zsh side of the devshell is # never loaded. Guarded by LAST_LOADED_DIRENV_ZSH_RC so we don't re-source # it on every precmd. _nix_direnv_bridge_hook() { if [[ -n "$DIRENV_ZSH_RC" && "$LAST_LOADED_DIRENV_ZSH_RC" != "$DIRENV_ZSH_RC" ]]; then if [[ -f "$DIRENV_ZSH_RC" ]]; then source "$DIRENV_ZSH_RC" export LAST_LOADED_DIRENV_ZSH_RC="$DIRENV_ZSH_RC" echo "❄️ direnv zsh loaded..." fi fi } autoload -Uz add-zsh-hook add-zsh-hook precmd _nix_direnv_bridge_hook source ${./wt.zsh} ''; # Configure IntelliJ to exclude .direnv from indexing home.activation.intellijIgnoreDirenv = '' for idea_config in $HOME/.config/JetBrains/IntelliJIdea*; do if [ -d "$idea_config" ]; then $DRY_RUN_CMD mkdir -p "$idea_config/options" $DRY_RUN_CMD tee "$idea_config/options/filetypes.xml" > /dev/null <<'EOF' EOF fi done ''; home.sessionVariables = { GITHUB_ACTOR = "Alexander Heldt"; GITHUB_TOKEN = "$(${pkgs.coreutils}/bin/cat ${config.age.secrets.work-github-token.path})"; }; home.packages = [ # (pkgs.callPackage ./pants.nix { inherit (pkgs) stdenv.hostPlatform.system; }) (inputs.nix-jetbrains-plugins.lib.buildIdeWithPlugins pkgs "idea" [ "IdeaVIM" "com.github.copilot" ]) pkgs.bashInteractive (pkgs.google-cloud-sdk.withExtraComponents [ pkgs.google-cloud-sdk.components.gke-gcloud-auth-plugin ]) pkgs.graphite-cli pkgs.postman pkgs.grpcurl pkgs.slack # for `radio` pkgs.go-mockery pkgs.golangci-lint (pkgs.writeShellScriptBin "work-vpn" '' registered() { ! warp-cli --accept-tos status | ${pkgs.gnugrep}/bin/grep -q "Registration Missing" } connected() { warp-cli --accept-tos status | ${pkgs.gnugrep}/bin/grep -q "Status update: Connected" } wait-for() { for _ in $(${pkgs.coreutils}/bin/seq $1); do $2 && return 0 ${pkgs.coreutils}/bin/sleep 1 done return 1 } case $1 in up) if ! registered; then warp-cli --accept-tos registration new wait-for 300 registered fi warp-cli --accept-tos connect && wait-for 30 connected ;; down) warp-cli --accept-tos disconnect ;; esac '') ]; programs.go = lib.mkIf goEnabled { env = { GOPRIVATE = [ "$(${pkgs.coreutils}/bin/cat ${config.age.secrets.work-go-private.path})" ]; }; }; programs.git = lib.mkIf gitEnabled { includes = [ { path = config.age.secrets.work-gitconfig.path; condition = "gitdir:~/code/work/"; } ]; }; programs.rv = lib.mkIf gitEnabled { enable = true; settings = { tokenFile = config.age.secrets.work-github-token.path; teamsFile = config.age.secrets.work-rv-teams.path; }; }; systemd.user.services = lib.mkIf gitEnabled { rv.Service.WorkingDirectory = "%h/code/work"; }; }; home-manager.sharedModules = [ inputs.rv.homeManagerModules.default ]; # Ensure ~/code/work is owned by alex; it was previously created as root by # agenix when secrets had a custom path there. systemd.tmpfiles.rules = [ "d /home/alex/code 0755 alex users -" "d /home/alex/code/work 0755 alex users -" ]; # Needed for `copilot` programs.nix-ld.enable = true; programs.nix-ld.libraries = [ pkgs.stdenv.cc.cc.lib pkgs.zlib ]; age.secrets = { "work-gitconfig" = lib.mkIf gitEnabled { file = ../../../../secrets/pinwheel/work-gitconfig.age; owner = "alex"; group = "users"; }; "work-github-token" = lib.mkIf gitEnabled { file = ../../../../secrets/pinwheel/work-github-token.age; owner = "alex"; group = "users"; }; "work-rv-teams" = lib.mkIf gitEnabled { file = ../../../../secrets/pinwheel/work-rv-teams.age; owner = "alex"; group = "users"; }; "work-go-private" = lib.mkIf goEnabled { file = ../../../../secrets/pinwheel/work-go-private.age; owner = "alex"; group = "users"; }; "work-cloudflare-mdm" = lib.mkIf vpnEnabled { file = ../../../../secrets/pinwheel/work-cloudflare-mdm.age; path = "/var/lib/cloudflare-warp/mdm.xml"; symlink = false; }; }; }