2023-06-07 12:26:30 +00:00
|
|
|
{ lib, config, nixpkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
pkgs = config.nodes.machine.nixpkgs.pkgs;
|
|
|
|
|
|
|
|
root = pkgs.runCommand "nixpkgs-flake" {}
|
|
|
|
''
|
2024-05-29 22:22:25 +00:00
|
|
|
mkdir -p $out/{stable,tags}
|
2023-06-07 12:26:30 +00:00
|
|
|
|
|
|
|
set -x
|
|
|
|
dir=nixpkgs-${nixpkgs.shortRev}
|
|
|
|
cp -prd ${nixpkgs} $dir
|
|
|
|
# Set the correct timestamp in the tarball.
|
2023-09-19 15:21:07 +00:00
|
|
|
find $dir -print0 | xargs -0 touch -h -t ${builtins.substring 0 12 nixpkgs.lastModifiedDate}.${builtins.substring 12 2 nixpkgs.lastModifiedDate} --
|
2023-06-07 12:26:30 +00:00
|
|
|
tar cfz $out/stable/${nixpkgs.rev}.tar.gz $dir --hard-dereference
|
|
|
|
|
2024-05-29 22:22:25 +00:00
|
|
|
# Set the "Link" header on the redirect but not the final response to
|
|
|
|
# simulate an S3-like serving environment where the final host cannot set
|
|
|
|
# arbitrary headers.
|
|
|
|
cat >$out/tags/.htaccess <<EOF
|
|
|
|
Redirect "/tags/latest.tar.gz" "/stable/${nixpkgs.rev}.tar.gz"
|
|
|
|
Header always set Link "<http://localhost/stable/${nixpkgs.rev}.tar.gz?rev=${nixpkgs.rev}&revCount=1234>; rel=\"immutable\""
|
|
|
|
EOF
|
2023-06-07 12:26:30 +00:00
|
|
|
'';
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
name = "tarball-flakes";
|
|
|
|
|
|
|
|
nodes =
|
|
|
|
{
|
|
|
|
machine =
|
|
|
|
{ config, pkgs, ... }:
|
|
|
|
{ networking.firewall.allowedTCPPorts = [ 80 ];
|
|
|
|
|
|
|
|
services.httpd.enable = true;
|
|
|
|
services.httpd.adminAddr = "foo@example.org";
|
|
|
|
services.httpd.extraConfig = ''
|
|
|
|
ErrorLog syslog:local6
|
|
|
|
'';
|
|
|
|
services.httpd.virtualHosts."localhost" =
|
|
|
|
{ servedDirs =
|
|
|
|
[ { urlPath = "/";
|
|
|
|
dir = root;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
virtualisation.writableStore = true;
|
|
|
|
virtualisation.diskSize = 2048;
|
|
|
|
virtualisation.additionalPaths = [ pkgs.hello pkgs.fuse ];
|
|
|
|
virtualisation.memorySize = 4096;
|
|
|
|
nix.settings.substituters = lib.mkForce [ ];
|
|
|
|
nix.extraOptions = "experimental-features = nix-command flakes";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = { nodes }: ''
|
|
|
|
# fmt: off
|
|
|
|
import json
|
|
|
|
|
|
|
|
start_all()
|
|
|
|
|
|
|
|
machine.wait_for_unit("httpd.service")
|
|
|
|
|
2024-05-29 22:22:25 +00:00
|
|
|
out = machine.succeed("nix flake metadata --json http://localhost/tags/latest.tar.gz")
|
2023-06-07 12:26:30 +00:00
|
|
|
print(out)
|
|
|
|
info = json.loads(out)
|
|
|
|
|
|
|
|
# Check that we got redirected to the immutable URL.
|
tests: add error messages to the asserts in tarball flakes test
In hopes of avoiding opaque error messages like the one in
https://buildbot.lix.systems/#/builders/49/builds/1054/steps/1/logs/stdio
Traceback (most recent call last):
File "/nix/store/wj6wh89jhd2492r781qsr09r9wydfs6m-nixos-test-driver-1.1/bin/.nixos-test-driver-wrapped", line 9, in <module>
sys.exit(main())
^^^^^^
File "/nix/store/wj6wh89jhd2492r781qsr09r9wydfs6m-nixos-test-driver-1.1/lib/python3.11/site-packages/test_driver/__init__.py", line 126, in main
driver.run_tests()
File "/nix/store/wj6wh89jhd2492r781qsr09r9wydfs6m-nixos-test-driver-1.1/lib/python3.11/site-packages/test_driver/driver.py", line 159, in run_tests
self.test_script()
File "/nix/store/wj6wh89jhd2492r781qsr09r9wydfs6m-nixos-test-driver-1.1/lib/python3.11/site-packages/test_driver/driver.py", line 151, in test_script
exec(self.tests, symbols, None)
File "<string>", line 13, in <module>
AssertionError
Change-Id: Idd2212a1c3714ce58c7c3a9f34c2ca4313eb6d55
2024-04-22 22:13:36 +00:00
|
|
|
locked_url = info["locked"]["url"]
|
2024-06-25 10:31:52 +00:00
|
|
|
assert locked_url == "http://localhost/stable/${nixpkgs.rev}.tar.gz?rev=${nixpkgs.rev}&revCount=1234", f"{locked_url=} != http://localhost/stable/${nixpkgs.rev}.tar.gz"
|
2023-06-07 12:26:30 +00:00
|
|
|
|
|
|
|
# Check that we got the rev and revCount attributes.
|
tests: add error messages to the asserts in tarball flakes test
In hopes of avoiding opaque error messages like the one in
https://buildbot.lix.systems/#/builders/49/builds/1054/steps/1/logs/stdio
Traceback (most recent call last):
File "/nix/store/wj6wh89jhd2492r781qsr09r9wydfs6m-nixos-test-driver-1.1/bin/.nixos-test-driver-wrapped", line 9, in <module>
sys.exit(main())
^^^^^^
File "/nix/store/wj6wh89jhd2492r781qsr09r9wydfs6m-nixos-test-driver-1.1/lib/python3.11/site-packages/test_driver/__init__.py", line 126, in main
driver.run_tests()
File "/nix/store/wj6wh89jhd2492r781qsr09r9wydfs6m-nixos-test-driver-1.1/lib/python3.11/site-packages/test_driver/driver.py", line 159, in run_tests
self.test_script()
File "/nix/store/wj6wh89jhd2492r781qsr09r9wydfs6m-nixos-test-driver-1.1/lib/python3.11/site-packages/test_driver/driver.py", line 151, in test_script
exec(self.tests, symbols, None)
File "<string>", line 13, in <module>
AssertionError
Change-Id: Idd2212a1c3714ce58c7c3a9f34c2ca4313eb6d55
2024-04-22 22:13:36 +00:00
|
|
|
revision = info["revision"]
|
|
|
|
rev_count = info["revCount"]
|
|
|
|
assert revision == "${nixpkgs.rev}", f"{revision=} != ${nixpkgs.rev}"
|
|
|
|
assert rev_count == 1234, f"{rev_count=} != 1234"
|
2023-06-07 12:26:30 +00:00
|
|
|
|
|
|
|
# Check that fetching with rev/revCount/narHash succeeds.
|
2024-05-29 22:22:25 +00:00
|
|
|
machine.succeed("nix flake metadata --json http://localhost/tags/latest.tar.gz?rev=" + revision)
|
|
|
|
machine.succeed("nix flake metadata --json http://localhost/tags/latest.tar.gz?revCount=" + str(rev_count))
|
|
|
|
machine.succeed("nix flake metadata --json http://localhost/tags/latest.tar.gz?narHash=" + info["locked"]["narHash"])
|
2023-06-07 12:26:30 +00:00
|
|
|
|
|
|
|
# Check that fetching fails if we provide incorrect attributes.
|
2024-05-29 22:22:25 +00:00
|
|
|
machine.fail("nix flake metadata --json http://localhost/tags/latest.tar.gz?rev=493300eb13ae6fb387fbd47bf54a85915acc31c0")
|
|
|
|
machine.fail("nix flake metadata --json http://localhost/tags/latest.tar.gz?revCount=789")
|
|
|
|
machine.fail("nix flake metadata --json http://localhost/tags/latest.tar.gz?narHash=sha256-tbudgBSg+bHWHiHnlteNzN8TUvI80ygS9IULh4rklEw=")
|
2023-06-07 12:26:30 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
}
|