2024-06-03 18:00:48 +03:00
{ lib , nixpkgs , nixpkgsFor , self }:
2023-10-06 17:53:01 +03:00
let
nixos-lib = import ( nixpkgs + " / n i x o s / l i b " ) { } ;
2024-08-15 00:19:22 +03:00
noTests = pkg : pkg . overrideAttrs (
finalAttrs : prevAttrs : {
doCheck = false ;
doInstallCheck = false ;
} ) ;
2023-10-06 17:53:01 +03:00
# https://nixos.org/manual/nixos/unstable/index.html#sec-calling-nixos-tests
2023-12-29 10:15:16 +02:00
runNixOSTestFor = system : test :
( nixos-lib . runTest {
2024-06-16 17:40:20 +03:00
imports = [
test
] ;
2023-12-29 10:15:16 +02:00
hostPkgs = nixpkgsFor . ${ system } . native ;
defaults = {
nixpkgs . pkgs = nixpkgsFor . ${ system } . native ;
nix . checkAllErrors = false ;
2024-11-04 00:10:34 +02:00
# TODO: decide which packaging stage to use. `nix-cli` is efficient, but not the same as the user-facing `everything.nix` package (`default`). Perhaps a good compromise is `everything.nix` + `noTests` defined above?
nix . package = nixpkgsFor . ${ system } . native . nixComponents . nix-cli ;
2023-12-29 10:15:16 +02:00
} ;
_module . args . nixpkgs = nixpkgs ;
_module . args . system = system ;
} )
// {
# allow running tests against older nix versions via `nix eval --apply`
# Example:
# nix build "$(nix eval --raw --impure .#hydraJobs.tests.fetch-git --apply 't: (t.forNix "2.19.2").drvPath')^*"
forNix = nixVersion : runNixOSTestFor system {
imports = [ test ] ;
defaults . nixpkgs . overlays = [ ( curr : prev : {
2024-11-04 00:10:34 +02:00
nix = let
packages = ( builtins . getFlake " n i x / ${ nixVersion } " ) . packages . ${ system } ;
in packages . nix-cli or packages . nix ;
2023-12-29 10:15:16 +02:00
} ) ] ;
} ;
2023-10-06 17:53:01 +03:00
} ;
2024-01-22 19:34:52 +02:00
# Checks that a NixOS configuration does not contain any references to our
# locally defined Nix version.
checkOverrideNixVersion = { pkgs , lib , . . . }: {
# pkgs.nix: The new Nix in this repo
# We disallow it, to make sure we don't accidentally use it.
2024-06-03 17:42:11 +03:00
system . forbiddenDependenciesRegexes = [
( lib . strings . escapeRegex " n i x - ${ pkgs . nix . version } " )
] ;
2024-01-22 19:34:52 +02:00
} ;
2024-06-03 18:26:16 +03:00
otherNixes . nix_2_3 . setNixPackage = { lib , pkgs , . . . }: {
imports = [ checkOverrideNixVersion ] ;
nix . package = lib . mkForce pkgs . nixVersions . nix_2_3 ;
2024-01-22 19:34:52 +02:00
} ;
2024-06-03 18:26:16 +03:00
otherNixes . nix_2_13 . setNixPackage = { lib , pkgs , . . . }: {
imports = [ checkOverrideNixVersion ] ;
nix . package = lib . mkForce (
self . inputs . nixpkgs-23-11 . legacyPackages . ${ pkgs . stdenv . hostPlatform . system } . nixVersions . nix_2_13 . overrideAttrs ( o : {
meta = o . meta // { knownVulnerabilities = [ ] ; } ;
} )
) ;
} ;
2024-01-22 19:34:52 +02:00
2024-06-03 18:33:38 +03:00
otherNixes . nix_2_18 . setNixPackage = { lib , pkgs , . . . }: {
imports = [ checkOverrideNixVersion ] ;
nix . package = lib . mkForce pkgs . nixVersions . nix_2_18 ;
} ;
2024-06-03 18:26:16 +03:00
in
2024-01-22 19:34:52 +02:00
2024-06-03 18:26:16 +03:00
{
authorization = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./authorization.nix ;
2024-01-22 19:34:52 +02:00
2024-06-03 18:26:16 +03:00
remoteBuilds = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./remote-builds.nix ;
2024-01-22 19:34:52 +02:00
2023-10-31 18:32:09 +02:00
remoteBuildsSshNg = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./remote-builds-ssh-ng.nix ;
2024-06-03 18:26:16 +03:00
}
// lib . concatMapAttrs (
nixVersion : { setNixPackage , . . . }:
{
" r e m o t e B u i l d s _ r e m o t e _ ${ nixVersion } " = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " {
name = " r e m o t e B u i l d s _ r e m o t e _ ${ nixVersion } " ;
imports = [ ./remote-builds.nix ] ;
builders . config = { lib , pkgs , . . . }: {
imports = [ setNixPackage ] ;
} ;
2024-01-22 19:34:52 +02:00
} ;
2024-06-03 18:26:16 +03:00
" r e m o t e B u i l d s _ l o c a l _ ${ nixVersion } " = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " {
name = " r e m o t e B u i l d s _ l o c a l _ ${ nixVersion } " ;
imports = [ ./remote-builds.nix ] ;
nodes . client = { lib , pkgs , . . . }: {
imports = [ setNixPackage ] ;
} ;
2024-01-22 19:34:52 +02:00
} ;
2024-06-03 18:26:16 +03:00
" r e m o t e B u i l d s S s h N g _ r e m o t e _ ${ nixVersion } " = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " {
name = " r e m o t e B u i l d s S s h N g _ r e m o t e _ ${ nixVersion } " ;
imports = [ ./remote-builds-ssh-ng.nix ] ;
builders . config = { lib , pkgs , . . . }: {
imports = [ setNixPackage ] ;
} ;
2024-01-22 19:34:52 +02:00
} ;
2024-06-03 18:26:16 +03:00
# FIXME: these tests don't work yet
# "remoteBuildsSshNg_local_${nixVersion}" = runNixOSTestFor "x86_64-linux" {
# name = "remoteBuildsSshNg_local_${nixVersion}";
# imports = [ ./remote-builds-ssh-ng.nix ];
# nodes.client = { lib, pkgs, ... }: {
# imports = [ overridingModule ];
# };
# };
}
) otherNixes
// {
2024-01-22 19:34:52 +02:00
2023-10-06 17:53:01 +03:00
nix-copy-closure = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./nix-copy-closure.nix ;
nix-copy = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./nix-copy.nix ;
nssPreload = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./nss-preload.nix ;
githubFlakes = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./github-flakes.nix ;
2024-04-11 15:58:42 +03:00
gitSubmodules = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./git-submodules.nix ;
2023-10-06 17:53:01 +03:00
sourcehutFlakes = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./sourcehut-flakes.nix ;
tarballFlakes = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./tarball-flakes.nix ;
containers = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./containers/containers.nix ;
setuid = lib . genAttrs
2024-06-03 19:09:38 +03:00
[ " x 8 6 _ 6 4 - l i n u x " ]
2023-10-06 17:53:01 +03:00
( system : runNixOSTestFor system ./setuid.nix ) ;
2023-12-29 10:15:16 +02:00
fetch-git = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./fetch-git ;
2024-02-12 22:28:20 +02:00
ca-fd-leak = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./ca-fd-leak ;
2024-03-30 00:29:34 +02:00
gzip-content-encoding = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./gzip-content-encoding.nix ;
2024-04-08 15:51:54 +03:00
2024-06-16 13:13:07 +03:00
functional_user = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./functional/as-user.nix ;
functional_trusted = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./functional/as-trusted-user.nix ;
functional_root = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./functional/as-root.nix ;
2024-04-08 15:51:54 +03:00
user-sandboxing = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./user-sandboxing ;
2024-08-05 12:38:38 +03:00
s3-binary-cache-store = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./s3-binary-cache-store.nix ;
2024-08-22 16:34:19 +03:00
fsync = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./fsync.nix ;
2024-09-03 20:27:56 +03:00
cgroups = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./cgroups ;
2024-09-24 17:13:28 +03:00
fetchurl = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./fetchurl.nix ;
2024-10-22 23:23:16 +03:00
chrootStore = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./chroot-store.nix ;
2023-10-06 17:53:01 +03:00
}