]> git.scottworley.com Git - nix-currently-building/commitdiff
Show what nix-daemon is currently building 1.0.0
authorScott Worley <scottworley@scottworley.com>
Wed, 1 Jul 2020 19:44:08 +0000 (12:44 -0700)
committerScott Worley <scottworley@scottworley.com>
Wed, 1 Jul 2020 19:49:29 +0000 (12:49 -0700)
README.md [new file with mode: 0644]
default.nix [new file with mode: 0644]
nix_currently_building.py [new file with mode: 0755]
setup.py [new file with mode: 0644]

diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..9c1ce17
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+A crummy workaround for https://github.com/NixOS/nix/issues/3200
diff --git a/default.nix b/default.nix
new file mode 100644 (file)
index 0000000..4972f1e
--- /dev/null
@@ -0,0 +1,7 @@
+{ pkgs ? import <nixpkgs> { } }:
+pkgs.python3Packages.callPackage ({ lib, buildPythonPackage, }:
+  buildPythonPackage rec {
+    pname = "nix-currently-building";
+    version = "1.0.0";
+    src = lib.cleanSource ./.;
+  }) { }
diff --git a/nix_currently_building.py b/nix_currently_building.py
new file mode 100755 (executable)
index 0000000..1b507c8
--- /dev/null
@@ -0,0 +1,28 @@
+import os
+import subprocess
+import time
+
+
+BLOCK_SIZE = 4096
+MIN_AGE = time.time() - 86400 * 7
+
+
+def removesuffix(s, suf):  # Until python 3.9
+    return s[:len(s) - len(suf)] if s.endswith(suf) else s
+
+
+def truncated(log):
+    return subprocess.run(['bunzip2', '--test', log], stderr=subprocess.DEVNULL).returncode == 2
+
+
+def main():
+    for d, _, files in os.walk(os.environ.get('NIX_LOG_DIR', '/nix/var/log/nix')):
+        for f in files:
+            path = os.path.join(d, f)
+            st = os.stat(path)
+            if (st.st_size % BLOCK_SIZE) == 0 and st.st_mtime > MIN_AGE and truncated(path):
+                print(d[-2:] + removesuffix(f, '.bz2'))
+
+
+if __name__ == '__main__':
+    main()
diff --git a/setup.py b/setup.py
new file mode 100644 (file)
index 0000000..bee174c
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,11 @@
+from setuptools import setup
+
+setup(
+    name='nix_currently_building',
+    py_modules=['nix_currently_building'],
+    entry_points={
+        'console_scripts': [
+            'nix-currently-building = nix_currently_building:main',
+        ],
+    }
+)