at master 1.3 kB view raw
1{ pkgs, lib, ... }: 2{ 3 name = "nar-serve"; 4 meta.maintainers = [ lib.maintainers.rizary ]; 5 nodes = { 6 server = 7 { pkgs, ... }: 8 { 9 services.nginx = { 10 enable = true; 11 virtualHosts.default.root = "/var/www"; 12 }; 13 services.nar-serve = { 14 enable = true; 15 # Connect to the localhost nginx instead of the default 16 # https://cache.nixos.org 17 cacheURL = "http://localhost/"; 18 }; 19 environment.systemPackages = [ 20 pkgs.hello 21 pkgs.curl 22 ]; 23 24 networking.firewall.allowedTCPPorts = [ 8383 ]; 25 26 # virtualisation.diskSize = 2 * 1024; 27 }; 28 }; 29 testScript = '' 30 import os 31 32 start_all() 33 34 # Create a fake cache with Nginx service the static files 35 server.succeed( 36 "nix --experimental-features nix-command copy --to file:///var/www ${pkgs.hello}" 37 ) 38 server.wait_for_unit("nginx.service") 39 server.wait_for_open_port(80) 40 41 # Check that nar-serve can return the content of the derivation 42 drvName = os.path.basename("${pkgs.hello}") 43 drvHash = drvName.split("-")[0] 44 server.wait_for_unit("nar-serve.service") 45 server.succeed( 46 "curl -o hello -f http://localhost:8383/nix/store/{}/bin/hello".format(drvHash) 47 ) 48 ''; 49}