From fcf24459e0c7fb072e77f3416ff27881c4c58f2e Mon Sep 17 00:00:00 2001 From: sternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org> Date: Fri, 12 Feb 2021 18:04:47 +0100 Subject: pkgs/profpatsch/nman: don't realise all build outputs for `out` nix-instantiate unfortunately prints the plain .drv path for .out wheras it prints .drv! for all non-default outputs. If we realise the plain .drv path, _all_ outputs are realised which is not desireable since we may not need extra store path being created by this, e. g. for a derivation with outputs = [ "out" "lib" "dev" ] we only need to realise "out" if the man pages are located in there, saving a bit of time and disk space. We implement this better behavior by adding the render function to DrvWithOutput which converts a DrvWithOutput (at the cost of copying) to an OsString. If the output is out, "!out" is appended to the path meaning nix-store will only realise the default output. --- pkgs/profpatsch/nman/nman.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'pkgs/profpatsch/nman') diff --git a/pkgs/profpatsch/nman/nman.rs b/pkgs/profpatsch/nman/nman.rs index b73836df..77086b87 100644 --- a/pkgs/profpatsch/nman/nman.rs +++ b/pkgs/profpatsch/nman/nman.rs @@ -1,5 +1,4 @@ -use std::cmp::Ordering; -use std::ffi::OsStr; +use std::ffi::{OsStr, OsString}; use std::io::{Error, ErrorKind, self, Write}; use std::os::unix::ffi::OsStrExt; use std::path::{Path, PathBuf}; @@ -100,6 +99,19 @@ struct DrvWithOutput<'a> { rendered: &'a [u8], } +impl DrvWithOutput<'_> { + fn render(&self) -> OsString { + match self.output { + DrvOutput::Out => { + let mut r = OsStr::from_bytes(self.rendered).to_os_string(); + r.push("!out"); + r + } + _ => OsStr::from_bytes(self.rendered).to_os_string(), + } + } +} + fn parse_output<'a>(output: &'a [u8]) -> DrvOutput<'a> { match output { b"out" => DrvOutput::Out, @@ -133,7 +145,7 @@ fn parse_drv_path<'a>(drv_path: &'a [u8]) -> Option> { fn build_man_page(drv: DrvWithOutput, section: &str, page: &str, tempdir: &TempDir) -> Result, NmanError> { let mut build = Command::new("nix-store") .arg("--realise") - .arg(OsStr::from_bytes(drv.rendered)) + .arg(drv.render()) .arg("--add-root") .arg(tempdir.as_ref().join("build-result")) .arg("--indirect") @@ -146,8 +158,6 @@ fn build_man_page(drv: DrvWithOutput, section: &str, page: &str, tempdir: &TempD // get the first line of the output, usually only one line // is printed, but this way we also get rid of the trailing '\n' - // TODO(sterni): use the !out suffix for default output drvs to - // prevent nix from realising all drv outputs. let first_path = build.stdout.split(|c| char::from(*c) == '\n') .next().ok_or(NmanError::Build)?; -- cgit 1.4.1