mirror of
https://gitee.com/amber-ce/amber-pm
synced 2026-06-22 06:03:55 +08:00
293ce7006c
将常用工具加入运行时PATH,确保activation脚本可以正常调用依赖命令
71 lines
1.9 KiB
Nix
71 lines
1.9 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
|
|
let
|
|
cfg = config.programs.amber-pm;
|
|
|
|
aceRuntimePath = lib.makeBinPath (with pkgs; [
|
|
bash
|
|
bubblewrap
|
|
coreutils
|
|
gawk
|
|
gnugrep
|
|
gnused
|
|
gnutar
|
|
sudo
|
|
]);
|
|
in
|
|
{
|
|
options.programs.amber-pm = {
|
|
enable = lib.mkEnableOption "Amber Package Manager";
|
|
|
|
package = lib.mkPackageOption pkgs "amber-pm" { };
|
|
|
|
initializeState = lib.mkOption {
|
|
type = lib.types.bool;
|
|
default = true;
|
|
description = "Create /var/lib/apm/apm during system activation when it does not already exist.";
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
programs.nix-ld.enable = lib.mkDefault true;
|
|
|
|
boot.kernel.sysctl."kernel.apparmor_restrict_unprivileged_userns" = lib.mkDefault 0;
|
|
|
|
system.activationScripts.amber-pm-state = lib.mkIf cfg.initializeState ''
|
|
export PATH="${aceRuntimePath}:$PATH"
|
|
target="/var/lib/apm/apm"
|
|
version_file="$target/.amber-pm-version"
|
|
current_version="${cfg.package.version}"
|
|
|
|
if [ ! -e "$target" ]; then
|
|
echo "APM state directory not found, initializing..."
|
|
${cfg.package}/bin/amber-pm-init-state
|
|
echo "Running ace-init for first-time setup..."
|
|
/var/lib/apm/apm/files/bin/ace-init
|
|
elif [ -f "$version_file" ]; then
|
|
stored_version="$(cat "$version_file")"
|
|
if [ "$stored_version" != "$current_version" ]; then
|
|
echo "APM version changed ($stored_version -> $current_version), re-initializing..."
|
|
${cfg.package}/bin/amber-pm-init-state --force
|
|
echo "Running ace-init..."
|
|
/var/lib/apm/apm/files/bin/ace-init
|
|
else
|
|
echo "APM version unchanged ($current_version), skipping ace-init."
|
|
fi
|
|
else
|
|
echo "No version file found, refreshing state and running ace-init..."
|
|
${cfg.package}/bin/amber-pm-init-state --force
|
|
/var/lib/apm/apm/files/bin/ace-init
|
|
fi
|
|
'';
|
|
};
|
|
}
|