Skip to content

Commit 9b0ef2e

Browse files
shfmt: enable shfmt to align all the shell scripts
Signed-off-by: Brian McGillion <[email protected]>
1 parent e4cf26f commit 9b0ef2e

File tree

16 files changed

+367
-345
lines changed

16 files changed

+367
-345
lines changed

docs/src/content/docs/ghaf/dev/ref/modules.mdx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,20 +283,18 @@ See [Memory Wipe on Boot and Free](/ghaf/dev/ref/memory-wipe) for detailed docum
283283
```nix
284284
{ config, lib, pkgs, ... }:
285285
286-
with lib;
287-
288286
{
289287
options.ghaf.moduleName = {
290-
enable = mkEnableOption "module description";
288+
enable = lib.mkEnableOption "module description";
291289
292-
setting = mkOption {
293-
type = types.str;
290+
setting = lib.mkOption {
291+
type = lib.types.str;
294292
default = "default-value";
295293
description = "Setting description with examples";
296294
};
297295
};
298296
299-
config = mkIf config.ghaf.moduleName.enable {
297+
config = lib.mkIf config.ghaf.moduleName.enable {
300298
# Implementation
301299
};
302300
}

docs/src/content/docs/ghaf/dev/ref/packages.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ stdenv.mkDerivation rec {
160160
161161
src = ./src;
162162
163-
meta = with lib; {
163+
meta = {
164164
description = "Brief description of package purpose";
165165
longDescription = ''
166166
Detailed description including:
@@ -170,9 +170,9 @@ stdenv.mkDerivation rec {
170170
- Security considerations
171171
'';
172172
homepage = "https://ghaf.tii.ae/ghaf/dev/ref/packages";
173-
license = licenses.asl20;
174-
maintainers = with maintainers; [ /* maintainer list */ ];
175-
platforms = platforms.linux;
173+
license = lib.licenses.asl20;
174+
maintainers = with lib.maintainers; [ /* maintainer list */ ];
175+
platforms = lib.platforms.linux;
176176
};
177177
}
178178
```

lib/icons.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
name: srcPath: size:
4141
let
4242
out =
43-
pkgs.runCommand "${name}-${size}" { nativeBuildInputs = with pkgs; [ buildPackages.imagemagick ]; }
43+
pkgs.runCommand "${name}-${size}" { nativeBuildInputs = [ pkgs.buildPackages.imagemagick ]; }
4444
''
4545
mkdir -p $out
4646
convert \
@@ -91,7 +91,7 @@
9191
sizes = builtins.split "x" size;
9292
width = builtins.head sizes;
9393
height = builtins.elemAt sizes 2;
94-
out = pkgs.runCommand "${name}-${size}" { nativeBuildInputs = with pkgs; [ librsvg ]; } ''
94+
out = pkgs.runCommand "${name}-${size}" { nativeBuildInputs = [ pkgs.librsvg ]; } ''
9595
mkdir -p $out
9696
rsvg-convert ${srcPath} -o $out/${name}.png \
9797
--width=${width} --height=${height} --keep-aspect-ratio

modules/common/firewall/attack-mitigation.nix

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
# SPDX-FileCopyrightText: 2022-2026 TII (SSRC) and the Ghaf contributors
22
# SPDX-License-Identifier: Apache-2.0
33
{ config, lib, ... }:
4-
5-
with lib;
6-
74
let
85
cfg = config.ghaf.firewall.attack-mitigation;
6+
7+
inherit (lib)
8+
mkOption
9+
mkEnableOption
10+
mkAfter
11+
mkForce
12+
mkIf
13+
types
14+
;
15+
916
floodType = types.submodule {
1017
options = {
1118
burstNum = mkOption {
@@ -88,7 +95,7 @@ in
8895
# ssh syn flood protection
8996
ghaf.firewall.tcpBlacklistRules = mkIf cfg.ssh.enable [
9097
{
91-
port = head config.services.openssh.ports;
98+
port = builtins.head config.services.openssh.ports;
9299
trackingSize = 100;
93100
inherit (cfg.ssh.rule) burstNum;
94101
inherit (cfg.ssh.rule) maxPacketFreq;

modules/microvm/common/ghaf-audio.nix

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@
88
}:
99
let
1010
cfg = config.ghaf.ghaf-audio;
11+
12+
inherit (lib)
13+
mkIf
14+
mkEnableOption
15+
mkOption
16+
types
17+
;
18+
1119
audiovmHost = "audio-vm";
1220
audiovmPort = config.ghaf.services.audio.pulseaudioTcpPort;
1321
address = "tcp:${audiovmHost}:${toString audiovmPort}";
1422
reconnectMs = 1000;
1523
in
1624
{
17-
options.ghaf.ghaf-audio = with lib; {
25+
options.ghaf.ghaf-audio = {
1826
enable = mkEnableOption "Ghaf audio support for application virtual machine.";
1927

2028
name = mkOption {
@@ -27,22 +35,22 @@ in
2735
useTunneling = mkEnableOption "Enable local pulseaudio with tunneling";
2836
};
2937

30-
config = lib.mkIf cfg.enable {
38+
config = mkIf cfg.enable {
3139
security.rtkit.enable = cfg.useTunneling;
32-
ghaf.users.appUser.extraGroups = lib.mkIf cfg.useTunneling [
40+
ghaf.users.appUser.extraGroups = mkIf cfg.useTunneling [
3341
"audio"
3442
"video"
3543
];
3644

37-
hardware.pulseaudio = lib.mkIf cfg.useTunneling {
45+
hardware.pulseaudio = mkIf cfg.useTunneling {
3846
enable = true;
3947
extraConfig = ''
4048
load-module module-tunnel-sink sink_name=${cfg.name}.speaker server=${address} reconnect_interval_ms=${toString reconnectMs}
4149
load-module module-tunnel-source source_name=${cfg.name}.mic server=${address} reconnect_interval_ms=${toString reconnectMs}
4250
'';
4351
};
4452

45-
environment = lib.mkIf (!cfg.useTunneling) {
53+
environment = mkIf (!cfg.useTunneling) {
4654
systemPackages = [ pkgs.pulseaudio ];
4755
sessionVariables = {
4856
PULSE_SERVER = "${address}";

modules/reference/services/globalprotect-vpn/default.nix

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77
...
88
}:
99

10-
with lib;
11-
1210
let
1311
cfg = config.ghaf.reference.services.globalprotect;
1412

13+
inherit (lib)
14+
literalExpression
15+
mkIf
16+
mkEnableOption
17+
mkOption
18+
types
19+
;
20+
1521
execStart =
1622
if cfg.csdWrapper == null then
1723
"${pkgs.globalprotect-openconnect}/bin/gpservice"

nix/treefmt.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
# Bash
3737
shellcheck.enable = true; # lints shell scripts https://github.com/koalaman/shellcheck
38+
shfmt.enable = true; # bash formatter https://github.com/mvdan/sh
39+
actionlint.enable = true; # github actions linter
3840

3941
# TODO: treefmt claims it changes the files
4042
# though the files are not in the diff

packages/chrome-extensions/default.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ let
9292
inherit id;
9393
};
9494

95-
meta = with lib; {
95+
meta = {
9696
description = "Chrome extension ${id}";
97-
platforms = platforms.all;
97+
platforms = lib.platforms.all;
9898
};
9999
};
100100
in

packages/chrome-extensions/open-normal/src/open_normal.sh

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ CFGF="/etc/open-normal-extension.cfg"
1313
# Send browser extension API message. First send four bytes of the length of
1414
# the payload and then the actual payload.
1515
function Msg {
16-
local len b1 b2 b3 b4
16+
local len b1 b2 b3 b4
1717

18-
len="${#1}"
19-
b1="$(( len & 255 ))"
20-
b2="$(( (len >> 8) & 255 ))"
21-
b3="$(( (len >> 16) & 255 ))"
22-
b4="$(( (len >> 24) & 255 ))"
23-
printf "%b" "$(printf "\\\\x%02x\\\\x%02x\\\\x%02x\\\\x%02x" "$b1" "$b2" "$b3" "$b4")"
24-
printf "%s" "$1"
18+
len="${#1}"
19+
b1="$((len & 255))"
20+
b2="$(((len >> 8) & 255))"
21+
b3="$(((len >> 16) & 255))"
22+
b4="$(((len >> 24) & 255))"
23+
printf "%b" "$(printf '\\x%02x\\x%02x\\x%02x\\x%02x' "$b1" "$b2" "$b3" "$b4")"
24+
printf "%s" "$1"
2525
}
2626

2727
# Read the four bytes of length in the received API message
@@ -32,39 +32,39 @@ LEN="$(od -t u4 -A n -N 4 --endian=little)"
3232
# So 8k should be plenty for the time being
3333
# If length is negative or zero or larger than 8k, then message is invalid
3434
if [ -z "$LEN" ] || [ "$LEN" -le 0 ] || [ "$LEN" -gt 8192 ]; then
35-
Msg "{\"status\":\"Failed to read parameters from API\"}"
36-
exit 100
35+
Msg '{"status":"Failed to read parameters from API"}'
36+
exit 100
3737
fi
3838

3939
# Read the json payload
4040
LANG=C IFS= read -r -d '' -n "$LEN" JSON
4141
# Remove json prefix
42-
PFX="{\"URL\":\""
42+
PFX='{"URL":"'
4343
URL="${JSON##"$PFX"}"
4444
# Remove json suffix
45-
SFX="\"}"
45+
SFX='"}'
4646
URL="${URL%%"$SFX"}"
4747

4848
# Check that config file is readable
4949
if [ -r "$CFGF" ]; then
50-
# Do not complain about not being able to follow non-constant source
51-
# shellcheck disable=SC1090
52-
. "$CFGF"
53-
# Sanity check settings
54-
if [ -z "$GIVC_PATH" ] || [ -z "$GIVC_OPTS" ] || [ ! -x "${GIVC_PATH}/bin/givc-cli" ]; then
55-
Msg "{\"status\":\"Invalid config in ${CFGF}\"}"
56-
exit 102
57-
else
58-
# Do not complain about double quotes, $GIVC_OPTS is purposefully unquoted here
59-
# shellcheck disable=SC2086
60-
"${GIVC_PATH}/bin/givc-cli" $GIVC_OPTS start app --vm chrome-vm google-chrome -- "${URL}" > /dev/null 2>&1
61-
RES=$?
62-
# Just return the exit value of givc-cli back to the browser
63-
Msg "{\"status\":\"${RES}\"}"
64-
exit "$RES"
65-
fi
50+
# Do not complain about not being able to follow non-constant source
51+
# shellcheck disable=SC1090
52+
. "$CFGF"
53+
# Sanity check settings
54+
if [ -z "$GIVC_PATH" ] || [ -z "$GIVC_OPTS" ] || [ ! -x "${GIVC_PATH}/bin/givc-cli" ]; then
55+
Msg "{\"status\":\"Invalid config in ${CFGF}\"}"
56+
exit 102
57+
else
58+
# Do not complain about double quotes, $GIVC_OPTS is purposefully unquoted here
59+
# shellcheck disable=SC2086
60+
"${GIVC_PATH}/bin/givc-cli" $GIVC_OPTS start app --vm chrome-vm google-chrome -- "${URL}" >/dev/null 2>&1
61+
RES=$?
62+
# Just return the exit value of givc-cli back to the browser
63+
Msg "{\"status\":\"${RES}\"}"
64+
exit "$RES"
65+
fi
6666
else
67-
# Report error to the browser, config was nonexistent or unreadable
68-
Msg "{\"status\":\"Failed to read ${CFGF}\"}"
69-
exit 101
67+
# Report error to the browser, config was nonexistent or unreadable
68+
Msg "{\"status\":\"Failed to read ${CFGF}\"}"
69+
exit 101
7070
fi

packages/pkgs-by-name/audit-rules/process-audit-rules.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ find "$INPUT_DIR" -maxdepth 1 -type f -name "*.rules" -print0 | while IFS= read
4747
s/$/"/
4848
}
4949
s/^[[:space:]]*//; s/[[:space:]]*$//
50-
' "$current_input_file" | grep -v '^[[:space:]]*$' > "$TMP_PROCESSED_CONTENT"
50+
' "$current_input_file" | grep -v '^[[:space:]]*$' >"$TMP_PROCESSED_CONTENT"
5151

5252
# Write the processed content to the output file
53-
(echo "["
54-
sed 's/^/ /' "$TMP_PROCESSED_CONTENT"
55-
echo "]") > "$output_filename"
53+
(
54+
echo "["
55+
sed 's/^/ /' "$TMP_PROCESSED_CONTENT"
56+
echo "]"
57+
) >"$output_filename"
5658

5759
# Cleanup
5860
rm "$TMP_PROCESSED_CONTENT"

0 commit comments

Comments
 (0)