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.
This commit is contained in:
parent
76612b17c0
commit
ec02a76ff5
21
pkgs/by-name/ch/chroot-realpath/package.nix
Normal file
21
pkgs/by-name/ch/chroot-realpath/package.nix
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
lib,
|
||||
rustPlatform,
|
||||
}:
|
||||
|
||||
let
|
||||
cargo = lib.importTOML ./src/Cargo.toml;
|
||||
in
|
||||
rustPlatform.buildRustPackage {
|
||||
pname = cargo.package.name;
|
||||
version = cargo.package.version;
|
||||
|
||||
src = ./src;
|
||||
|
||||
cargoLock.lockFile = ./src/Cargo.lock;
|
||||
|
||||
meta = {
|
||||
description = "Output a path's realpath within a chroot.";
|
||||
maintainers = [ lib.maintainers.elvishjerricco ];
|
||||
};
|
||||
}
|
7
pkgs/by-name/ch/chroot-realpath/src/Cargo.lock
generated
Normal file
7
pkgs/by-name/ch/chroot-realpath/src/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "chroot-realpath"
|
||||
version = "0.1.0"
|
9
pkgs/by-name/ch/chroot-realpath/src/Cargo.toml
Normal file
9
pkgs/by-name/ch/chroot-realpath/src/Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "chroot-realpath"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
[profile.release]
|
||||
opt-level = "z"
|
24
pkgs/by-name/ch/chroot-realpath/src/src/main.rs
Normal file
24
pkgs/by-name/ch/chroot-realpath/src/src/main.rs
Normal file
@ -0,0 +1,24 @@
|
||||
use std::env;
|
||||
use std::io::{stdout, Error, ErrorKind, Write};
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
use std::os::unix::fs;
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
if args.len() != 3 {
|
||||
return Err(Error::new(
|
||||
ErrorKind::InvalidInput,
|
||||
format!("Usage: {} <chroot> <path>", args[0]),
|
||||
));
|
||||
}
|
||||
|
||||
fs::chroot(&args[1])?;
|
||||
std::env::set_current_dir("/")?;
|
||||
|
||||
let path = std::fs::canonicalize(&args[2])?;
|
||||
|
||||
stdout().write_all(path.into_os_string().as_bytes())?;
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue
Block a user