-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup
executable file
·153 lines (117 loc) · 3.56 KB
/
setup
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env sh
set -e
###
# UTILS & VARS
###
GREEN="\033[0;32m"
BLUE="\033[0;34m"
YELLOW="\033[0;33m"
RED="\033[0;31m"
RESET="\033[0m"
DIR_NAME="$(realpath "$(dirname "$0")")"
PACKAGES_DIR="$DIR_NAME/packages"
FLATPAK_APPS="$(cat "$PACKAGES_DIR"/flatpak-apps)"
FLATPAK_RUNTIMES="$(cat "$PACKAGES_DIR"/flatpak-runtimes)"
log() {
case "$1" in
INFO)
printf "%b[%s]%b %s\n" "$BLUE" "INFO" "$RESET" "$2"
;;
WARNING)
printf "%b[%s]%b %s\n" "$YELLOW" "WARNING" "$RESET" "$2"
;;
SUCCESS)
printf "%b[%s]%b %s\n" "$GREEN" "SUCCESS" "$RESET" "$2"
;;
ERROR)
printf "%b[%s]%b %s\n" "$RED" "ERROR" "$RESET" "$2"
;;
esac
}
log_info() {
log "INFO" "$1"
}
log_success() {
log "SUCCESS" "$1"
}
log_warning() {
log "WARNING" "$1"
}
log_error() {
log "ERROR" "$1"
}
###
# STEPS
###
install_and_setup_nix() {
if command -v nix > /dev/null 2>&1; then
log_warning "Nix already installed, skipping installation"
return
fi
log_info "Install nix"
(set -x; curl -L https://nixos.org/nix/install | sh -s -- --no-daemon --yes --no-modify-profile)
# shellcheck disable=SC1091
. "$HOME"/.nix-profile/etc/profile.d/nix.sh
log_info "Add extra nix channels"
(set -x; nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager)
(set -x; nix-channel --add https://github.com/nix-community/nixGL/archive/main.tar.gz nixgl)
(set -x; nix-channel --update)
(set -x; nix-channel --list)
}
install_and_setup_home_manager() {
if command -v home-manager > /dev/null 2>&1; then
log_warning "Home-manager already installed, skipping installation"
return
fi
log_info "Install home manager"
(set -x; nix-shell '<home-manager>' -A install)
log_info "Set up home manager files"
(set -x; mkdir -p "$HOME"/.config/home-manager)
if [ -f "$HOME"/.config/home-manager/home.nix ]; then
(set -x; rm "$HOME"/.config/home-manager/home.nix)
fi
(set -x; ln -s "$HOME"/.dotfiles/nix/home.nix "$HOME"/.config/home-manager/home.nix)
}
install_home_manager_derivation() {
log_info "Install home manager packages"
(set -x; home-manager switch -b backup)
}
install_flatpak_apps_and_runtimes_step() {
if ! command -v flatpak > /dev/null 2>&1; then
log_warning "Flatpak is not installed, skipping"
return
fi
log_info "Adding flatpak remotes"
(set -x; flatpak remote-add --user --if-not-exists flathub-beta https://flathub.org/beta-repo/flathub-beta.flatpakrepo)
(set -x; flatpak remote-add --user --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo)
if [ -z "$FLATPAK_APPS" ]; then
log_warning "No flatpak apps to install, skipping instalation"
else
log_info "Install flatpak apps"
echo "$FLATPAK_APPS" | while read -r origin app; do
# shellcheck disable=SC2086
(set -x; flatpak install --user -y --noninteractive --or-update $origin $app)
done
fi
if [ -z "$FLATPAK_RUNTIMES" ]; then
log_warning "No flatpak runtimes to install, skipping instalation"
else
log_info "Install flatpak runtimes"
echo "$FLATPAK_RUNTIMES" | while read -r origin runtime; do
# shellcheck disable=SC2086
(set -x; flatpak install --user -y --noninteractive --or-update $origin $runtime)
done
fi
}
###
# MAIN
###
if [ "$(id -u)" -eq 0 ]; then
log_error "This script cannot be run as root. It will call sudo as needed"
exit 1
fi
install_and_setup_nix
install_and_setup_home_manager
install_home_manager_derivation
install_flatpak_apps_and_runtimes_step
log_success "All done, restart and open a new shell to get started !!!"