Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ct/tasks.nix: revert migration hack, invoke lib/tests/release.nix from single CT entry point #271819

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
# EditorConfig
/.editorconfig @Mic92 @zowoq

# single entry point for Continuous Testing (CT) runners (ofborg, github, etc)
/ct @infinisil @amjoseph-nixpkgs

# Libraries
/lib @infinisil
/lib/systems @alyssais @ericson2314 @amjoseph-nixpkgs
Expand Down
28 changes: 28 additions & 0 deletions ct/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env nix-shell
#!nix-shell -I nixpkgs=. ./. --pure --run true

#
# This file is the single entry point for all CT (Continuous
# Testing) in nixpkgs. CT is defined to be those checks which
# should be run upon every set of commits before they are merged.
#
# Neither this file nor anything else in the ./ct directory are
# stable interfaces of nixpkgs. If you depend on anything other
# than the exit code returned by `./ct/default.nix` you need to be
# prepared to respond to and deal with breakage.
#
# All CT runners (ofborg, gerrit, github actions, etc, etc) should
# be configured to invoke this file, which should in turn perform
# the requested action. CT actions must be runnable locally,
# i.e. by an ordinary developer using a nixpkgs checkout. Please do
# not write forge-specific/ofborg-specific CT actions. If you need
# to pass arguments please use `--arg`; we clear the environment
# with `--pure`.
#

{ ...
}@args:

import ./tasks.nix args


72 changes: 72 additions & 0 deletions ct/tasks.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#
# This derivation builds a Makefile, which is then passed to gmake
# in order to perform the necessary CT tasks, with correct
# dependency ordering and as much parallelism as possible.
#
# A Makefile is used solely because we need access to the Nix store
# (which contains cached artifacts from previous CT runs) in order
# to get reasonable performance. Since recursive-nix is neither
# stable nor ready for use, a Makefile is the simple interim solution.
#
# The Makefile contains one big target which runs nix-build on
# several attributes. In general you should try to express your CT
# target by adding additional attributes to this list. Please add
# new Makefile targets or shellscript only as a last resort.
#

{ pkgs-path ? ../.
, shortRev ? builtins.substring 0 8 (lib.commitIdFromGitRepo ../.git)
, pkgs ? import pkgs-path {}
, lib ? pkgs.lib
}:

let

# Attrset where the attrname is the target name and the attrvalue
# becomes the lines to be used. No tab characters needed.
#
# These commands are executed "outside of" nix-build, so they have
# access to the shared store which will retain cached artifacts
# across CT runs.
#
targets = {
pkgs-test-release =''
${pkgs.nix}/bin/nix-build ./pkgs/test/release
'';

pkgs-test-release-release-attrpaths-superset =''
${pkgs.nix}/bin/nix-build ./pkgs/test/release/release-attrpaths-superset.nix -A pass
'';

libtests = ''
${pkgs.nix}/bin/nix-build ./lib/tests/release.nix
'';
};

in
pkgs.mkShell {
pname = "nixpkgs-ct";
version = shortRev;

passAsFile = [ "makefile" ];
makefile = ''
${lib.concatStrings
(lib.mapAttrsToList
(name: val:
''
.PHONY: ${name}
default: ${name}
${name}:
${lib.concatStringsSep "\n"
(map (line: if line=="" then "" else "\t${line}")
(lib.splitString "\n" val))}
'')
targets)}
'';

shellHook = ''
unset shellHook
set -eu -o pipefail
${pkgs.gnumake}/bin/make -k -j -f $makefilePath default
'';
}
74 changes: 74 additions & 0 deletions pkgs/test/release/release-attrpaths-superset.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#
# This derivation verifies that calculating the list of outpaths
# using the old slow ofborg outpaths.nix script produces exactly the
# same results as calculating them the new fast parallel way with
# the pkgs/top-level/release-outpaths-parallel.nix script.
#
# This check needs access to the shared/cached store on the CT
# runner, so it can't be executed via the migration mechanism. It
# has to wait for OfBorg to merge and deploy this PR:
#
# https://github.com/NixOS/ofborg/pull/660
#

{ lib ? import ../../../lib
, pkgs ? import ../../.. { }
}:
let

nixpkgs-source = lib.cleanSource ../../..;

attrpaths-calculated-the-ofborg-way-drv =
pkgs.runCommand "attrpaths-calculated-the-ofborg-way.txt" {} ''
cp -r ${nixpkgs-source} nixpkgs
mkdir fake-store
${pkgs.nix}/bin/nix-env --store ./fake-store \
-qaP \
--no-name \
--arg checkMeta false \
--argstr path $(pwd)/nixpkgs \
-f nixpkgs/pkgs/top-level/release-outpaths.nix \
| sed 's/\.[^.]*$//' \
| sort \
| uniq \
> $out
'';

# yes, IFD
attrpaths-calculated-the-ofborg-way =
lib.splitString "\n"
(builtins.readFile
(import attrpaths-calculated-the-ofborg-way-drv)
);

attrpaths-calculated-the-fast-way =
(import ../../../pkgs/top-level/release-attrpaths-superset.nix { })
.names;

attrset-with-every-ofborg-way-attr-set-to-true =
builtins.listToAttrs
(map (path: lib.nameValuePair path true)
attrpaths-calculated-the-ofborg-way);

attrset-with-every-fast-way-attr-set-to-false =
builtins.listToAttrs
(map (path: lib.nameValuePair path false)
attrpaths-calculated-the-fast-way);

attrset-should-have-no-true-attrvalues =
attrset-with-every-ofborg-way-attr-set-to-true
// attrset-with-every-fast-way-attr-set-to-false;

failures =
lib.filter
(v: v != null)
(lib.mapAttrsToList
(k: v: if v == true then k else null)
attrset-should-have-no-true-attrvalues);

in {
# should be []
inherit failures;

pass = assert failures == [];
}