at master 1.9 kB view raw
1# Miscellaneous small tests that don't warrant their own VM run. 2{ pkgs, ... }: 3 4let 5 inherit (pkgs) lib; 6 tests.default = testsForPackage { nixPackage = pkgs.nix; }; 7 8 testsForPackage = args: { 9 # If the attribute is not named 'test' 10 # You will break all the universe on the release-*.nix side of things. 11 # `discoverTests` relies on `test` existence to perform a `callTest`. 12 test = testMiscFeatures args // { 13 passthru.override = args': (testsForPackage (args // args')).test; 14 }; 15 }; 16 17 testMiscFeatures = 18 { nixPackage, ... }: 19 pkgs.testers.nixosTest ( 20 let 21 foo = pkgs.writeText "foo" "Hello World"; 22 in 23 { 24 name = "${nixPackage.pname}-misc"; 25 meta.maintainers = with lib.maintainers; [ 26 raitobezarius 27 artturin 28 ]; 29 30 nodes.machine = 31 { lib, ... }: 32 { 33 system.extraDependencies = [ foo ]; 34 35 nix.package = nixPackage; 36 }; 37 38 testScript = '' 39 import json 40 41 def get_path_info(path): 42 result = machine.succeed(f"nix --option experimental-features nix-command path-info --json {path}") 43 parsed = json.loads(result) 44 return parsed 45 46 with subtest("nix-db"): 47 out = "${foo}" 48 info = get_path_info(out) 49 print(info) 50 51 pathinfo = info[0] if isinstance(info, list) else info[out] 52 53 if ( 54 pathinfo["narHash"] 55 != "sha256-BdMdnb/0eWy3EddjE83rdgzWWpQjfWPAj3zDIFMD3Ck=" 56 ): 57 raise Exception("narHash not set") 58 59 if pathinfo["narSize"] != 128: 60 raise Exception("narSize not set") 61 62 with subtest("nix-db"): 63 machine.succeed("nix-store -qR /run/current-system | grep nixos-") 64 ''; 65 } 66 ); 67in 68tests