2024-03-25 15:38:14 +08:00

91 lines
3.1 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# mod.nu -- example dotfile 的配置
#
# Copyright (C) 2022 KAAAsS
use ../knotfiles/log.nu
use ../knotfiles/dotfile *
export def module_name [] {
"example_module"
}
# 声明模块相关的文件
export def --env declare_files [] {
# 普通文件的声明。目标文件位于 ~/.config/example.yml
declare (module_name) "example_module/example.yml" ".config/example.yml"
# 增加 --local-only 则可以声明本地文件。此类文件用于管理本地环境相关的配置,不参与同步。
# 如果相关的本地文件不存在,则会根据对应的 .example 文件创建一个。
declare (module_name) "example_module/example.local.yml" ".config/example.local.yml" --local-only
}
# 声明环境约束
export def constraints [] {
# 环境约束用于根据当前安装的环境来确定该配置模块是否应该被启用。如:当约束包含了 "os/linux"
# 则只有在当前系统为 linux 时才会启用该模块,否则该配置会在实际安装时被忽略。可以使用命令
# `./dotfiles constraints` 来查看当前支持的全部约束,及其在当前环境中是否被满足。
#
# 此外,用户配置中也可以定义新的约束。建议在模块的 `register` 函数的一开始进行定义。
#
# ```nushell
# use ../knotfiles/dotfile
#
# dotfile register_custom_constraint "kde5" {
# use ../knotfiles/pkg.nu
#
# pkg check_install? "plasma-desktop"
# }
# ```
#
[ "os/linux", "gui" ]
}
# 声明依赖包
export def dependencies [] {
# 可以设置包管理器,这样只有对应包管理器的包才会被安装,若无匹配则忽略
[
# 依赖包会在安装前钩子运行前(同理也在安装配置前)进行检查,如果依赖包未安装,则会自动安装
"bat",
# 可以通过 record 设置包名。只有当前环境中存在对应的包管理器时才会安装对应的包,否则会直接
# 忽略安装。例如,下列配置在 Ubuntu包管理器为 apt下会被直接忽略。
{
"pacman": "bind-tools",
"homebrew": "bind",
}
]
}
# 安装前钩子,用于配置环境等等
export def pre_install [] {
# 如果需要使用家目录,则应该使用:$env.HOME_DIR
log info "将在安装前触发"
}
# 安装后钩子,用于配置启动项等等
export def post_install [] {
log info "将在安装后触发"
}
# 卸载前钩子,用于停止程序等等
export def pre_uninstall [] {
# 如果需要使用家目录,则应该使用:$env.HOME_DIR
log info "将在卸载前触发"
}
# 卸载后钩子,用于还原环境等等
export def post_uninstall [] {
log info "将在卸载后触发"
}
# 注册当前模块
export def --env register [] {
declare_files
require_constraints (module_name) (constraints)
require_packages (module_name) (dependencies)
register_pre_install (module_name) { pre_install }
register_post_install (module_name) { post_install }
register_pre_uninstall (module_name) { pre_uninstall }
register_post_uninstall (module_name) { post_uninstall }
}