66 lines
1.4 KiB
Nix
66 lines
1.4 KiB
Nix
{
|
|
user ? throw "user argument is required",
|
|
home ? throw "home argument is required",
|
|
}:
|
|
{
|
|
lib,
|
|
inputs,
|
|
system,
|
|
...
|
|
}:
|
|
{
|
|
home-manager.users.${user}.programs.zsh = {
|
|
shellAliases.nd = "nix-develop";
|
|
|
|
initContent =
|
|
let
|
|
devShells = lib.strings.concatStringsSep " " (
|
|
lib.attrsets.mapAttrsToList (key: _: key) inputs.self.devShells.${system}
|
|
);
|
|
in
|
|
''
|
|
nix-develop() {
|
|
local devshell=""
|
|
|
|
while getopts "s:" opt; do
|
|
case $opt in
|
|
s)
|
|
devshell=$OPTARG
|
|
;;
|
|
*)
|
|
echo "Usage: nix-develop [-s <devshell>]"
|
|
return 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [[ -z "$devshell" ]]; then
|
|
if [ ! -f flake.nix ]; then
|
|
cp "${./template.nix}" flake.nix
|
|
chmod 755 flake.nix
|
|
fi
|
|
|
|
if [ ! treefmt.nix ]; then
|
|
cp "${./treefmt.nix}" treefmt.nix
|
|
chmod 755 treefmt.nix
|
|
fi
|
|
|
|
nix develop -c "$SHELL"
|
|
else
|
|
nix develop self#"$devshell" -c "$SHELL"
|
|
fi
|
|
}
|
|
|
|
_nix-develop_completion() {
|
|
local options=(
|
|
'-s[Dev shell from root flake]:shell:(${devShells})'
|
|
)
|
|
|
|
_arguments -s $options
|
|
}
|
|
|
|
compdef _nix-develop_completion nix-develop
|
|
'';
|
|
};
|
|
}
|