Skip to content

Commit c5f2dfc

Browse files
authored
Merge pull request #67 from zimbatm/shellcheck
fix shellcheck warnings
2 parents 83742ac + cb765ad commit c5f2dfc

File tree

4 files changed

+49
-30
lines changed

4 files changed

+49
-30
lines changed

default.nix

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ let
1010
'';
1111
});
1212
in rec {
13+
toStorePath = target:
14+
# If a store path has been given, transform it to a string. And make sure
15+
# to capture the store path in its context.
16+
if lib.isStorePath target then
17+
let path = toString target; in
18+
builtins.appendContext path { "${path}" = { path = true; }; }
19+
# Otherwise, add to the store. This takes care of appending the store path
20+
# in the context automatically.
21+
else "${target}";
22+
1323
arx = { archive, startup}:
1424
stdenv.mkDerivation {
1525
name = "arx";
@@ -71,9 +81,13 @@ in rec {
7181
};
7282

7383
makeStartup = { target, nixUserChrootFlags, nix-user-chroot', run }:
84+
let
85+
# Avoid re-adding a store path into the store
86+
path = toStorePath target;
87+
in
7488
writeScript "startup" ''
7589
#!/bin/sh
76-
.${nix-user-chroot'}/bin/nix-user-chroot -n ./nix ${nixUserChrootFlags} -- ${target}${run} $@
90+
.${nix-user-chroot'}/bin/nix-user-chroot -n ./nix ${nixUserChrootFlags} -- ${path}${run} "$@"
7791
'';
7892

7993
nix-bootstrap = { target, extraTargets ? [], run, nix-user-chroot' ? nix-user-chroot, nixUserChrootFlags ? "" }:

nix-bootstrap.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
#!/bin/sh
22

3-
cmd=sh
4-
if ! [ $# -eq 0 ]; then
5-
cmd=$@
3+
if [ $# -gt 0 ]; then
4+
set -- sh
65
fi
76

87
# should download this in the future
98
# but the mirror is down
10-
proot=`dirname $0`/proot-`uname -p`
9+
proot=$(dirname "$0")/proot-$(uname -p)
1110
export PROOT_NO_SECCOMP=1
1211

1312
nixdir=$HOME/.nix
1413

1514
OLD_NIX_PATH=$NIX_PATH
16-
if [ -e $HOME/.nix-profile/etc/profile.d/nix.sh ]; then . $HOME/.nix-profile/etc/profile.d/nix.sh; fi
17-
if ! [ -z "$OLD_NIX_PATH" ]; then NIX_PATH="$OLD_NIX_PATH"; fi
15+
# shellcheck disable=SC1090
16+
if [ -e "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then . "$HOME/.nix-profile/etc/profile.d/nix.sh"; fi
17+
if [ -n "$OLD_NIX_PATH" ]; then NIX_PATH="$OLD_NIX_PATH"; fi
1818

1919
if [ -z "$IN_PROOT" ]; then
2020
export IN_PROOT=1
2121

22-
if ! [ -d $nixdir ]; then
23-
mkdir -p $nixdir
22+
if ! [ -d "$nixdir" ]; then
23+
mkdir -p "$nixdir"
2424
s=$(mktemp)
25-
curl https://nixos.org/nix/install -o $s
26-
$proot -b $nixdir:/nix $0 sh $s
25+
curl https://nixos.org/nix/install -o "$s"
26+
$proot -b "$nixdir:/nix" "$0" sh "$s"
2727
fi
2828

29-
$proot -b $nixdir:/nix $0 $cmd
29+
$proot -b "$nixdir:/nix" "$0" "$@"
3030

3131
export IN_PROOT=
3232
exit
33-
elif ! [ $# -eq 0 ]; then
34-
exec $cmd
33+
elif [ $# -gt 0 ]; then
34+
exec "$@"
3535
fi

nix-bundle.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Usage: $0 TARGET EXECUTABLE
88
Create a single-file bundle from the nixpkgs attribute "TARGET".
99
EXECUTABLE should be relative to the TARGET's output path.
1010
11+
The TARGET is either an attribute in nixpkgs, or an absolute path to the
12+
store.
13+
1114
For example:
1215
1316
$ $0 hello /bin/hello
@@ -19,7 +22,7 @@ EOF
1922
exit 1
2023
fi
2124

22-
nix_file=`dirname $0`/default.nix
25+
nix_file=$(dirname "$0")/default.nix
2326

2427
target="$1"
2528
shift
@@ -38,21 +41,23 @@ shift
3841
bootstrap=nix-bootstrap
3942
if [ "$target" = "nix-bundle" ] || [ "$target" = "nixStable" ] || [ "$target" = "nixUnstable" ] || [ "$target" = "nix" ]; then
4043
bootstrap=nix-bootstrap-nix
41-
elif ! [ -z "$extraTargets" ]; then
44+
elif [ -n "$extraTargets" ]; then
4245
bootstrap=nix-bootstrap-path
4346
fi
4447

4548
expr="with import <nixpkgs> {}; with import $nix_file {}; $bootstrap { target = $target; extraTargets = [ $extraTargets ]; run = \"$exec\"; }"
4649

47-
out=$(nix-store --no-gc-warning -r $(nix-instantiate --no-gc-warning -E "$expr"))
50+
drv=$(nix-instantiate --no-gc-warning -E "$expr")
51+
52+
out=$(nix-store --no-gc-warning --realize "$drv")
4853

4954
if [ -z "$out" ]; then
5055
>&2 echo "$0 failed. Exiting."
5156
exit 1
5257
elif [ -t 1 ]; then
53-
filename=$(basename $exec)
58+
filename=$(basename "$exec")
5459
echo "Nix bundle created at $filename."
55-
cp -f $out $filename
60+
cp -f "$out" "$filename"
5661
else
57-
cat $out
62+
cat "$out"
5863
fi

nix-run.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pkg="$1"
2222
shift
2323

2424
# A second argument will provide a hint to run
25-
if ! [ -z "$1" ]; then
25+
if [ -n "$1" ]; then
2626
name="$1"
2727
shift
2828
else
@@ -53,11 +53,11 @@ run_linux_desktop_app () {
5353
file="$1"
5454
shift
5555

56-
cmd=$(grep '^Exec' $file | tail -1 | \
56+
cmd=$(grep '^Exec' "$file" | tail -1 | \
5757
sed 's/Exec=//;s/^"//;s/" *$//')
5858

59-
if ! [ -z "$@" ]; then
60-
cmd=$(echo "$cmd" | sed "s/%[fu]/$1/;s/%[FU]/$@/")
59+
if [ "$#" -gt 0 ]; then
60+
cmd=$(echo "$cmd" | sed "s/%[fu]/$1/;s/%[FU]/$*/")
6161
fi
6262

6363
cmd=$(echo "$cmd" | sed "s/%k/$desktop/;s/%.//")
@@ -79,20 +79,20 @@ elif [ -x "$out/bin/run" ]; then
7979
run_bin "$out/bin/run" "$@"
8080
elif [ "$(uname)" = Darwin ] && [ -d "$out/Applications/$name.app" ]; then
8181
run_darwin_app "$out/Applications/$name.app" "$@"
82-
elif [ "$(uname)" = Darwin ] && [ -d $out/Applications/*.app ]; then
83-
for f in $out/Applications/*.app; do
82+
elif [ "$(uname)" = Darwin ] && [ -d "$out"/Applications/*.app ]; then
83+
for f in "$out"/Applications/*.app; do
8484
run_darwin_app "$f" "$@"
8585
done
8686
elif [ -f "$out/share/applications/$name.desktop" ]; then
87-
run_linux_desktop_app "$out/share/applications/$name.desktop" $@
88-
elif [ -d $out/share/applications ]; then
89-
for f in $out/share/applications/*.desktop; do
87+
run_linux_desktop_app "$out/share/applications/$name.desktop" "$@"
88+
elif [ -d "$out"/share/applications ]; then
89+
for f in "$out"/share/applications/*.desktop; do
9090
run_linux_desktop_app "$f"
9191
done
9292
elif [ -x "$out/bin/$name" ]; then
9393
run_bin "$out/bin/$name" "$@"
9494
elif [ -d "$out/bin" ]; then
95-
for bin in $out/bin/*; do
95+
for bin in "$out"/bin/*; do
9696
run_bin "$bin" "$@"
9797
done
9898
else

0 commit comments

Comments
 (0)