nix-files/pkgs/additional/sanebox/default.nix

62 lines
1.5 KiB
Nix
Raw Normal View History

{ lib, stdenv
, bash
, bubblewrap
, firejail
, landlock-sandboxer
, libcap
, substituteAll
2024-05-15 01:41:40 +00:00
, profileDir ? "/share/sanebox/profiles"
}:
let
2024-05-15 01:41:40 +00:00
sanebox = substituteAll {
src = ./sanebox;
inherit bash bubblewrap firejail libcap;
landlockSandboxer = landlock-sandboxer;
firejailProfileDirs = "/run/current-system/sw/etc/firejail /etc/firejail ${firejail}/etc/firejail";
};
self = stdenv.mkDerivation {
2024-05-15 01:41:40 +00:00
pname = "sanebox";
version = "0.1";
2024-05-15 01:41:40 +00:00
src = sanebox;
dontUnpack = true;
buildPhase = ''
runHook preBuild
2024-05-15 01:41:40 +00:00
substituteAll "$src" sanebox \
--replace-fail '@out@' "$out"
runHook postBuild
'';
installPhase = ''
runHook preInstall
install -d "$out"
install -d "$out/bin"
2024-05-15 01:41:40 +00:00
install -m 755 sanebox $out/bin/sanebox
runHook postInstall
'';
passthru = {
inherit landlock-sandboxer;
withProfiles = profiles: self.overrideAttrs (base: {
inherit profiles;
postInstall = (base.postInstall or "") + ''
2024-05-15 01:41:40 +00:00
install -d $out/share/sanebox
ln -s "${profiles}/${profileDir}" "$out/${profileDir}"
'';
});
};
meta = {
description = ''
helper program to run some other program in a sandbox.
factoring this out allows:
1. to abstract over the particular sandbox implementation (bwrap, firejail, ...).
2. to modify sandbox settings without forcing a rebuild of the sandboxed package.
'';
2024-05-15 01:41:40 +00:00
mainProgram = "sanebox";
};
};
in self