mirror of
https://github.com/ilyakooo0/nix-bundle.git
synced 2024-09-11 06:55:53 +03:00
commit
c5f2dfc736
16
default.nix
16
default.nix
@ -10,6 +10,16 @@ let
|
|||||||
'';
|
'';
|
||||||
});
|
});
|
||||||
in rec {
|
in rec {
|
||||||
|
toStorePath = target:
|
||||||
|
# If a store path has been given, transform it to a string. And make sure
|
||||||
|
# to capture the store path in its context.
|
||||||
|
if lib.isStorePath target then
|
||||||
|
let path = toString target; in
|
||||||
|
builtins.appendContext path { "${path}" = { path = true; }; }
|
||||||
|
# Otherwise, add to the store. This takes care of appending the store path
|
||||||
|
# in the context automatically.
|
||||||
|
else "${target}";
|
||||||
|
|
||||||
arx = { archive, startup}:
|
arx = { archive, startup}:
|
||||||
stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
name = "arx";
|
name = "arx";
|
||||||
@ -71,9 +81,13 @@ in rec {
|
|||||||
};
|
};
|
||||||
|
|
||||||
makeStartup = { target, nixUserChrootFlags, nix-user-chroot', run }:
|
makeStartup = { target, nixUserChrootFlags, nix-user-chroot', run }:
|
||||||
|
let
|
||||||
|
# Avoid re-adding a store path into the store
|
||||||
|
path = toStorePath target;
|
||||||
|
in
|
||||||
writeScript "startup" ''
|
writeScript "startup" ''
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
.${nix-user-chroot'}/bin/nix-user-chroot -n ./nix ${nixUserChrootFlags} -- ${target}${run} $@
|
.${nix-user-chroot'}/bin/nix-user-chroot -n ./nix ${nixUserChrootFlags} -- ${path}${run} "$@"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
nix-bootstrap = { target, extraTargets ? [], run, nix-user-chroot' ? nix-user-chroot, nixUserChrootFlags ? "" }:
|
nix-bootstrap = { target, extraTargets ? [], run, nix-user-chroot' ? nix-user-chroot, nixUserChrootFlags ? "" }:
|
||||||
|
@ -1,35 +1,35 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
cmd=sh
|
if [ $# -gt 0 ]; then
|
||||||
if ! [ $# -eq 0 ]; then
|
set -- sh
|
||||||
cmd=$@
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# should download this in the future
|
# should download this in the future
|
||||||
# but the mirror is down
|
# but the mirror is down
|
||||||
proot=`dirname $0`/proot-`uname -p`
|
proot=$(dirname "$0")/proot-$(uname -p)
|
||||||
export PROOT_NO_SECCOMP=1
|
export PROOT_NO_SECCOMP=1
|
||||||
|
|
||||||
nixdir=$HOME/.nix
|
nixdir=$HOME/.nix
|
||||||
|
|
||||||
OLD_NIX_PATH=$NIX_PATH
|
OLD_NIX_PATH=$NIX_PATH
|
||||||
if [ -e $HOME/.nix-profile/etc/profile.d/nix.sh ]; then . $HOME/.nix-profile/etc/profile.d/nix.sh; fi
|
# shellcheck disable=SC1090
|
||||||
if ! [ -z "$OLD_NIX_PATH" ]; then NIX_PATH="$OLD_NIX_PATH"; fi
|
if [ -e "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then . "$HOME/.nix-profile/etc/profile.d/nix.sh"; fi
|
||||||
|
if [ -n "$OLD_NIX_PATH" ]; then NIX_PATH="$OLD_NIX_PATH"; fi
|
||||||
|
|
||||||
if [ -z "$IN_PROOT" ]; then
|
if [ -z "$IN_PROOT" ]; then
|
||||||
export IN_PROOT=1
|
export IN_PROOT=1
|
||||||
|
|
||||||
if ! [ -d $nixdir ]; then
|
if ! [ -d "$nixdir" ]; then
|
||||||
mkdir -p $nixdir
|
mkdir -p "$nixdir"
|
||||||
s=$(mktemp)
|
s=$(mktemp)
|
||||||
curl https://nixos.org/nix/install -o $s
|
curl https://nixos.org/nix/install -o "$s"
|
||||||
$proot -b $nixdir:/nix $0 sh $s
|
$proot -b "$nixdir:/nix" "$0" sh "$s"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$proot -b $nixdir:/nix $0 $cmd
|
$proot -b "$nixdir:/nix" "$0" "$@"
|
||||||
|
|
||||||
export IN_PROOT=
|
export IN_PROOT=
|
||||||
exit
|
exit
|
||||||
elif ! [ $# -eq 0 ]; then
|
elif [ $# -gt 0 ]; then
|
||||||
exec $cmd
|
exec "$@"
|
||||||
fi
|
fi
|
||||||
|
@ -8,6 +8,9 @@ Usage: $0 TARGET EXECUTABLE
|
|||||||
Create a single-file bundle from the nixpkgs attribute "TARGET".
|
Create a single-file bundle from the nixpkgs attribute "TARGET".
|
||||||
EXECUTABLE should be relative to the TARGET's output path.
|
EXECUTABLE should be relative to the TARGET's output path.
|
||||||
|
|
||||||
|
The TARGET is either an attribute in nixpkgs, or an absolute path to the
|
||||||
|
store.
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
$ $0 hello /bin/hello
|
$ $0 hello /bin/hello
|
||||||
@ -19,7 +22,7 @@ EOF
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
nix_file=`dirname $0`/default.nix
|
nix_file=$(dirname "$0")/default.nix
|
||||||
|
|
||||||
target="$1"
|
target="$1"
|
||||||
shift
|
shift
|
||||||
@ -38,21 +41,23 @@ shift
|
|||||||
bootstrap=nix-bootstrap
|
bootstrap=nix-bootstrap
|
||||||
if [ "$target" = "nix-bundle" ] || [ "$target" = "nixStable" ] || [ "$target" = "nixUnstable" ] || [ "$target" = "nix" ]; then
|
if [ "$target" = "nix-bundle" ] || [ "$target" = "nixStable" ] || [ "$target" = "nixUnstable" ] || [ "$target" = "nix" ]; then
|
||||||
bootstrap=nix-bootstrap-nix
|
bootstrap=nix-bootstrap-nix
|
||||||
elif ! [ -z "$extraTargets" ]; then
|
elif [ -n "$extraTargets" ]; then
|
||||||
bootstrap=nix-bootstrap-path
|
bootstrap=nix-bootstrap-path
|
||||||
fi
|
fi
|
||||||
|
|
||||||
expr="with import <nixpkgs> {}; with import $nix_file {}; $bootstrap { target = $target; extraTargets = [ $extraTargets ]; run = \"$exec\"; }"
|
expr="with import <nixpkgs> {}; with import $nix_file {}; $bootstrap { target = $target; extraTargets = [ $extraTargets ]; run = \"$exec\"; }"
|
||||||
|
|
||||||
out=$(nix-store --no-gc-warning -r $(nix-instantiate --no-gc-warning -E "$expr"))
|
drv=$(nix-instantiate --no-gc-warning -E "$expr")
|
||||||
|
|
||||||
|
out=$(nix-store --no-gc-warning --realize "$drv")
|
||||||
|
|
||||||
if [ -z "$out" ]; then
|
if [ -z "$out" ]; then
|
||||||
>&2 echo "$0 failed. Exiting."
|
>&2 echo "$0 failed. Exiting."
|
||||||
exit 1
|
exit 1
|
||||||
elif [ -t 1 ]; then
|
elif [ -t 1 ]; then
|
||||||
filename=$(basename $exec)
|
filename=$(basename "$exec")
|
||||||
echo "Nix bundle created at $filename."
|
echo "Nix bundle created at $filename."
|
||||||
cp -f $out $filename
|
cp -f "$out" "$filename"
|
||||||
else
|
else
|
||||||
cat $out
|
cat "$out"
|
||||||
fi
|
fi
|
||||||
|
20
nix-run.sh
20
nix-run.sh
@ -22,7 +22,7 @@ pkg="$1"
|
|||||||
shift
|
shift
|
||||||
|
|
||||||
# A second argument will provide a hint to run
|
# A second argument will provide a hint to run
|
||||||
if ! [ -z "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
name="$1"
|
name="$1"
|
||||||
shift
|
shift
|
||||||
else
|
else
|
||||||
@ -53,11 +53,11 @@ run_linux_desktop_app () {
|
|||||||
file="$1"
|
file="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
cmd=$(grep '^Exec' $file | tail -1 | \
|
cmd=$(grep '^Exec' "$file" | tail -1 | \
|
||||||
sed 's/Exec=//;s/^"//;s/" *$//')
|
sed 's/Exec=//;s/^"//;s/" *$//')
|
||||||
|
|
||||||
if ! [ -z "$@" ]; then
|
if [ "$#" -gt 0 ]; then
|
||||||
cmd=$(echo "$cmd" | sed "s/%[fu]/$1/;s/%[FU]/$@/")
|
cmd=$(echo "$cmd" | sed "s/%[fu]/$1/;s/%[FU]/$*/")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cmd=$(echo "$cmd" | sed "s/%k/$desktop/;s/%.//")
|
cmd=$(echo "$cmd" | sed "s/%k/$desktop/;s/%.//")
|
||||||
@ -79,20 +79,20 @@ elif [ -x "$out/bin/run" ]; then
|
|||||||
run_bin "$out/bin/run" "$@"
|
run_bin "$out/bin/run" "$@"
|
||||||
elif [ "$(uname)" = Darwin ] && [ -d "$out/Applications/$name.app" ]; then
|
elif [ "$(uname)" = Darwin ] && [ -d "$out/Applications/$name.app" ]; then
|
||||||
run_darwin_app "$out/Applications/$name.app" "$@"
|
run_darwin_app "$out/Applications/$name.app" "$@"
|
||||||
elif [ "$(uname)" = Darwin ] && [ -d $out/Applications/*.app ]; then
|
elif [ "$(uname)" = Darwin ] && [ -d "$out"/Applications/*.app ]; then
|
||||||
for f in $out/Applications/*.app; do
|
for f in "$out"/Applications/*.app; do
|
||||||
run_darwin_app "$f" "$@"
|
run_darwin_app "$f" "$@"
|
||||||
done
|
done
|
||||||
elif [ -f "$out/share/applications/$name.desktop" ]; then
|
elif [ -f "$out/share/applications/$name.desktop" ]; then
|
||||||
run_linux_desktop_app "$out/share/applications/$name.desktop" $@
|
run_linux_desktop_app "$out/share/applications/$name.desktop" "$@"
|
||||||
elif [ -d $out/share/applications ]; then
|
elif [ -d "$out"/share/applications ]; then
|
||||||
for f in $out/share/applications/*.desktop; do
|
for f in "$out"/share/applications/*.desktop; do
|
||||||
run_linux_desktop_app "$f"
|
run_linux_desktop_app "$f"
|
||||||
done
|
done
|
||||||
elif [ -x "$out/bin/$name" ]; then
|
elif [ -x "$out/bin/$name" ]; then
|
||||||
run_bin "$out/bin/$name" "$@"
|
run_bin "$out/bin/$name" "$@"
|
||||||
elif [ -d "$out/bin" ]; then
|
elif [ -d "$out/bin" ]; then
|
||||||
for bin in $out/bin/*; do
|
for bin in "$out"/bin/*; do
|
||||||
run_bin "$bin" "$@"
|
run_bin "$bin" "$@"
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user