summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>2023-05-12 18:01:18 +0000
committerGitHub <noreply@github.com>2023-05-12 18:01:18 +0000
commit206417b7a2e3b7a712566de8276d7bd1706f0412 (patch)
tree172c22a931461a0304811cc9d262062636c86f0f /pkgs/build-support
parent30ae8398a940cdc001cfb9a59109c216931e9fac (diff)
parent587ac4e842be36ca36900c6f3b0343b7e01117a6 (diff)
Merge master into staging-next
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/dotnet/make-nuget-source/default.nix18
-rw-r--r--pkgs/build-support/dotnet/make-nuget-source/extract-licenses-from-nupkgs.py30
-rw-r--r--pkgs/build-support/testers/default.nix14
-rw-r--r--pkgs/build-support/testers/test/default.nix11
4 files changed, 64 insertions, 9 deletions
diff --git a/pkgs/build-support/dotnet/make-nuget-source/default.nix b/pkgs/build-support/dotnet/make-nuget-source/default.nix
index ea1c5328082d5..6bda65f18d58b 100644
--- a/pkgs/build-support/dotnet/make-nuget-source/default.nix
+++ b/pkgs/build-support/dotnet/make-nuget-source/default.nix
@@ -1,4 +1,4 @@
-{ dotnetPackages, lib, xml2, stdenvNoCC }:
+{ lib, python3, stdenvNoCC }:
 
 { name
 , description ? ""
@@ -10,21 +10,21 @@ let
     inherit name;
 
     meta.description = description;
-    nativeBuildInputs = [ dotnetPackages.Nuget xml2 ];
+    nativeBuildInputs = [ python3 ];
 
     buildCommand = ''
-      export HOME=$(mktemp -d)
       mkdir -p $out/{lib,share}
 
-      ${lib.concatMapStringsSep "\n" (dep: ''
-        nuget init "${dep}" "$out/lib"
-      '') deps}
+      (
+        shopt -s nullglob
+        for nupkg in ${lib.concatMapStringsSep " " (dep: "\"${dep}\"/*.nupkg") deps}; do
+          cp --no-clobber "$nupkg" $out/lib
+        done
+      )
 
       # Generates a list of all licenses' spdx ids, if available.
       # Note that this currently ignores any license provided in plain text (e.g. "LICENSE.txt")
-      find "$out/lib" -name "*.nuspec" -exec sh -c \
-        "NUSPEC=\$(xml2 < {}) && echo "\$NUSPEC" | grep license/@type=expression | tr -s \  '\n' | grep "license=" | cut -d'=' -f2" \
-      \; | sort -u > $out/share/licenses
+      python ${./extract-licenses-from-nupkgs.py} $out/lib > $out/share/licenses
     '';
   } // { # We need data from `$out` for `meta`, so we have to use overrides as to not hit infinite recursion.
     meta.licence = let
diff --git a/pkgs/build-support/dotnet/make-nuget-source/extract-licenses-from-nupkgs.py b/pkgs/build-support/dotnet/make-nuget-source/extract-licenses-from-nupkgs.py
new file mode 100644
index 0000000000000..22564b0bb2bc8
--- /dev/null
+++ b/pkgs/build-support/dotnet/make-nuget-source/extract-licenses-from-nupkgs.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python3
+"""
+Opens each .nupkg file in a directory, and extracts the SPDX license identifiers
+from them if they exist. The SPDX license identifier is stored in the
+'<license type="expression">...</license>' tag in the .nuspec file.
+All found license identifiers will be printed to stdout.
+"""
+
+from glob import glob
+from pathlib import Path
+import sys
+import xml.etree.ElementTree as ET
+import zipfile
+
+all_licenses = set()
+
+if len(sys.argv) < 2:
+    print(f"Usage: {sys.argv[0]} DIRECTORY")
+    sys.exit(1)
+
+nupkg_dir = Path(sys.argv[1])
+for nupkg_name in glob("*.nupkg", root_dir=nupkg_dir):
+    with zipfile.ZipFile(nupkg_dir / nupkg_name) as nupkg:
+        for nuspec_name in [name for name in nupkg.namelist() if name.endswith(".nuspec")]:
+            with nupkg.open(nuspec_name) as nuspec_stream:
+                nuspec = ET.parse(nuspec_stream)
+                licenses = nuspec.findall(".//{*}license[@type='expression']")
+                all_licenses.update([license.text for license in licenses])
+
+print("\n".join(sorted(all_licenses)))
diff --git a/pkgs/build-support/testers/default.nix b/pkgs/build-support/testers/default.nix
index 542133dd959a3..190ce72d0e630 100644
--- a/pkgs/build-support/testers/default.nix
+++ b/pkgs/build-support/testers/default.nix
@@ -95,6 +95,20 @@
     in checked;
 
   # See doc/builders/testers.chapter.md or
+  # https://nixos.org/manual/nixpkgs/unstable/#tester-runNixOSTest
+  runNixOSTest =
+    let nixos = import ../../../nixos/lib {};
+    in testModule:
+        nixos.runTest {
+          _file = "pkgs.runNixOSTest implementation";
+          imports = [
+            (lib.setDefaultModuleLocation "the argument that was passed to pkgs.runNixOSTest" testModule)
+          ];
+          hostPkgs = pkgs;
+          node.pkgs = pkgs;
+        };
+
+  # See doc/builders/testers.chapter.md or
   # https://nixos.org/manual/nixpkgs/unstable/#tester-invalidateFetcherByDrvHash
   nixosTest =
     let
diff --git a/pkgs/build-support/testers/test/default.nix b/pkgs/build-support/testers/test/default.nix
index 313c556737fb3..fc4df4964f398 100644
--- a/pkgs/build-support/testers/test/default.nix
+++ b/pkgs/build-support/testers/test/default.nix
@@ -14,6 +14,17 @@ in
 lib.recurseIntoAttrs {
   hasPkgConfigModule = pkgs.callPackage ../hasPkgConfigModule/tests.nix { };
 
+  runNixOSTest-example = pkgs-with-overlay.testers.runNixOSTest ({ lib, ... }: {
+    name = "runNixOSTest-test";
+    nodes.machine = { pkgs, ... }: {
+      system.nixos = dummyVersioning;
+      environment.systemPackages = [ pkgs.proof-of-overlay-hello pkgs.figlet ];
+    };
+    testScript = ''
+      machine.succeed("hello | figlet >/dev/console")
+    '';
+  });
+
   # Check that the wiring of nixosTest is correct.
   # Correct operation of the NixOS test driver should be asserted elsewhere.
   nixosTest-example = pkgs-with-overlay.testers.nixosTest ({ lib, pkgs, figlet, ... }: {