mirror of
https://github.com/ilyakooo0/nix-bundle.git
synced 2024-08-16 10:20:28 +03:00
Add nix-bundle.sh.
This commit is contained in:
parent
6dc15dff24
commit
21b6115ddf
6
arx.nix
6
arx.nix
@ -1,9 +1,5 @@
|
||||
{ stdenv, arx }:
|
||||
|
||||
{ name
|
||||
, archive
|
||||
, startup
|
||||
}:
|
||||
{ name, archive, startup}:
|
||||
|
||||
stdenv.mkDerivation {
|
||||
inherit name;
|
||||
|
33
default.nix
33
default.nix
@ -2,7 +2,7 @@
|
||||
|
||||
with nixpkgs;
|
||||
|
||||
let
|
||||
rec {
|
||||
|
||||
arx = callPackage ./arx.nix {
|
||||
inherit (haskellPackages) arx;
|
||||
@ -22,35 +22,4 @@ let
|
||||
inherit nix-user-chroot makebootstrap;
|
||||
};
|
||||
|
||||
in {
|
||||
|
||||
hello = nix-bootstrap {
|
||||
name = "hello";
|
||||
target = hello;
|
||||
run = "/bin/hello";
|
||||
};
|
||||
|
||||
firefox = nix-bootstrap {
|
||||
name = "firefox";
|
||||
target = firefox;
|
||||
run = "/bin/firefox";
|
||||
};
|
||||
|
||||
nano = nix-bootstrap {
|
||||
name = "nano";
|
||||
target = nano;
|
||||
run = "/bin/nano";
|
||||
};
|
||||
|
||||
emacs = nix-bootstrap {
|
||||
name = "emacs";
|
||||
target = emacs;
|
||||
run = "/bin/emacs";
|
||||
};
|
||||
|
||||
nixInstaller = makebootstrap {
|
||||
name = "nix-installer.sh";
|
||||
targets = [ nix-installer ];
|
||||
startup = ".${nix-installer}/install";
|
||||
};
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{ arx, maketar }:
|
||||
|
||||
{ name, targets, startup }:
|
||||
|
||||
arx {
|
||||
inherit name startup;
|
||||
archive = maketar {
|
||||
|
18
maketar.nix
18
maketar.nix
@ -1,5 +1,4 @@
|
||||
{ stdenv, perl, pathsFromGraph }:
|
||||
|
||||
{ stdenv, gcc, perl, pathsFromGraph }:
|
||||
{ name, targets }:
|
||||
|
||||
stdenv.mkDerivation {
|
||||
@ -8,8 +7,21 @@
|
||||
nativeBuildInputs = [ perl ];
|
||||
buildCommand = ''
|
||||
storePaths=$(${perl}/bin/perl ${pathsFromGraph} ./closure-*)
|
||||
|
||||
# remove "unused" stdenv store paths
|
||||
# these need to be adjusted and made more intelligent
|
||||
# this should create a "runtime stdenv"
|
||||
storePaths=$(echo $storePaths | tr ' ' '\n' | \
|
||||
grep -Ev '/nix/store/[a-z0-9]+-linux-headers-[0-9.]+' | \
|
||||
grep -v ${stdenv.cc.libc.dev} | \
|
||||
grep -v ${stdenv.cc.libc.bin} | \
|
||||
grep -v ${stdenv.cc.cc} | \
|
||||
grep -v ${stdenv.cc.cc.lib} | \
|
||||
tr '\n' ' ')
|
||||
# grep -Ev '/nix/store/[a-z0-9]+-zlib-[0-9.]+' | \
|
||||
|
||||
# printRegistration=1 ${perl}/bin/perl ${pathsFromGraph} ./closure-* > .reginfo
|
||||
tar cvfj $out \
|
||||
tar cfj $out \
|
||||
--owner=0 --group=0 --mode=u+rw,uga+r \
|
||||
--hard-dereference \
|
||||
$storePaths
|
||||
|
@ -1,5 +1,4 @@
|
||||
{ stdenv, writeText, nix-user-chroot, makebootstrap }:
|
||||
|
||||
{ name, target, run }:
|
||||
|
||||
makebootstrap {
|
||||
|
29
nix-bundle.sh
Executable file
29
nix-bundle.sh
Executable file
@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
if [ "$#" -lt 2 ]; then
|
||||
cat <<EOF
|
||||
|
||||
Usage: $0 TARGET EXECUTABLE
|
||||
|
||||
Create a single-file bundle from the nixpkgs attribute "TARGET".
|
||||
EXECUTABLE should be relative to the TARGET's output path.
|
||||
|
||||
For example:
|
||||
|
||||
$ $0 hello /bin/hello
|
||||
$ ./hello
|
||||
Hello, world!
|
||||
|
||||
EOF
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
||||
target="$1"
|
||||
exec="$2"
|
||||
|
||||
expr="with import <nixpkgs> {}; with import ./. {}; nix-bootstrap { name = \"$target\"; target = $target; run = \"$exec\"; }"
|
||||
|
||||
out=$(nix-store -r $(nix-instantiate -E "$expr"))
|
||||
|
||||
cp -f $out $target
|
@ -1,3 +1,10 @@
|
||||
/*
|
||||
* This file is based on @lethalman's nix-user-chroot. This file has
|
||||
* diverged from it though.
|
||||
*
|
||||
* Usage: nix-user-chroot <nixpath> <command>
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <sched.h>
|
||||
#include <unistd.h>
|
||||
|
@ -1,12 +1,20 @@
|
||||
{ stdenv, fetchFromGitHub }:
|
||||
{ stdenv, fetchFromGitHub, patchelf }:
|
||||
|
||||
stdenv.mkDerivation {
|
||||
name = "nix-user-chroot";
|
||||
phases = [ "buildPhase" "installPhase" "fixupPhase" ];
|
||||
phases = [ "buildPhase" "fixupPhase" "installPhase" ];
|
||||
|
||||
buildPhase = ''
|
||||
cp ${./nix-user-chroot.c} nix-user-chroot.c
|
||||
$CC nix-user-chroot.c -o nix-user-chroot
|
||||
'';
|
||||
|
||||
# setup local libc interpreter
|
||||
fixupPhase = ''
|
||||
patchelf --set-interpreter .$(patchelf --print-interpreter nix-user-chroot) nix-user-chroot
|
||||
patchelf --set-rpath $(patchelf --print-rpath nix-user-chroot | sed 's|/nix/store/|./nix/store/|g') nix-user-chroot
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin/
|
||||
cp nix-user-chroot $out/bin/nix-user-chroot
|
||||
|
Loading…
Reference in New Issue
Block a user