-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen-config.sh
More file actions
executable file
·56 lines (48 loc) · 1.17 KB
/
gen-config.sh
File metadata and controls
executable file
·56 lines (48 loc) · 1.17 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
#!/usr/bin/env bash
set -euo pipefail
script_dir=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
cd "${script_dir}"
# Generated mostly by chat gpt
# Create the "hosts" folder if it doesn't already exist
mkdir -p "$script_dir/hosts"
# Determine the current system (either "macOS" or "Linux")
if [[ "$OSTYPE" == "darwin"* ]]; then
base_file="../machine-types/osx.nix"
# Get the host CPU architecture
arch=$(uname -m)
if [[ "$arch" == "arm64" ]]; then
# arm Mac
system="aarch64-darwin"
else
# Intel-based Mac
system="x86_64-darwin"
fi
else
# Linux-based system
base_file="../machine-types/base.nix"
arch=$(uname -m)
if [[ "$arch" == "arm64" ]]; then
# ARM-based Linux
system="aarch64-linux"
else
# x86-based Linux
system="x86_64-linux"
fi
fi
# Write the home directory and username to a file in the "hosts" folder, using the current hostname as the file name
cat <<EOF >"$script_dir/hosts/$(hostname).nix"
{
config,
lib,
pkgs,
...
}:
{
imports = [ ${base_file} ];
home.packages = with pkgs; [
# machine-specific-nonsense
];
}
EOF
# Set up default symlink
ln -s "./hosts/$(hostname).nix" "$script_dir/localhost.nix"