-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathJustfile
223 lines (178 loc) Β· 6.72 KB
/
Justfile
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# Set the default shell to bash for more features
set shell := ["bash", "-uc"]
# Determine the OS and set the appropriate rebuild command
os := `uname`
rebuild_cmd := if os == "Darwin" { "darwin-rebuild" } else { "sudo nixos-rebuild" }
rebuild_args := "--impure"
host := `hostname`
# Default recipe to show available commands
default:
@just --list
# Clean up and optimize the Nix store
gc:
#!/usr/bin/env bash
set -euo pipefail
echo -e "\nπ Starting garbage collection at $(date)\n"
sudo nix-env -p /nix/var/nix/profiles/system --delete-generations +3
sudo nix-collect-garbage --delete-older-than 7d
sudo nix store gc
sudo nix store optimise
echo -e "\nβ
Garbage collection completed at $(date)\n"
# Open a Nix REPL with trace
repl:
nix repl --show-trace
# Open a Nix REPL with nixpkgs
repl-nixpkgs:
nix repl -f flake:nixpkgs
# Build with verbose output and no cache
build-verbose-no-cache:
#!/usr/bin/env bash
set -euo pipefail
echo -e "\nπ¨ Building with verbose output and no cache using \033[1;34m{{ rebuild_cmd }}\033[0m at $(date)...\n"
{{ rebuild_cmd }} build \
--flake .#{{ host }} \
--option eval-cache false \
--show-trace \
--print-build-logs \
--verbose {{ rebuild_args }}
echo -e "\nβ
Build completed at $(date)\n"
# Build with verbose output
build-verbose:
#!/usr/bin/env bash
set -euo pipefail
echo -e "\nπ¨ Building with verbose output using \033[1;34m{{ rebuild_cmd }}\033[0m at $(date)...\n"
{{ rebuild_cmd }} build \
--flake .#{{ host }} \
--show-trace \
--print-build-logs \
--verbose {{ rebuild_args }}
echo -e "\nβ
Build completed at $(date)\n"
build:
#!/usr/bin/env bash
set -euo pipefail
echo -e "\nπ¨ Building for '{{ host }}' on '{{ os }}' using \033[1;34m{{ rebuild_cmd }}\033[0m...\n"
echo -e "π¨ Host: \033[1;32m{{ host }}\033[0m"
echo -e "πΉ OS: \033[1;32m{{ os }}\033[0m"
echo -e "πΉ Command: \033[1;32m{{ rebuild_cmd }}\033[0m\n"
{{ rebuild_cmd }} build \
--flake .#{{ host }} \
{{ rebuild_args }}
# Switch configuration using the detected rebuild command with retries
switch:
#!/usr/bin/env bash
set -euo pipefail
echo -e "\nπ Switching configuration for '{{ host }}' on '{{ os }}' using \033[1;34m{{ rebuild_cmd }}\033[0m at $(date)...\n"
for i in {1..3}; do
if {{ rebuild_cmd }} switch --flake .#{{ host }} --impure; then
echo -e "β
Switch successful on attempt $i at $(date)\n"
exit 0
else
echo -e "β Switch failed on attempt $i at $(date), retrying in 5 seconds...\n"
sleep 5
fi
done
echo -e "β Switch failed after 3 attempts at $(date)\n"
exit 1
boot:
#!/usr/bin/env bash
set -euo pipefail
echo -e "\nπ Setting configuration on {{ os }} using \033[1;34m{{ rebuild_cmd }}\033[0m for next boot...\n"
for i in {1..3}; do
if {{ rebuild_cmd }} boot --flake .#{{ host }} --impure; then
echo -e "β
Build successful on attempt $i\n"
exit 0
else
echo -e "β Build failed on attempt $i, retrying in 5 seconds...\n"
sleep 5
fi
done
echo -e "β Build failed after 3 attempts\n"
exit 1
# Update dconf settings
update-dconf:
#!/usr/bin/env bash
set -euo pipefail
echo -e "\nπ Updating dconf settings at $(date)...\n"
# Base directory for dconf settings
TARGET_DIR="./modules/home-manager/features-linux/gnome/dconf"
mkdir -p "$TARGET_DIR"
# Array to store successfully generated files
declare -a generated_files
# Function to process dconf dumps
process_dconf() {
local path="$1"
local output_file="$2"
local temp_file temp_converted
temp_file=$(mktemp)
temp_converted=$(mktemp)
trap 'rm -f "$temp_file" "$temp_converted"' RETURN
echo -e "π Processing /$path/ -> $output_file\n"
# Special handling for shell settings
if [[ "$path" == "org/gnome/shell" ]]; then
dconf dump "/$path/" | grep -v "app-picker-layout" > "$temp_file"
else
dconf dump "/$path/" > "$temp_file"
fi
if [ -s "$temp_file" ]; then
if nix run nixpkgs#dconf2nix -- < "$temp_file" > "$temp_converted"; then
escaped_path=$(echo "$path" | sed 's/\//\\\//g')
sed -i "s/\"\" = {/\"$escaped_path\" = {/" "$temp_converted"
mv "$temp_converted" "$TARGET_DIR/$output_file"
echo -e "β
Generated $output_file at $(date)\n"
generated_files+=("$output_file")
else
echo -e "β Failed to convert $output_file at $(date)\n"
return 1
fi
else
echo -e "β οΈ No settings found for /$path/ at $(date)\n"
fi
}
# Process each dconf path
process_dconf "org/gnome/desktop/interface" "interface.nix"
process_dconf "org/gnome/desktop/input-sources" "input.nix"
process_dconf "org/gnome/desktop/wm" "wm.nix"
process_dconf "org/gnome/mutter" "mutter.nix"
process_dconf "org/gnome/shell" "shell.nix"
process_dconf "org/gnome/settings-daemon/plugins/power" "power.nix"
process_dconf "org/gnome/desktop/media-handling" "media.nix"
process_dconf "org/gnome/desktop/privacy" "privacy.nix"
process_dconf "org/gnome/desktop/wm/keybindings" "keybindings.nix"
process_dconf "org/gnome/settings-daemon/plugins/media-keys" "media-keys.nix"
process_dconf "org/gnome/shell/keybindings" "shell-keybindings.nix"
process_dconf "org/gnome/desktop/background" "background.nix"
# Generate default.nix only with successfully generated files
if [ ${#generated_files[@]} -gt 0 ]; then
{
echo '{ lib, ... }:'
echo ''
echo '{'
echo ' imports = ['
for file in "${generated_files[@]}"; do
echo " ./$file"
done
echo ' ];'
echo '}'
} > "$TARGET_DIR/default.nix"
echo -e "β
Successfully updated dconf settings in $TARGET_DIR/ at $(date)\n"
else
echo -e "β οΈ No dconf settings were generated at $(date)\n"
fi
# Update flake
up:
nix flake update
# Fetch submodules
sub-fetch:
git submodule update --init --recursive
# Commit all submodules using heredoc syntax and handle no changes
sub-sync:
#!/usr/bin/env bash
git submodule foreach --quiet 'git add . && \
if ! git diff --cached --quiet; then \
git commit -m "Auto commit by Justfile" && git push; \
fi'
git add git/*
if ! git diff --cached --quiet; then
git commit -m "Update submodules"
git push
fi