61 lines
1.9 KiB
Nix
61 lines
1.9 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
let
|
|
user = "dominik";
|
|
home = "/home/${user}";
|
|
npmPrefix = "${home}/.npm-global";
|
|
node = pkgs.nodejs; # or pkgs.nodejs_20
|
|
in {
|
|
home-manager.users.dominik = { config, lib, pkgs, ... }: {
|
|
home.packages = with pkgs; [
|
|
node
|
|
gnutar # provides `tar`
|
|
gzip # provides `gzip` used by tar
|
|
unzip
|
|
python314 # useful for codex model use
|
|
jq # useful for JSON processing
|
|
(pkgs.writeShellScriptBin "codex" ''
|
|
#!/usr/bin/env bash
|
|
export TMPDIR="''${TMPDIR:-$HOME/.cache/codex-tmp}"
|
|
export XDG_RUNTIME_DIR="''${XDG_RUNTIME_DIR:-$HOME/.cache/xdg-runtime}"
|
|
exec ${npmPrefix}/bin/codex "$@"
|
|
'')
|
|
];
|
|
|
|
# Ensure ~/.npmrc with a user prefix (no sudo needed)
|
|
home.file.".npmrc"= {
|
|
text = ''
|
|
prefix=${npmPrefix}
|
|
'';
|
|
force = true;
|
|
};
|
|
|
|
|
|
# Ensure the npm bin dir is on PATH for all shells
|
|
home.sessionPath = [
|
|
"${npmPrefix}/bin"
|
|
];
|
|
|
|
# Nice-to-have: visible variables in the shell
|
|
home.sessionVariables = {
|
|
NPM_CONFIG_PREFIX = npmPrefix;
|
|
};
|
|
|
|
home.activation.ensureCodexDirs = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
|
|
install -d -m 700 "${config.home.homeDirectory}/.cache/codex-tmp"
|
|
install -d -m 700 "${config.home.homeDirectory}/.cache/xdg-runtime"
|
|
'';
|
|
|
|
# Auto-install @openai/codex if it's not already there
|
|
# (idempotent on each `home-manager switch`)
|
|
home.activation.installCodexCli = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
|
|
export PATH=${node}/bin:${pkgs.gnutar}/bin:${pkgs.gzip}/bin:${pkgs.unzip}/bin:${pkgs.curl}/bin:$PATH
|
|
mkdir -p ${npmPrefix}
|
|
if [ ! -x "${npmPrefix}/bin/codex" ]; then
|
|
echo "Installing @openai/codex globally..."
|
|
# --global uses prefix from ~/.npmrc; PATH has node for postinstall
|
|
${node}/bin/npm install -g @openai/codex
|
|
fi
|
|
'';
|
|
};
|
|
}
|