From ceab386076cc98ac447c8bbc768691bce5bf8ac6 Mon Sep 17 00:00:00 2001 From: aszlig Date: Thu, 10 Dec 2020 02:30:45 +0100 Subject: profiles/base: Add helper for showing last Nix log This is a common pattern I encounter on a daily basis, which involves copy & pasting the store path of a failed build to "nix log". Now the same is just a matter of running "nlast" and we get rid of the useless copy & paste. The way we do this does have a small goof: Using mtime (or really any time, other than atime, which commonly is disabled) is not going to work if we *repeat* an older Nix build, since this will only change the log file but the prefix directory will be unchanged. Since addressing this goof would most likely result in iterating through *all* log files, I'm not doing it since I think it doesn't occur very often in practice. If I happen to be wrong on that, we could still go for the heavyweight solution. Also, I went for implementing this in Python instead of a shell script, because the latter would not only be less readable but also way slower since we need to either fork out for every stat command or use ls and head to figure out the newest file. Signed-off-by: aszlig --- pkgs/aszlig/default.nix | 1 + pkgs/aszlig/nlast/default.nix | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 pkgs/aszlig/nlast/default.nix (limited to 'pkgs/aszlig') diff --git a/pkgs/aszlig/default.nix b/pkgs/aszlig/default.nix index d3f42882..81178000 100644 --- a/pkgs/aszlig/default.nix +++ b/pkgs/aszlig/default.nix @@ -9,6 +9,7 @@ librxtx_java = callPackage ./librxtx-java { }; lockdev = callPackage ./lockdev { }; mutt = callPackage ./mutt { inherit mutt; }; + nlast = callPackage ./nlast { }; psi = callPackage ./psi { }; pvolctrl = callPackage ./pvolctrl { }; vim = callPackage ./vim { vim = vim_configurable; }; diff --git a/pkgs/aszlig/nlast/default.nix b/pkgs/aszlig/nlast/default.nix new file mode 100644 index 00000000..3ff149b6 --- /dev/null +++ b/pkgs/aszlig/nlast/default.nix @@ -0,0 +1,13 @@ +{ writeScriptBin, python3, nix }: + +writeScriptBin "nlast" '' + #!${python3.interpreter} + from os import execl + from functools import partial + from pathlib import Path + + newest = partial(max, key=lambda entry: entry.stat().st_mtime) + prefix = newest(Path('/nix/var/log/nix/drvs').iterdir()) + drvname = prefix.name + newest(prefix.iterdir()).stem + execl('${nix}/bin/nix', 'nix', 'log', Path('${builtins.storeDir}') / drvname) +'' -- cgit 1.4.1