about summary refs log tree commit diff
path: root/pkgs/profpatsch/nman/nman.rs
diff options
context:
space:
mode:
authorsternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org>2021-02-12 18:04:47 +0100
committersternenseemann <sternenseemann@systemli.org>2021-02-25 19:52:33 +0100
commitfcf24459e0c7fb072e77f3416ff27881c4c58f2e (patch)
treef8065c5fe7b63be66cb09a4162fc9a89ffd18dd8 /pkgs/profpatsch/nman/nman.rs
parent95387b07393fe293b423c87fdd8ad2e78901a067 (diff)
pkgs/profpatsch/nman: don't realise all build outputs for `out`
nix-instantiate unfortunately prints the plain .drv path for <attr>.out
wheras it prints <name>.drv!<output> 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.
Diffstat (limited to 'pkgs/profpatsch/nman/nman.rs')
-rw-r--r--pkgs/profpatsch/nman/nman.rs20
1 files changed, 15 insertions, 5 deletions
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<DrvWithOutput<'a>> {
 fn build_man_page(drv: DrvWithOutput, section: &str, page: &str, tempdir: &TempDir) -> Result<Option<PathBuf>, 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)?;