2019-10-04 11:45:33 +03:00
|
|
|
{ nixpkgs, system, overlay }:
|
2019-06-11 22:45:57 +03:00
|
|
|
|
2019-10-04 11:45:33 +03:00
|
|
|
with import (nixpkgs + "/nixos/lib/testing.nix") {
|
|
|
|
inherit system;
|
|
|
|
extraConfigurations = [ { nixpkgs.overlays = [ overlay ]; } ];
|
|
|
|
};
|
2019-06-11 22:45:57 +03:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
# Generate a fake root CA and a fake github.com certificate.
|
|
|
|
cert = pkgs.runCommand "cert" { buildInputs = [ pkgs.openssl ]; }
|
|
|
|
''
|
|
|
|
mkdir -p $out
|
|
|
|
|
|
|
|
openssl genrsa -out ca.key 2048
|
|
|
|
openssl req -new -x509 -days 36500 -key ca.key \
|
|
|
|
-subj "/C=NL/ST=Denial/L=Springfield/O=Dis/CN=Root CA" -out $out/ca.crt
|
|
|
|
|
|
|
|
openssl req -newkey rsa:2048 -nodes -keyout $out/server.key \
|
|
|
|
-subj "/C=CN/ST=Denial/L=Springfield/O=Dis/CN=github.com" -out server.csr
|
|
|
|
openssl x509 -req -extfile <(printf "subjectAltName=DNS:api.github.com,DNS:github.com,DNS:raw.githubusercontent.com") \
|
|
|
|
-days 36500 -in server.csr -CA $out/ca.crt -CAkey ca.key -CAcreateserial -out $out/server.crt
|
|
|
|
'';
|
|
|
|
|
|
|
|
registry = pkgs.writeTextFile {
|
|
|
|
name = "registry";
|
|
|
|
text = ''
|
|
|
|
{
|
2020-06-03 17:29:04 +03:00
|
|
|
"flakes": [
|
|
|
|
{
|
|
|
|
"from": {
|
|
|
|
"type": "indirect",
|
|
|
|
"id": "nixpkgs"
|
|
|
|
},
|
|
|
|
"to": {
|
|
|
|
"type": "github",
|
|
|
|
"owner": "NixOS",
|
|
|
|
"repo": "nixpkgs"
|
|
|
|
}
|
2019-06-11 22:45:57 +03:00
|
|
|
}
|
2020-06-03 17:29:04 +03:00
|
|
|
],
|
|
|
|
"version": 2
|
2019-06-11 22:45:57 +03:00
|
|
|
}
|
|
|
|
'';
|
|
|
|
destination = "/flake-registry.json";
|
|
|
|
};
|
|
|
|
|
2019-11-06 15:48:35 +02:00
|
|
|
api = pkgs.runCommand "nixpkgs-flake" {}
|
2019-06-11 22:45:57 +03:00
|
|
|
''
|
2019-11-06 15:48:35 +02:00
|
|
|
mkdir -p $out/tarball
|
|
|
|
|
2019-06-11 22:45:57 +03:00
|
|
|
dir=NixOS-nixpkgs-${nixpkgs.shortRev}
|
|
|
|
cp -prd ${nixpkgs} $dir
|
|
|
|
# Set the correct timestamp in the tarball.
|
2020-04-03 22:36:21 +03:00
|
|
|
find $dir -print0 | xargs -0 touch -t ${builtins.substring 0 12 nixpkgs.lastModifiedDate}.${builtins.substring 12 2 nixpkgs.lastModifiedDate} --
|
2020-01-22 01:25:17 +02:00
|
|
|
tar cfz $out/tarball/${nixpkgs.rev} $dir --hard-dereference
|
2019-11-06 15:48:35 +02:00
|
|
|
|
|
|
|
mkdir -p $out/commits
|
|
|
|
echo '{"sha": "${nixpkgs.rev}"}' > $out/commits/master
|
2019-06-11 22:45:57 +03:00
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
makeTest (
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
nodes =
|
|
|
|
{ # Impersonate github.com and api.github.com.
|
|
|
|
github =
|
|
|
|
{ config, pkgs, ... }:
|
|
|
|
{ networking.firewall.allowedTCPPorts = [ 80 443 ];
|
|
|
|
|
|
|
|
services.httpd.enable = true;
|
|
|
|
services.httpd.adminAddr = "foo@example.org";
|
|
|
|
services.httpd.extraConfig = ''
|
|
|
|
ErrorLog syslog:local6
|
|
|
|
'';
|
2020-03-20 16:03:18 +02:00
|
|
|
services.httpd.virtualHosts."github.com" =
|
|
|
|
{ forceSSL = true;
|
|
|
|
sslServerKey = "${cert}/server.key";
|
|
|
|
sslServerCert = "${cert}/server.crt";
|
|
|
|
servedDirs =
|
|
|
|
[ { urlPath = "/NixOS/flake-registry/raw/master";
|
|
|
|
dir = registry;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
services.httpd.virtualHosts."api.github.com" =
|
|
|
|
{ forceSSL = true;
|
|
|
|
sslServerKey = "${cert}/server.key";
|
|
|
|
sslServerCert = "${cert}/server.crt";
|
|
|
|
servedDirs =
|
|
|
|
[ { urlPath = "/repos/NixOS/nixpkgs";
|
|
|
|
dir = api;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2019-06-11 22:45:57 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
client =
|
2019-11-06 15:48:35 +02:00
|
|
|
{ config, lib, pkgs, nodes, ... }:
|
2019-06-11 22:45:57 +03:00
|
|
|
{ virtualisation.writableStore = true;
|
2019-12-18 15:34:03 +02:00
|
|
|
virtualisation.diskSize = 2048;
|
2019-06-11 22:45:57 +03:00
|
|
|
virtualisation.pathsInNixDB = [ pkgs.hello pkgs.fuse ];
|
2020-03-20 16:03:18 +02:00
|
|
|
virtualisation.memorySize = 4096;
|
2019-11-06 15:48:35 +02:00
|
|
|
nix.binaryCaches = lib.mkForce [ ];
|
|
|
|
nix.extraOptions = "experimental-features = nix-command flakes";
|
2019-06-11 22:45:57 +03:00
|
|
|
environment.systemPackages = [ pkgs.jq ];
|
|
|
|
networking.hosts.${(builtins.head nodes.github.config.networking.interfaces.eth1.ipv4.addresses).address} =
|
|
|
|
[ "github.com" "api.github.com" "raw.githubusercontent.com" ];
|
|
|
|
security.pki.certificateFiles = [ "${cert}/ca.crt" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = { nodes }:
|
|
|
|
''
|
|
|
|
use POSIX qw(strftime);
|
|
|
|
|
|
|
|
startAll;
|
|
|
|
|
|
|
|
$github->waitForUnit("httpd.service");
|
|
|
|
|
|
|
|
$client->succeed("curl -v https://github.com/ >&2");
|
|
|
|
|
2020-05-21 23:02:34 +03:00
|
|
|
$client->succeed("nix registry list | grep nixpkgs");
|
2019-06-11 22:45:57 +03:00
|
|
|
|
|
|
|
$client->succeed("nix flake info nixpkgs --json | jq -r .revision") eq "${nixpkgs.rev}\n"
|
|
|
|
or die "revision mismatch";
|
|
|
|
|
2020-05-21 23:02:34 +03:00
|
|
|
$client->succeed("nix registry pin nixpkgs");
|
2019-06-11 22:45:57 +03:00
|
|
|
|
|
|
|
$client->succeed("nix flake info nixpkgs --tarball-ttl 0 >&2");
|
|
|
|
|
|
|
|
# Shut down the web server. The flake should be cached on the client.
|
|
|
|
$github->succeed("systemctl stop httpd.service");
|
|
|
|
|
|
|
|
my $date = $client->succeed("nix flake info nixpkgs --json | jq -M .lastModified");
|
2020-04-03 22:36:21 +03:00
|
|
|
strftime("%Y%m%d%H%M%S", gmtime($date)) eq "${nixpkgs.lastModifiedDate}" or die "time mismatch";
|
2019-06-11 22:45:57 +03:00
|
|
|
|
2019-10-04 11:45:33 +03:00
|
|
|
$client->succeed("nix build nixpkgs#hello");
|
2019-06-11 22:45:57 +03:00
|
|
|
|
|
|
|
# The build shouldn't fail even with --tarball-ttl 0 (the server
|
|
|
|
# being down should not be a fatal error).
|
2019-10-04 11:45:33 +03:00
|
|
|
$client->succeed("nix build nixpkgs#fuse --tarball-ttl 0");
|
2019-06-11 22:45:57 +03:00
|
|
|
'';
|
|
|
|
|
|
|
|
})
|