Skip to content

Commit ec02a76

Browse files
chroot-realpath: init
Now it's placed between initrd-switch-root.target and initrd-switch-root.service, meaning it is truly the last thing to happen before switch-root, as it should be.
1 parent 76612b1 commit ec02a76

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
lib,
3+
rustPlatform,
4+
}:
5+
6+
let
7+
cargo = lib.importTOML ./src/Cargo.toml;
8+
in
9+
rustPlatform.buildRustPackage {
10+
pname = cargo.package.name;
11+
version = cargo.package.version;
12+
13+
src = ./src;
14+
15+
cargoLock.lockFile = ./src/Cargo.lock;
16+
17+
meta = {
18+
description = "Output a path's realpath within a chroot.";
19+
maintainers = [ lib.maintainers.elvishjerricco ];
20+
};
21+
}

pkgs/by-name/ch/chroot-realpath/src/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "chroot-realpath"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
8+
[profile.release]
9+
opt-level = "z"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use std::env;
2+
use std::io::{stdout, Error, ErrorKind, Write};
3+
use std::os::unix::ffi::OsStrExt;
4+
use std::os::unix::fs;
5+
6+
fn main() -> std::io::Result<()> {
7+
let args: Vec<String> = env::args().collect();
8+
9+
if args.len() != 3 {
10+
return Err(Error::new(
11+
ErrorKind::InvalidInput,
12+
format!("Usage: {} <chroot> <path>", args[0]),
13+
));
14+
}
15+
16+
fs::chroot(&args[1])?;
17+
std::env::set_current_dir("/")?;
18+
19+
let path = std::fs::canonicalize(&args[2])?;
20+
21+
stdout().write_all(path.into_os_string().as_bytes())?;
22+
23+
Ok(())
24+
}

0 commit comments

Comments
 (0)