nixos/roles/home/zsh.nix
2023-03-19 12:23:48 -07:00

58 lines
1.1 KiB
Nix

{ config, pkgs, lib, optionalString, ... }:
let
inherit (pkgs.lib) optionalString;
# not having the attribute users means
# we cannot change the default shell (e.g. this is not a NixOS host)
exec_zsh = ''
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
exec ${pkgs.zsh}/bin/zsh
'';
nix_run_fn = ''
function _nr {
if [ "$#" -lt 1 ]; then
echo "Usage: _nr <pkg>"
return
fi
quoted_args=()
local pkg=$1
shift 1
for a in "$@"; do
quoted_args+=("\"$a\"")
done
echo ''${quoted_args[@]}
# `nix run nixpkgs#$pkg -- ''${quoted_args[@]}`
exec nix run nixpkgs#$pkg "$@"
}
'';
in
{
programs.zsh = {
enable = true;
oh-my-zsh = {
enable = true;
plugins = [ "git" "sudo" "docker" "docker-compose" "adb" "systemd" ];
theme = "bira";
};
};
home.file.".bashrc".text = ''
${nix_run_fn}
${optionalString (!builtins.hasAttr "users" config) "${exec_zsh}"}
'';
home.file.".zshrc".text = nix_run_fn;
}