Skip to content

Commit e2d1a94

Browse files
committed
treewide: add formatting via treefmt
1 parent 75c182a commit e2d1a94

File tree

6 files changed

+105
-74
lines changed

6 files changed

+105
-74
lines changed

bors.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ status = [
77
"package default [x86_64-linux]",
88
"check from-nixos-with-sudo [x86_64-linux]",
99
"package nixos-remote [x86_64-linux]",
10+
"check treefmt [x86_64-linux]",
11+
"package treefmt [x86_64-linux]",
1012
# github actions
1113
"deploy"
1214
]

flake.lock

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
disko = { url = "github:nix-community/disko/master"; inputs.nixpkgs.follows = "nixpkgs"; };
88
# used for testing
99
nixos-images.url = "github:nix-community/nixos-images";
10+
# used for development
11+
treefmt-nix.url = "github:numtide/treefmt-nix";
1012
};
1113

1214

@@ -17,6 +19,18 @@
1719
./src/flake-module.nix
1820
./tests/flake-module.nix
1921
./docs/flake-module.nix
22+
inputs.treefmt-nix.flakeModule
2023
];
24+
25+
perSystem = { config, ... }: {
26+
treefmt = {
27+
projectRootFile = "flake.nix";
28+
programs.nixpkgs-fmt.enable = true;
29+
programs.shellcheck.enable = true;
30+
programs.shfmt.enable = true;
31+
settings.formatter.shellcheck.options = [ "-s" "bash" ];
32+
};
33+
formatter = config.treefmt.build.wrapper;
34+
};
2135
};
2236
}

src/nixos-remote.sh

Lines changed: 67 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -42,63 +42,62 @@ declare -A disk_encryption_keys
4242

4343
while [[ $# -gt 0 ]]; do
4444
case "$1" in
45-
-f | --flake)
46-
flake=$2
47-
shift
48-
;;
49-
-L | --print-build-logs)
50-
print_build_logs=y
51-
;;
52-
-s | --store-paths)
53-
disko_script=$(readlink -f "$2")
54-
nixos_system=$(readlink -f "$3")
55-
shift
56-
shift
57-
;;
58-
--help)
45+
-f | --flake)
46+
flake=$2
47+
shift
48+
;;
49+
-L | --print-build-logs)
50+
print_build_logs=y
51+
;;
52+
-s | --store-paths)
53+
disko_script=$(readlink -f "$2")
54+
nixos_system=$(readlink -f "$3")
55+
shift
56+
shift
57+
;;
58+
--help)
59+
showUsage
60+
exit 0
61+
;;
62+
--kexec)
63+
kexec_url=$2
64+
shift
65+
;;
66+
--no-ssh-copy-id)
67+
no_ssh_copy=y
68+
;;
69+
--debug)
70+
enable_debug="-x"
71+
print_build_logs=y
72+
set -x
73+
;;
74+
--extra-files)
75+
extra_files=$2
76+
shift
77+
;;
78+
--disk-encryption-keys)
79+
disk_encryption_keys["$2"]="$3"
80+
shift
81+
shift
82+
;;
83+
--stop-after-disko)
84+
stop_after_disko=y
85+
;;
86+
--no-reboot)
87+
maybereboot=""
88+
;;
89+
*)
90+
if [[ -z ${ssh_connection:-} ]]; then
91+
ssh_connection="$1"
92+
else
5993
showUsage
60-
exit 0
61-
;;
62-
--kexec)
63-
kexec_url=$2
64-
shift
65-
;;
66-
--no-ssh-copy-id)
67-
no_ssh_copy=y
68-
;;
69-
--debug)
70-
enable_debug="-x"
71-
print_build_logs=y
72-
set -x
73-
;;
74-
--extra-files)
75-
extra_files=$2
76-
shift
77-
;;
78-
--disk-encryption-keys)
79-
disk_encryption_keys["$2"]="$3"
80-
shift
81-
shift
82-
;;
83-
--stop-after-disko)
84-
stop_after_disko=y
85-
;;
86-
--no-reboot)
87-
maybereboot=""
88-
;;
89-
*)
90-
if [[ -z ${ssh_connection:-} ]]; then
91-
ssh_connection="$1"
92-
else
93-
showUsage
94-
exit 1
95-
fi
96-
;;
94+
exit 1
95+
fi
96+
;;
9797
esac
9898
shift
9999
done
100100

101-
102101
# ssh wrapper
103102
timeout_ssh_() {
104103
timeout 10 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$ssh_connection" "$@"
@@ -134,20 +133,20 @@ if [[ -z ${ssh_connection:-} ]]; then
134133
fi
135134

136135
# parse flake nixos-install style syntax, get the system attr
137-
if [[ -n "${flake:-}" ]]; then
136+
if [[ -n ${flake:-} ]]; then
138137
if [[ $flake =~ ^(.*)\#([^\#\"]*)$ ]]; then
139-
flake="${BASH_REMATCH[1]}"
140-
flakeAttr="${BASH_REMATCH[2]}"
138+
flake="${BASH_REMATCH[1]}"
139+
flakeAttr="${BASH_REMATCH[2]}"
141140
fi
142-
if [[ -z "${flakeAttr:-}" ]]; then
141+
if [[ -z ${flakeAttr:-} ]]; then
143142
echo "Please specify the name of the NixOS configuration to be installed, as a URI fragment in the flake-uri."
144-
echo "For example, to use the output nixosConfigurations.foo from the flake.nix, append \"#foo\" to the flake-uri."
143+
echo 'For example, to use the output nixosConfigurations.foo from the flake.nix, append "#foo" to the flake-uri.'
145144
exit 1
146145
fi
147146
disko_script=$(nix_build "${flake}#nixosConfigurations.${flakeAttr}.config.system.build.disko")
148147
nixos_system=$(nix_build "${flake}#nixosConfigurations.${flakeAttr}.config.system.build.toplevel")
149-
elif [[ -n "${disko_script:-}" ]] && [[ -n "${nixos_system:-}" ]]; then
150-
if [[ ! -e "${disko_script}" ]] || [[ ! -e "${nixos_system}" ]]; then
148+
elif [[ -n ${disko_script:-} ]] && [[ -n ${nixos_system:-} ]]; then
149+
if [[ ! -e ${disko_script} ]] || [[ ! -e ${nixos_system} ]]; then
151150
echo "${disko_script} and ${nixos_system} must be existing store-paths"
152151
exit 1
153152
fi
@@ -160,7 +159,8 @@ fi
160159
# TODO we probably need an architecture detection here
161160
# TODO if we have specified a user here but we are already booted into the
162161
# installer, than the user might not work anymore
163-
until facts=$(ssh_ -o ConnectTimeout=10 -- <<SSH
162+
until facts=$(
163+
ssh_ -o ConnectTimeout=10 -- <<SSH
164164
set -efu ${enable_debug}
165165
has(){
166166
command -v tar >/dev/null && echo "y" || echo "n"
@@ -198,14 +198,14 @@ if [[ ${is_kexec-n} != "y" ]] && [[ ${no_ssh_copy-n} != "y" ]]; then
198198
fi
199199

200200
if [[ ${is_kexec-n} == "n" ]]; then
201-
ssh_ << SSH
201+
ssh_ <<SSH
202202
set -efu ${enable_debug}
203203
"${maybesudo}" rm -rf /root/kexec
204204
"${maybesudo}" mkdir -p /root/kexec
205205
SSH
206206

207-
if [[ -f "$kexec_url" ]]; then
208-
ssh_ "${maybesudo} tar -C /root/kexec -xvzf-" < "$kexec_url"
207+
if [[ -f $kexec_url ]]; then
208+
ssh_ "${maybesudo} tar -C /root/kexec -xvzf-" <"$kexec_url"
209209
elif [[ ${has_curl-n} == "y" ]]; then
210210
ssh_ "curl --fail -Ss -L '${kexec_url}' | ${maybesudo} tar -C /root/kexec -xvzf-"
211211
elif [[ ${has_wget-n} == "y" ]]; then
@@ -214,7 +214,7 @@ SSH
214214
curl --fail -Ss -L "${kexec_url}" | ssh_ "${maybesudo} tar -C /root/kexec -xvzf-"
215215
fi
216216

217-
ssh_ << SSH
217+
ssh_ <<SSH
218218
TMPDIR=/root/kexec setsid ${maybesudo} /root/kexec/kexec/run
219219
SSH
220220

@@ -227,10 +227,9 @@ SSH
227227
# watiting for machine to become available again
228228
until ssh_ -o ConnectTimeout=10 -- exit 0; do sleep 5; done
229229
fi
230-
for path in "${!disk_encryption_keys[@]}"
231-
do
230+
for path in "${!disk_encryption_keys[@]}"; do
232231
echo "Uploading ${disk_encryption_keys[$path]} to $path"
233-
ssh_ "umask 077; cat > $path" < "${disk_encryption_keys[$path]}"
232+
ssh_ "umask 077; cat > $path" <"${disk_encryption_keys[$path]}"
234233
done
235234

236235
nix_copy --to "ssh://$ssh_connection" "$disko_script"
@@ -242,7 +241,7 @@ fi
242241

243242
nix_copy --to "ssh://$ssh_connection?remote-store=local?root=/mnt" "$nixos_system"
244243
if [[ -n ${extra_files:-} ]]; then
245-
if [[ -d "$extra_files" ]]; then
244+
if [[ -d $extra_files ]]; then
246245
extra_files="$extra_files/"
247246
fi
248247
rsync -vrlF -e "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" "$extra_files" "${ssh_connection}:/mnt/"

tests/lib/test-base.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
test:
2-
{ pkgs ? import <nixpkgs> {}, ... } @ args:
2+
{ pkgs ? import <nixpkgs> { }, ... } @ args:
33
let
44
inherit (pkgs) lib;
5-
nixos-lib = import (pkgs.path + "/nixos/lib") {};
5+
nixos-lib = import (pkgs.path + "/nixos/lib") { };
66
in
77
(nixos-lib.runTest {
88
hostPkgs = pkgs;

tests/modules/system-to-install.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{modulesPath, self, ...}: {
1+
{ modulesPath, self, ... }: {
22
imports = [
33
(modulesPath + "/testing/test-instrumentation.nix")
44
(modulesPath + "/profiles/qemu-guest.nix")
@@ -9,7 +9,7 @@
99
hardware.enableAllFirmware = false;
1010
networking.hostId = "8425e349"; # from profiles/base.nix, needed for zfs
1111
boot.zfs.devNodes = "/dev/disk/by-uuid"; # needed because /dev/disk/by-id is empty in qemu-vms
12-
boot.loader.grub.devices = ["/dev/vda"];
12+
boot.loader.grub.devices = [ "/dev/vda" ];
1313
disko.devices = {
1414
disk = {
1515
vda = {
@@ -25,7 +25,7 @@
2525
start = "0";
2626
end = "1M";
2727
part-type = "primary";
28-
flags = ["bios_grub"];
28+
flags = [ "bios_grub" ];
2929
}
3030
{
3131
type = "partition";

0 commit comments

Comments
 (0)