2024-06-03 15:00:48 +00:00
{ lib , nixpkgs , nixpkgsFor , self }:
2023-10-06 14:53:01 +00:00
let
nixos-lib = import ( nixpkgs + " / n i x o s / l i b " ) { } ;
2024-08-14 21:19:22 +00:00
noTests = pkg : pkg . overrideAttrs (
finalAttrs : prevAttrs : {
doCheck = false ;
doInstallCheck = false ;
} ) ;
2023-10-06 14:53:01 +00:00
# https://nixos.org/manual/nixos/unstable/index.html#sec-calling-nixos-tests
2023-12-29 08:15:16 +00:00
runNixOSTestFor = system : test :
( nixos-lib . runTest {
2024-06-16 14:40:20 +00:00
imports = [
test
] ;
2023-12-29 08:15:16 +00:00
hostPkgs = nixpkgsFor . ${ system } . native ;
defaults = {
nixpkgs . pkgs = nixpkgsFor . ${ system } . native ;
nix . checkAllErrors = false ;
2024-11-03 22:10:34 +00: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 08:15:16 +00: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-03 22:10:34 +00:00
nix = let
packages = ( builtins . getFlake " n i x / ${ nixVersion } " ) . packages . ${ system } ;
in packages . nix-cli or packages . nix ;
2023-12-29 08:15:16 +00:00
} ) ] ;
} ;
2023-10-06 14:53:01 +00:00
} ;
2024-01-22 17:34:52 +00: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 14:42:11 +00:00
system . forbiddenDependenciesRegexes = [
( lib . strings . escapeRegex " n i x - ${ pkgs . nix . version } " )
] ;
2024-01-22 17:34:52 +00:00
} ;
2024-06-03 15:26:16 +00:00
otherNixes . nix_2_3 . setNixPackage = { lib , pkgs , . . . }: {
imports = [ checkOverrideNixVersion ] ;
nix . package = lib . mkForce pkgs . nixVersions . nix_2_3 ;
2024-01-22 17:34:52 +00:00
} ;
2024-06-03 15:26:16 +00: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 17:34:52 +00:00
2024-06-03 15:33:38 +00:00
otherNixes . nix_2_18 . setNixPackage = { lib , pkgs , . . . }: {
imports = [ checkOverrideNixVersion ] ;
nix . package = lib . mkForce pkgs . nixVersions . nix_2_18 ;
} ;
2024-06-03 15:26:16 +00:00
in
2024-01-22 17:34:52 +00:00
2024-06-03 15:26:16 +00:00
{
authorization = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./authorization.nix ;
2024-01-22 17:34:52 +00:00
2024-06-03 15:26:16 +00:00
remoteBuilds = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./remote-builds.nix ;
2024-01-22 17:34:52 +00:00
2023-10-31 16:32:09 +00:00
remoteBuildsSshNg = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./remote-builds-ssh-ng.nix ;
2024-06-03 15:26:16 +00: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 17:34:52 +00:00
} ;
2024-06-03 15:26:16 +00: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 17:34:52 +00:00
} ;
2024-06-03 15:26:16 +00: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 17:34:52 +00:00
} ;
2024-06-03 15:26:16 +00: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 17:34:52 +00:00
2023-10-06 14:53:01 +00: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 ;
2024-11-10 21:31:02 +00:00
nix-docker = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./nix-docker.nix ;
2023-10-06 14:53:01 +00:00
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 12:58:42 +00:00
gitSubmodules = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./git-submodules.nix ;
2023-10-06 14:53:01 +00: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 16:09:38 +00:00
[ " x 8 6 _ 6 4 - l i n u x " ]
2023-10-06 14:53:01 +00:00
( system : runNixOSTestFor system ./setuid.nix ) ;
2023-12-29 08:15:16 +00:00
fetch-git = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./fetch-git ;
2024-02-12 20:28:20 +00:00
ca-fd-leak = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./ca-fd-leak ;
2024-03-29 22:29:34 +00:00
gzip-content-encoding = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./gzip-content-encoding.nix ;
2024-04-08 12:51:54 +00:00
2024-06-16 10:13:07 +00: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 12:51:54 +00:00
user-sandboxing = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./user-sandboxing ;
2024-08-05 09:38:38 +00:00
s3-binary-cache-store = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./s3-binary-cache-store.nix ;
2024-08-22 13:34:19 +00:00
fsync = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./fsync.nix ;
2024-09-03 17:27:56 +00:00
cgroups = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./cgroups ;
2024-09-24 14:13:28 +00:00
fetchurl = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./fetchurl.nix ;
2024-10-22 20:23:16 +00:00
chrootStore = runNixOSTestFor " x 8 6 _ 6 4 - l i n u x " ./chroot-store.nix ;
2023-10-06 14:53:01 +00:00
}