Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit f534bac

Browse files
ghudginsgrahamc
authored andcommitted
make-targets: shellcheck
It was choking on more complicated machine expressions
1 parent 6e33f3b commit f534bac

File tree

3 files changed

+47
-23
lines changed

3 files changed

+47
-23
lines changed

make-targets.sh

+29-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env nix-shell
22
#!nix-shell -i bash ./shell.nix
3+
# shellcheck shell=bash
34

45
set -eux
56
set -o pipefail
@@ -48,15 +49,16 @@ sshwrap() (
4849
)
4950

5051
cfg_for_provisioner() (
51-
provisioner=$1
52-
ip=$2
52+
local provisioner=$1
53+
local name=$2
54+
local ip=$3
5355

5456
case "$provisioner" in
5557
"metal")
56-
cfg_for_metal "$ip"
58+
cfg_for_metal "$name" "$ip"
5759
;;
5860
"nixos-install")
59-
cfg_for_nixos_install "$ip"
61+
cfg_for_nixos_install "$name" "$ip"
6062
;;
6163
*)
6264
echo "Failed: no such provisioner: $provisioner"
@@ -66,16 +68,37 @@ cfg_for_provisioner() (
6668
)
6769

6870
cfg_for_metal() (
71+
local name=$1
72+
local ip=$2
6973
sshwrap "root@$ip" -- cat /etc/nixos/packet/system.nix > "$scratch/machines/${name}.system.nix"
7074
)
7175

7276
cfg_for_nixos_install() (
77+
local name=$1
78+
local ip=$2
79+
7380
mkdir -p "$scratch/machines/${name}"
7481
sshwrap "root@$ip" -- cat /etc/nixos/configuration.nix > "$scratch/machines/${name}/configuration.nix"
7582
sshwrap "root@$ip" -- cat /etc/nixos/hardware-configuration.nix > "$scratch/machines/${name}/hardware-configuration.nix"
7683
printf '{ imports = [ %s ]; }' "./${name}/configuration.nix" > "$scratch/machines/${name}.system.nix"
7784
)
7885

86+
import_machine() (
87+
local machine=$1
88+
89+
local name
90+
name="$(jq -r .key <<<"$machine")"
91+
local ip
92+
ip="$(jq -r .value.ip <<<"$machine")"
93+
local provisioner
94+
provisioner=$(jq -r .value.provisioner <<<"$machine")
95+
jq -r .value.expression <<<"$machine"
96+
jq -r .value.expression <<<"$machine" > "$scratch/machines/${name}.expr.nix"
97+
if cfg_for_provisioner "$provisioner" "$name" "$ip"; then
98+
networkentry "$name" "$ip" >> "$scratch/default.nix"
99+
fi
100+
)
101+
79102
cat <<EOF > "$scratch/default.nix"
80103
{
81104
network = {
@@ -96,17 +119,8 @@ cat <<EOF > "$scratch/default.nix"
96119
97120
EOF
98121

99-
machines | while read machine; do
100-
(
101-
name="$(jq -r .key <<<"$machine")"
102-
ip=$(jq -r .value.ip <<<"$machine")
103-
provisioner=$(jq -r .value.provisioner <<<"$machine")
104-
jq -r .value.expression <<<"$machine"
105-
jq -r .value.expression <<<"$machine" > "$scratch/machines/${name}.expr.nix"
106-
if cfg_for_provisioner "$provisioner" "$ip"; then
107-
networkentry "$name" "$ip" >> "$scratch/default.nix"
108-
fi
109-
) < /dev/null
122+
machines | while read -r machine; do
123+
import_machine "$machine" < /dev/null
110124
done
111125

112126
echo "}" >> "$scratch/default.nix"
+14-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
1-
{ }
1+
{
2+
roles.darwin-builder.enable = true;
3+
services.ofborg.macos_vm.version = "catalina";
4+
macosGuest = {
5+
guest = {
6+
sockets = 1;
7+
cores = 4;
8+
threads = 1;
9+
memoryInMegs = 13 * 1024;
10+
};
11+
network.externalInterface = "ens1";
12+
};
13+
}
14+

shell.nix

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
let
22
sources = import ./nix/sources.nix;
3-
overlay = _: pkgs: {
4-
};
3+
overlay = _: pkgs: { };
54

65
pkgs = import sources.nixpkgs {
76
overlays = [ overlay ];
8-
config = {
9-
allowUnfree = true;
10-
};
7+
config = { allowUnfree = true; };
118
};
12-
in
13-
pkgs.mkShell {
9+
in pkgs.mkShell {
1410
buildInputs = [
1511
pkgs.coreutils
1612
pkgs.jq
@@ -21,6 +17,7 @@ pkgs.mkShell {
2117
pkgs.bashInteractive
2218
pkgs.git
2319
pkgs.morph
20+
pkgs.shellcheck
2421
(pkgs.terraform_0_14.withPlugins (p: [
2522
(pkgs.buildGoModule rec {
2623
pname = "terraform-provider-cloudamqp";

0 commit comments

Comments
 (0)