-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
220 lines (182 loc) · 7.33 KB
/
Makefile
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
#
# NOTE: Makefile's target name should not be the same as one of the file or directory in the current directory,
# otherwise the target will not be executed!
#
# Define the output directory and filenames
RSA_KEY_FILE = ~/.ssh/ssh_host_rsa_key
ED25519_KEY_FILE = ~/.ssh/ssh_host_ed25519_key
AGE_DIR = ~/.config/sops/age
AGE_PUBLIC_KEY_FILE = $(AGE_DIR)/keys.txt
# Define the number of bits for RSA key
RSA_BITS = 4096
# Define the makefile targets and rules
.PHONY: keygen rsa_key ed25519_key age_key get_age_public_key
keygen: rsa_key ed25519_key age_key get_age_public_key
# Generate AGE pair
# nix-shell -p age --run 'age-keygen -o ~/.config/sops/age/key.txt'
# Note: age-keygen -y ~/.config/sops/age/key.txt gives you the public output
# nix-shell -p ssh-to-age --run 'cat ~/.ssh/ssh_host_ed25519_key.pub | ssh-to-age'
rsa_key:
@if [ ! -f $(RSA_KEY_FILE) ] || (read -p "RSA SSH key already exists. Do you want to overwrite it? [y/N] " answer; [ "$$answer" == "y" ]); then \
echo "Generating RSA SSH key..."; \
ssh-keygen -t rsa -b $(RSA_BITS) -f $(RSA_KEY_FILE) -N ""; \
else \
echo "Skipping RSA SSH key generation..."; \
fi
ed25519_key:
@if [ ! -f $(ED25519_KEY_FILE) ] || (read -p "Ed25519 SSH key already exists. Do you want to overwrite it? [y/N] " answer; [ "$$answer" == "y" ]); then \
echo "Generating Ed25519 SSH key..."; \
ssh-keygen -t ed25519 -f $(ED25519_KEY_FILE) -N ""; \
else \
echo "Skipping Ed25519 SSH key generation..."; \
fi
age_key: create_age_dir
@if [ ! -f $(AGE_PUBLIC_KEY_FILE) ] || (read -p "Age key pair already exists. Do you want to overwrite it? [y/N] " answer; [ "$$answer" == "y" ]); then \
echo "Generating Age key pair..."; \
nix --extra-experimental-features nix-command run --extra-experimental-features flakes nixpkgs#ssh-to-age -- -private-key -i $(ED25519_KEY_FILE) > $(AGE_PUBLIC_KEY_FILE); \
else \
echo "Skipping Age key pair generation..."; \
fi
create_age_dir:
@if [ ! -d $(AGE_DIR) ]; then \
echo "Creating Age key directory..."; \
mkdir -p $(AGE_DIR); \
fi
get_age_public_key:
@if [ -f $(AGE_PUBLIC_KEY_FILE) ]; then \
echo "Getting Age public key..."; \
nix --extra-experimental-features nix-command shell --extra-experimental-features flakes nixpkgs#age -c age-keygen -y $(AGE_PUBLIC_KEY_FILE); \
else \
echo "Age public key does not exist. Skipping..."; \
fi
ssh_to_age:
@if [ ! -f $(ED25519_KEY_FILE) ] || (read -p "Ed25519 SSH key exists. Do you want to create a AGE key? [y/N] " answer; [ "$$answer" == "y" ]); then \
echo "Generating AGE from Ed25519 SSH key..."; \
cat $(ED25519_KEY_FILE) | ; \
else \
echo "Skipping SSH-TO_AGE key conversion..."; \
fi
###########################################################################
#
# Make PGP
#
############################################################################
.PHONY: pgp
# Not working!!!
pgp:
@echo "Make PGP key..."
nix --extra-experimental-features nix-command shell --extra-experimental-features flakes nixpkgs#gpg --full-generate-key
###########################################################################
#
# Get sha256 hash of a VSIX package
#
############################################################################
.PHONY: get-vscode-sha
get-vscode-extension-sha:
@read -p "Enter Publisher: " PUBLISHER; \
read -p "Enter Extension Name: " EXTENSION; \
read -p "Enter Version: " VERSION; \
URL="https://ms-vscode.gallery.vsassets.io/_apis/public/gallery/publisher/$$PUBLISHER/extension/$$EXTENSION/$$VERSION/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage"; \
echo "Checking URL $$URL..."; \
HTTP_STATUS=$$(curl -o /dev/null -L --silent --write-out '%{http_code}\n' $$URL); \
if [ $$HTTP_STATUS -eq 200 ]; then \
echo "URL is valid. Calculating SHA256 for $$EXTENSION version $$VERSION from $$PUBLISHER..."; \
SHA256_HASH=$$(curl -sL $$URL | openssl dgst -sha256 -binary | openssl base64); \
echo "{"; \
echo " name = \"$$EXTENSION\";"; \
echo " publisher = \"$$PUBLISHER\";"; \
echo " version = \"$$VERSION\";"; \
echo " sha256 = \"sha256-$$SHA256_HASH\";"; \
echo "}"; \
else \
echo "Error: The URL is not valid or the file does not exist. HTTP Status: $$HTTP_STATUS"; \
fi
get-vscode-sha:
@read -p "Enter Platform (linux-x64, linux-arm64, darwin-arm64): " PLAT; \
read -p "Enter Version: " VERSION; \
URL="https://update.code.visualstudio.com/$$VERSION/$$PLAT/stable"; \
echo "Checking URL $$URL..."; \
HTTP_STATUS=$$(curl -o /dev/null -L --silent --write-out '%{http_code}\n' $$URL); \
if [ $$HTTP_STATUS -eq 200 ]; then \
echo "URL is valid. Calculating SHA256 for VSCode version $$VERSION on $$PLAT..."; \
SHA256_HASH=$$(curl -sL $$URL | sha256sum); \
echo "{"; \
echo " plat = \"$$PLAT\";"; \
echo " version = \"$$VERSION\";"; \
echo " sha256 = \"sha256-$$SHA256_HASH\";"; \
echo "}"; \
else \
echo "Error: The URL is not valid or the file does not exist. HTTP Status: $$HTTP_STATUS"; \
fi
###########################################################################
#
# Make Secrets
#
############################################################################
# Not working!!!!
.PHONY: secrets
secrets:
@echo "Enter the path where the encrypted secrets.yaml file will be saved: "
@read SECRETS_PATH; \
if [ "$${SECRETS_PATH:0:1}" != "/" ]; then \
SECRETS_PATH="$(CURDIR)/$$SECRETS_PATH"; \
fi; \
DIR_PATH=$$(dirname $$SECRETS_PATH); \
if [ ! -d "$$DIR_PATH" ]; then \
echo "The directory $$DIR_PATH does not exist. Do you want to create it? [y/N]:"; \
read CONFIRM; \
if [ "$$CONFIRM" != "y" ] && [ "$$CONFIRM" != "Y" ]; then \
echo "Exiting. Directory not created."; \
exit 1; \
fi; \
mkdir -p $$DIR_PATH; \
echo "Directory $$DIR_PATH created."; \
fi; \
echo "The encrypted secrets.yaml will be created at: $$SECRETS_PATH"; \
cd $$SECRETS_PATH
echo "Creating and encrypting secrets.yaml..."; \
nix --experimental-features 'nix-command flakes' run nixpkgs#sops secrets.yaml \
echo "Encrypted secrets.yaml created at: $$SECRETS_PATH"
############################################################################
#
# Nix commands related to the local machine
#
############################################################################
switch:
sudo nixos-rebuild switch --flake .#$(i) --show-trace --verbose
woody:
sudo nixos-rebuild switch --flake .#woody --show-trace --verbose
frametop-dryrun:
sudo nixos-rebuild dry-run --flake .#frametop
woody-dryrun:
sudo nixos-rebuild dry-run --flake .#woody
up:
nix flake update
# Update specific input
# usage: make upp i=wallpapers
upp:
nix flake lock --update-input $(i)
history:
nix profile history --profile /nix/var/nix/profiles/system
gc:
$(eval MACHINE_NAME := $(shell hostname))
@echo "Machine Name: $$MACHINE_NAME"
echo "Wiping profile history older than 7 days..."; \
sudo nix profile wipe-history --profile /nix/var/nix/profiles/system --older-than 7d; \
echo "Running garbage collection..."; \
sudo nix store gc; \
echo "Deleting old generations of garbage..."; \
sudo nix-collect-garbage --delete-older-than 7d; \
echo "Rebuilding NixOS for machine $$MACHINE_NAME..."; \
sudo nixos-rebuild boot --flake .#$$MACHINE_NAME
############################################################################
#
# Misc, other useful commands
#
############################################################################
fmt:
# format the nix files in this repo
nix fmt
.PHONY: clean
clean:
rm -rf result