-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·145 lines (127 loc) · 3.84 KB
/
build.sh
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
#!/usr/bin/env bash
PWD=$(pwd)
FLAKE_PATH=$1
install_deps() {
nix-env -iA attic-client -f '<nixpkgs>' || exit 1
}
free_space() {
if [[ $INPUTS_LITTLE_SPACE == 'true' ]]; then
echo Deleting old paths...
rm -rf \
./result \
~/.cache/nix \
/homeless-shelter
nix store gc
nix store optimise
fi
}
login() {
if ! attic cache info $INPUTS_ATTIC_CACHE >> /dev/null ; then
echo Configuring attic client...
attic login local $INPUTS_ATTIC_URL $INPUTS_ATTIC_TOKEN || exit 1
fi
}
push() {
echo Pushing ...
attic push $INPUTS_ATTIC_CACHE ./result
}
build_packages() {
# Prepare VARS
PACKAGE_ARCHS=$(nix flake show --json 2> /dev/null | jq -r '.packages | keys[]' | tr '\n' ' ')
SUPPORTED_ARCHS_REGEX="^($(echo $system$(cat /etc/nix/nix.conf | grep extra-platforms | cut -d "=" -f 2) | tr " " "|"))$"
# Build Packages
if [[ "$PACKAGE_ARCHS" != "" ]]; then
for ARCH in $PACKAGE_ARCHS; do
if [[ "$ARCH" =~ $SUPPORTED_ARCHS_REGEX ]]; then
PACKAGES=$(nix flake show --json 2> /dev/null | jq -r '.packages["'"$ARCH"'"] | keys[]' | tr '\n' ' ')
if [[ "$PACKAGES" != "" ]]; then
for PACKAGE in $PACKAGES; do
echo Building $ARCH.$PACKAGE
if [[ ($INPUTS_DONT_FAIL == 'true') || ($INPUTS_DONT_FAIL == '') ]]; then
nix build --accept-flake-config .\#packages.$ARCH.$PACKAGE --max-jobs 2 --keep-going
else
nix build --accept-flake-config .\#packages.$ARCH.$PACKAGE --max-jobs 2
fi
if [ $? -eq 0 ]; then
echo $ARCH.$PACKAGE was build!
push
# Frees up space if $INPUTS_LITTLE_SPACE is true
free_space
else
echo $ARCH.$PACKAGE build failed!
exit 1
fi
echo
echo
done
else
echo No packages for arch $ARCH in flake found!
fi
else
echo $ARCH is not supported on your system!
fi
done
else
echo No packages in flake found!
fi
}
build_systems() {
# Prepare VARS
SYSTEMS=$(nix flake show --json 2> /dev/null | jq -r '.nixosConfigurations | keys[]' | tr '\n' ' ')
if [[ "$SYSTEMS" != "" ]]; then
# Build systems
for SYSTEM in $SYSTEMS; do
SYSTEM_ARCH=$(nix repl <<< ":lf ." <<< ":p nixosConfigurations.$SYSTEM.pkgs.system" 2> /dev/null)
if [[ "$SYSTEM_ARCH" =~ $SUPPORTED_ARCHS_REGEX ]]; then
echo Building $SYSTEM ...
if [[ ($INPUTS_DONT_FAIL == 'true') || ($INPUTS_DONT_FAIL == '') ]]; then
nix build --accept-flake-config .\#nixosConfigurations.$SYSTEM.config.system.build.toplevel --max-jobs 2 --keep-going
else
nix build --accept-flake-config .\#nixosConfigurations.$SYSTEM.config.system.build.toplevel --max-jobs 2
fi
if [ $? -eq 0 ]; then
echo $SYSTEM was build!
push
# Frees up space if $INPUTS_LITTLE_SPACE is true
free_space
else
echo $SYSTEM build failed!
exit 1
fi
echo
echo
else
echo $SYSTEM_ARCH is not supported on your system!
fi
done
else
echo No systems in flake found!
fi
}
main() {
if [ ! -d $FLAKE_PATH ]; then
echo $FLAKE_PATH is not a vaild path
echo Usage: $0 [Path to Directory with flake]
exit 1
fi
if [[ $INPUTS_NO_KEEP_ATTIC_CONF == true]]; then
rm -rf ~/.config/attic
fi
if [[ $INPUTS_INSTALL_DEPS == true ]]; then
install_deps
fi
login
if [[ "$FLAKE_PATH" != "" ]]; then
cd $FLAKE_PATH
fi
if [[ ($INPUTS_BUILD_SYSTEMS == 'true') || ($INPUTS_BUILD_SYSTEMS == '') ]]; then
build_systems
fi
if [[ $INPUTS_BUILD_PACKAGES == 'true' || ($INPUTS_BUILD_PACKAGES == '') ]]; then
build_packages
fi
if [[ "$FLAKE_PATH" != "" ]]; then
cd $PWD
fi
}
main