nix-bundle/default.nix

105 lines
2.9 KiB
Nix
Raw Normal View History

{nixpkgs ? import <nixpkgs> {}}:
with nixpkgs;
let
arx' = haskellPackages.arx.overrideAttrs (o: {
patchPhase = (o.patchPhase or "") + ''
substituteInPlace model-scripts/tmpx.sh \
2018-04-25 22:29:51 +03:00
--replace /tmp/ \$HOME/.cache/
'';
});
in rec {
arx = { archive, startup}:
stdenv.mkDerivation {
name = "arx";
buildCommand = ''
${arx'}/bin/arx tmpx --shared -rm! ${archive} -o $out // ${startup}
chmod +x $out
'';
};
maketar = { targets }:
stdenv.mkDerivation {
name = "maketar";
2017-04-30 09:48:41 +03:00
buildInputs = [ perl ];
exportReferencesGraph = map (x: [("closure-" + baseNameOf x) x]) targets;
buildCommand = ''
2017-04-27 07:03:01 +03:00
storePaths=$(perl ${pathsFromGraph} ./closure-*)
2017-04-30 10:09:34 +03:00
tar -cf - \
--owner=0 --group=0 --mode=u+rw,uga+r \
--hard-dereference \
2017-04-30 10:09:34 +03:00
$storePaths | bzip2 -z > $out
'';
};
2017-04-27 07:03:01 +03:00
# TODO: eventually should this go in nixpkgs?
2017-04-30 03:53:32 +03:00
nix-user-chroot = stdenv.lib.makeOverridable stdenv.mkDerivation {
2017-11-09 05:46:55 +03:00
name = "nix-user-chroot-2c52b5f";
src = ./nix-user-chroot;
makeFlags = [];
2017-04-30 03:53:32 +03:00
# hack to use when /nix/store is not available
postFixup = ''
exe=$out/bin/nix-user-chroot
patchelf \
--set-interpreter .$(patchelf --print-interpreter $exe) \
--set-rpath $(patchelf --print-rpath $exe | sed 's|/nix/store/|./nix/store/|g') \
$exe
'';
2017-02-07 01:17:20 +03:00
installPhase = ''
2017-04-30 03:53:32 +03:00
runHook preInstall
mkdir -p $out/bin/
cp nix-user-chroot $out/bin/nix-user-chroot
2017-04-30 03:53:32 +03:00
runHook postInstall
'';
meta.platforms = lib.platforms.linux;
2017-02-07 01:17:20 +03:00
};
makebootstrap = { targets, startup }:
arx {
inherit startup;
archive = maketar {
inherit targets;
};
};
makeStartup = { target, nixUserChrootFlags, nix-user-chroot', run }:
writeScript "startup" ''
#!/bin/sh
.${nix-user-chroot'}/bin/nix-user-chroot -n ./nix ${nixUserChrootFlags} -- ${target}${run} "$@"
'';
nix-bootstrap = { target, extraTargets ? [], run, nix-user-chroot' ? nix-user-chroot, nixUserChrootFlags ? "" }:
let
script = makeStartup { inherit target nixUserChrootFlags nix-user-chroot' run; };
in makebootstrap {
2018-04-04 23:04:37 +03:00
startup = ".${script} '\"$@\"'";
targets = [ "${script}" ] ++ extraTargets;
2017-04-30 03:53:32 +03:00
};
nix-bootstrap-nix = {target, run, extraTargets ? []}:
nix-bootstrap-path {
inherit target run;
extraTargets = [ gnutar bzip2 xz gzip coreutils bash ];
};
2017-04-30 03:53:32 +03:00
# special case adding path to the environment before launch
nix-bootstrap-path = let
nix-user-chroot'' = targets: nix-user-chroot.overrideDerivation (o: {
buildInputs = o.buildInputs ++ targets;
makeFlags = o.makeFlags ++ [
2017-04-30 03:53:32 +03:00
''ENV_PATH="${stdenv.lib.makeBinPath targets}"''
];
}); in { target, extraTargets ? [], run }: nix-bootstrap {
2017-04-30 03:53:32 +03:00
inherit target extraTargets run;
nix-user-chroot' = nix-user-chroot'' extraTargets;
};
}