Skip to content

Commit

Permalink
fix wrong applet
Browse files Browse the repository at this point in the history
  • Loading branch information
viperML committed Jul 9, 2023
1 parent 333a407 commit 4ef67a1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 47 deletions.
20 changes: 3 additions & 17 deletions pkgs/init.lua
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
local miq = require "miq"

---@param first table<string, any>
---@param second table<string, any>
local merge = function(first, second)
for k, v in pairs(second) do
if first[k] == nil then
first[k] = v
else
error("Tried to merge two tables with same key: " .. k, 2)
end
end
end

local pkgs = {}

-- merge(pkgs, require "bootstrap")
-- merge(pkgs, require "stage1")

-- pkgs.bootstrap = require("bootstrap")
pkgs.stage0 = require "stage0"
pkgs.stage1 = require "stage1"

pkgs.empty0 = miq.package {
name = "empty0",
script = [[
set -x
echo $PWD
pwd
sleep
pwd
]],
}

Expand Down
26 changes: 3 additions & 23 deletions pkgs/stage0.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,6 @@ x.bootstrap_tools = miq.fetch {
url = "https://wdtz.org/files/gywxhjgl70sxippa0pxs0vj5qcgz1wi8-stdenv-bootstrap-tools/on-server/bootstrap-tools.tar.xz",
}

x.busybox = miq.fetch {
url = "https://wdtz.org/files/gywxhjgl70sxippa0pxs0vj5qcgz1wi8-stdenv-bootstrap-tools/on-server/busybox",
executable = true,
}

x.toybox = miq.fetch {
url = "http://landley.net/toybox/bin/toybox-x86_64",
executable = true,
}
miq.trace(x.toybox)

local t = f "ls -la {{x.toybox}}"
miq.trace(t)

x.unpack_bootstrap_tools = miq.fetch {
url = "https://raw.githubusercontent.com/NixOS/nixpkgs/d6b863fd9b7bb962e6f9fdf292419a775e772891/pkgs/stdenv/linux/bootstrap-tools-musl/scripts/unpack-bootstrap-tools.sh",
Expand All @@ -32,17 +19,10 @@ x.bootstrap = miq.package {
name = "bootstrap",
script = f [[
set -exu
{{x.toybox}} mkdir -p $HOME/bin
export PATH="$HOME/bin:${PATH}"
{{x.toybox}} ln -vs {{x.toybox}} $HOME/bin/ln
{{x.toybox}} ln -vs {{x.toybox}} $HOME/bin/cp
{{x.toybox}} ln -vs {{x.toybox}} $HOME/bin/tar
{{x.toybox}} ln -vs {{x.toybox}} $HOME/bin/mkdir
{{x.toybox}} ln -vs {{x.toybox}} $HOME/bin/chmod
export out=$miq_out
export out="$miq_out"
export tarball={{x.bootstrap_tools}}
export builder={{x.busybox}}
export builder=/usr/bin/busybox
{{x.unpack_bootstrap_tools}}
]],
}
Expand Down
6 changes: 5 additions & 1 deletion pkgs/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ x.stdenvBuilder = function(input)
},
script = f [[
set -x
mkdir -p $miq_out
tee $miq_out/stdenv.sh <<EOF
echo "stdenv setup" >&2
export PATH="{{input.cc}}/bin:{{input.ld}}/bin:{{input.coreutils}}/bin"
Expand All @@ -80,6 +81,8 @@ x.stdenvBuilder = function(input)
export NIX_DEBUG=1
mkdir -p \$miq_out
{{input.extra}}
EOF
]],
Expand Down Expand Up @@ -153,7 +156,8 @@ x.fetchTarBuilder = function(input)
script = f [[
set -ex
export PATH="{{input.PATH}}"
cd $miq_out
mkdir -p $PREFIX
cd $PREFIX
tar -xvf {{fetch}} --strip-components=1 --no-same-permissions --no-same-owner
{{post}}
Expand Down
16 changes: 11 additions & 5 deletions src/build_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::num::NonZeroUsize;
use std::ops::Deref;
use std::os::fd::{AsRawFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
use std::path::Path;
use std::process::Stdio;
use std::process::{ExitStatus, Stdio};
use std::ptr::addr_of;
use std::sync::Mutex;

Expand All @@ -32,6 +32,7 @@ use crate::semaphore::SemaphoreHandle;
use crate::*;

const STACK_SIZE: usize = 1024 * 1024;
const BUILD_SCRIPT_LOC: &str = "/build-script";

#[async_trait]
impl Build for Package {
Expand Down Expand Up @@ -61,8 +62,11 @@ impl Build for Package {
let ppid = Pid::this();

let mut cmd = tokio::process::Command::new("/bin/bash");
cmd.args(["--norc", "--noprofile", "/build-script"]);
cmd.kill_on_drop(true);
cmd.args(["--norc", "--noprofile"]);
cmd.arg(BUILD_SCRIPT_LOC);
// cmd.arg("-i");

cmd.env_clear();
cmd.envs([
("HOME", "/build"),
("PREFIX", path.to_str().unwrap()),
Expand All @@ -75,13 +79,14 @@ impl Build for Package {
("PATH", "/usr/bin:/bin"),
]);
cmd.envs(&self.env);

cmd.kill_on_drop(true);
cmd.stdout(Stdio::piped());
cmd.stderr(Stdio::piped());

let _self = self.clone();
unsafe {
cmd.pre_exec(move || {
// let sandbox_path = sandbox_path.clone();
let pid = Pid::this();
let _span = span!(Level::WARN, "child", ?pid, ?ppid);
let _enter = _span.enter();
Expand Down Expand Up @@ -114,7 +119,8 @@ impl Build for Package {
let bash = mem_app::BASH
.as_ref()
.map_err(|e| Into::<io::Error>::into(*e))?;
let busybox = mem_app::BASH

let busybox = mem_app::BUSYBOX
.as_ref()
.map_err(|e| Into::<io::Error>::into(*e))?;

Expand Down
2 changes: 1 addition & 1 deletion src/mem_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl MemApp {
let dst = nix::sys::mman::mmap(
None,
NonZeroUsize::new(len).unwrap(),
ProtFlags::PROT_WRITE,
ProtFlags::PROT_WRITE | ProtFlags::PROT_READ,
MapFlags::MAP_SHARED,
fd.as_raw_fd(),
0,
Expand Down

0 comments on commit 4ef67a1

Please sign in to comment.