2016-06-15 19:23:19 +03:00
|
|
|
{nixpkgs ? import <nixpkgs> {}}:
|
|
|
|
|
|
|
|
with nixpkgs;
|
|
|
|
|
2018-04-10 20:58:56 +03:00
|
|
|
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/
|
2018-04-10 20:58:56 +03:00
|
|
|
'';
|
|
|
|
});
|
|
|
|
in rec {
|
2020-11-09 19:11:52 +03:00
|
|
|
toStorePath = target:
|
2021-05-04 18:10:01 +03:00
|
|
|
# If a store path has been given but is not a derivation, add the missing context
|
2020-11-29 15:28:59 +03:00
|
|
|
# to it so it will be propagated properly as a build input.
|
2021-05-04 18:10:01 +03:00
|
|
|
if !(lib.isDerivation target) && lib.isStorePath target then
|
|
|
|
let path = toString target; in
|
|
|
|
builtins.appendContext path { "${path}" = { path = true; }; }
|
2020-11-09 19:11:52 +03:00
|
|
|
# Otherwise, add to the store. This takes care of appending the store path
|
|
|
|
# in the context automatically.
|
|
|
|
else "${target}";
|
|
|
|
|
2017-04-26 09:31:01 +03:00
|
|
|
arx = { archive, startup}:
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
name = "arx";
|
|
|
|
buildCommand = ''
|
2018-04-10 20:58:56 +03:00
|
|
|
${arx'}/bin/arx tmpx --shared -rm! ${archive} -o $out // ${startup}
|
2017-04-26 09:31:01 +03:00
|
|
|
chmod +x $out
|
|
|
|
'';
|
|
|
|
};
|
2016-06-15 19:23:19 +03:00
|
|
|
|
2017-04-26 09:31:01 +03:00
|
|
|
maketar = { targets }:
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
name = "maketar";
|
2017-04-30 09:48:41 +03:00
|
|
|
buildInputs = [ perl ];
|
2017-04-26 09:31:01 +03:00
|
|
|
exportReferencesGraph = map (x: [("closure-" + baseNameOf x) x]) targets;
|
|
|
|
buildCommand = ''
|
2017-04-27 07:03:01 +03:00
|
|
|
storePaths=$(perl ${pathsFromGraph} ./closure-*)
|
2016-06-15 19:23:19 +03:00
|
|
|
|
2017-04-30 10:09:34 +03:00
|
|
|
tar -cf - \
|
2017-04-26 09:31:01 +03:00
|
|
|
--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-26 09:31:01 +03:00
|
|
|
'';
|
|
|
|
};
|
2016-11-18 19:53:30 +03:00
|
|
|
|
2017-04-27 07:03:01 +03:00
|
|
|
# TODO: eventually should this go in nixpkgs?
|
2021-07-19 15:00:00 +03:00
|
|
|
nix-user-chroot = lib.makeOverridable stdenv.mkDerivation {
|
2017-11-09 05:46:55 +03:00
|
|
|
name = "nix-user-chroot-2c52b5f";
|
2018-02-20 04:45:03 +03:00
|
|
|
src = ./nix-user-chroot;
|
2016-06-15 19:23:19 +03:00
|
|
|
|
2018-04-05 00:19:32 +03:00
|
|
|
makeFlags = [];
|
|
|
|
|
2017-04-30 03:53:32 +03:00
|
|
|
# hack to use when /nix/store is not available
|
2017-04-26 09:31:01 +03:00
|
|
|
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
|
|
|
|
2017-04-26 09:31:01 +03:00
|
|
|
installPhase = ''
|
2017-04-30 03:53:32 +03:00
|
|
|
runHook preInstall
|
|
|
|
|
2017-04-26 09:31:01 +03:00
|
|
|
mkdir -p $out/bin/
|
|
|
|
cp nix-user-chroot $out/bin/nix-user-chroot
|
2017-04-30 03:53:32 +03:00
|
|
|
|
|
|
|
runHook postInstall
|
2017-04-26 09:31:01 +03:00
|
|
|
'';
|
2020-07-30 23:33:06 +03:00
|
|
|
|
|
|
|
meta.platforms = lib.platforms.linux;
|
2017-02-07 01:17:20 +03:00
|
|
|
};
|
|
|
|
|
2017-04-26 09:31:01 +03:00
|
|
|
makebootstrap = { targets, startup }:
|
|
|
|
arx {
|
|
|
|
inherit startup;
|
|
|
|
archive = maketar {
|
|
|
|
inherit targets;
|
|
|
|
};
|
|
|
|
};
|
2017-02-13 03:21:51 +03:00
|
|
|
|
2022-04-29 03:22:18 +03:00
|
|
|
makeStartup = { target, nixUserChrootFlags, nix-user-chroot', run, initScript }:
|
2020-11-09 19:11:52 +03:00
|
|
|
let
|
|
|
|
# Avoid re-adding a store path into the store
|
|
|
|
path = toStorePath target;
|
|
|
|
in
|
2018-02-20 04:45:03 +03:00
|
|
|
writeScript "startup" ''
|
2018-12-07 12:00:32 +03:00
|
|
|
#!/bin/sh
|
2022-04-29 03:22:18 +03:00
|
|
|
${initScript}
|
2020-11-09 19:11:52 +03:00
|
|
|
.${nix-user-chroot'}/bin/nix-user-chroot -n ./nix ${nixUserChrootFlags} -- ${path}${run} "$@"
|
2018-02-20 04:45:03 +03:00
|
|
|
'';
|
|
|
|
|
2022-04-29 03:22:18 +03:00
|
|
|
nix-bootstrap = { target, extraTargets ? [], run, nix-user-chroot' ? nix-user-chroot, nixUserChrootFlags ? "", initScript ? "" }:
|
2018-02-20 04:45:03 +03:00
|
|
|
let
|
2022-04-29 03:22:18 +03:00
|
|
|
script = makeStartup { inherit target nixUserChrootFlags nix-user-chroot' run initScript; };
|
2018-02-20 04:45:03 +03:00
|
|
|
in makebootstrap {
|
2018-04-04 23:04:37 +03:00
|
|
|
startup = ".${script} '\"$@\"'";
|
2018-02-20 04:45:03 +03:00
|
|
|
targets = [ "${script}" ] ++ extraTargets;
|
2017-04-30 03:53:32 +03:00
|
|
|
};
|
|
|
|
|
2018-04-05 00:19: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
|
2018-04-05 00:19:32 +03:00
|
|
|
nix-user-chroot'' = targets: nix-user-chroot.overrideDerivation (o: {
|
|
|
|
buildInputs = o.buildInputs ++ targets;
|
|
|
|
makeFlags = o.makeFlags ++ [
|
2021-07-19 15:00:00 +03:00
|
|
|
''ENV_PATH="${lib.makeBinPath targets}"''
|
2017-04-30 03:53:32 +03:00
|
|
|
];
|
2022-04-29 03:22:18 +03:00
|
|
|
}); in { target, extraTargets ? [], run, initScript ? "" }: nix-bootstrap {
|
|
|
|
inherit target extraTargets run initScript;
|
2017-04-30 03:53:32 +03:00
|
|
|
nix-user-chroot' = nix-user-chroot'' extraTargets;
|
2017-04-26 09:31:01 +03:00
|
|
|
};
|
2016-06-15 19:23:19 +03:00
|
|
|
}
|