-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·66 lines (62 loc) · 2.12 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·66 lines (62 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env bash
set -euo pipefail
# gitやjqがPATHにない場合PATHに追加して再実行。
# Nix-on-Droidの初期環境などではインストールされていないため必要。
missing_packages=()
command -v git >/dev/null 2>&1 || missing_packages+=('nixpkgs#git')
command -v jq >/dev/null 2>&1 || missing_packages+=('nixpkgs#jq')
if [ ${#missing_packages[@]} -gt 0 ]; then
exec nix shell "${missing_packages[@]}" --command "$0" "$@"
fi
# `stage_last_commit`で利用するファイルをクリーンアップすることを試みます。
# 失敗しても無害なファイルが残るだけなため、
# エラーは無視します。
cleanup_last_commit() {
git reset -- last-commit.json 2>/dev/null || true
if command -v trash >/dev/null 2>&1; then
trash last-commit.json 2>/dev/null || true
else
rm last-commit.json 2>/dev/null || true
fi
}
# 最新コミットの情報をlast-commit.jsonに保存してstagingします。
# flakeはstagingされたファイルのみをソースに含めるため、
# 一時的にgit addで注入してrebuild後にunstageします。
# last-commit.jsonのstagingで必ずdirtyになるため、注入前に本来のdirty状態を記録します。
stage_last_commit() {
local subject branch dirty
subject=$(git log -1 --format=%s)
branch=$(git rev-parse --abbrev-ref HEAD)
if git diff --quiet && git diff --cached --quiet; then
dirty=false
else
dirty=true
fi
jq -n \
--arg subject "$subject" \
--argjson dirty "$dirty" \
--arg branch "$branch" \
'{subject: $subject, dirty: $dirty, branch: $branch}' \
>last-commit.json
git add -f last-commit.json
trap cleanup_last_commit EXIT
}
if [ -f /etc/NIXOS ]; then
stage_last_commit
sudo nixos-rebuild switch --flake ".#$(hostname)"
elif [ -n "${TERMUX_VERSION:-}" ]; then
nix-on-droid switch --flake "."
else
case $(uname -m) in
x86_64)
home-manager --flake ".#x86_64-linux" -b "hm-bak" switch
;;
aarch64)
home-manager --flake ".#aarch64-linux" -b "hm-bak" switch
;;
*)
echo "未対応のプラットフォーム: $(uname -s)-$(uname -m)"
exit 1
;;
esac
fi