···11# Testers {#chap-testers}
22+23This chapter describes several testing builders which are available in the `testers` namespace.
3445## `hasPkgConfigModules` {#tester-hasPkgConfigModules}
···67<!-- Old anchor name so links still work -->
78[]{#tester-hasPkgConfigModule}
89Checks whether a package exposes a given list of `pkg-config` modules.
99-If the `moduleNames` argument is omitted, `hasPkgConfigModules` will
1010-use `meta.pkgConfigModules`.
1010+If the `moduleNames` argument is omitted, `hasPkgConfigModules` will use `meta.pkgConfigModules`.
1111+1212+:::{.example #ex-haspkgconfigmodules-defaultvalues}
11131212-Example:
1414+# Check that `pkg-config` modules are exposed using default values
13151416```nix
1517passthru.tests.pkg-config = testers.hasPkgConfigModules {
1618 package = finalAttrs.finalPackage;
1717- moduleNames = [ "libfoo" ];
1819};
2020+2121+meta.pkgConfigModules = [ "libfoo" ];
1922```
20232121-If the package in question has `meta.pkgConfigModules` set, it is even simpler:
2424+:::
2525+2626+:::{.example #ex-haspkgconfigmodules-explicitmodules}
2727+2828+# Check that `pkg-config` modules are exposed using explicit module names
22292330```nix
2431passthru.tests.pkg-config = testers.hasPkgConfigModules {
2532 package = finalAttrs.finalPackage;
3333+ moduleNames = [ "libfoo" ];
2634};
3535+```
27362828-meta.pkgConfigModules = [ "libfoo" ];
2929-```
3737+:::
30383139## `testVersion` {#tester-testVersion}
3240···8391 - Move `$out` to `$out/result`, if it exists (assuming `out` is the default output)
8492 - Save the build log to `$out/testBuildFailure.log` (same)
85938686-Example:
9494+While `testBuildFailure` is designed to keep changes to the original builder's environment to a minimum, some small changes are inevitable:
9595+9696+ - The file `$TMPDIR/testBuildFailure.log` is present. It should not be deleted.
9797+ - `stdout` and `stderr` are a pipe instead of a tty. This could be improved.
9898+ - One or two extra processes are present in the sandbox during the original builder's execution.
9999+ - The derivation and output hashes are different, but not unusual.
100100+ - The derivation includes a dependency on `buildPackages.bash` and `expect-failure.sh`, which is built to include a transitive dependency on `buildPackages.coreutils` and possibly more.
101101+ These are not added to `PATH` or any other environment variable, so they should be hard to observe.
102102+103103+:::{.example #ex-testBuildFailure-showingenvironmentchanges}
104104+105105+# Check that a build fails, and verify the changes made during build
8710688107```nix
89108runCommand "example" {
···100119'';
101120```
102121103103-While `testBuildFailure` is designed to keep changes to the original builder's
104104-environment to a minimum, some small changes are inevitable.
105105-106106- - The file `$TMPDIR/testBuildFailure.log` is present. It should not be deleted.
107107- - `stdout` and `stderr` are a pipe instead of a tty. This could be improved.
108108- - One or two extra processes are present in the sandbox during the original
109109- builder's execution.
110110- - The derivation and output hashes are different, but not unusual.
111111- - The derivation includes a dependency on `buildPackages.bash` and
112112- `expect-failure.sh`, which is built to include a transitive dependency on
113113- `buildPackages.coreutils` and possibly more. These are not added to `PATH`
114114- or any other environment variable, so they should be hard to observe.
122122+:::
115123116124## `testEqualContents` {#tester-equalContents}
117125118126Check that two paths have the same contents.
119127120120-Example:
128128+:::{.example #ex-testEqualContents-toyexample}
129129+130130+# Check that two paths have the same contents
121131122132```nix
123133testers.testEqualContents {
···137147}
138148```
139149150150+:::
151151+140152## `testEqualDerivation` {#tester-testEqualDerivation}
141153142154Checks that two packages produce the exact same build instructions.
143155144144-This can be used to make sure that a certain difference of configuration,
145145-such as the presence of an overlay does not cause a cache miss.
156156+This can be used to make sure that a certain difference of configuration, such as the presence of an overlay does not cause a cache miss.
146157147158When the derivations are equal, the return value is an empty file.
148159Otherwise, the build log explains the difference via `nix-diff`.
149160150150-Example:
161161+:::{.example #ex-testEqualDerivation-hello}
162162+163163+# Check that two packages produce the same derivation
151164152165```nix
153166testers.testEqualDerivation
···156169 (hello.overrideAttrs(o: { doCheck = true; }))
157170```
158171172172+:::
173173+159174## `invalidateFetcherByDrvHash` {#tester-invalidateFetcherByDrvHash}
160175161176Use the derivation hash to invalidate the output via name, for testing.
162177163178Type: `(a@{ name, ... } -> Derivation) -> a -> Derivation`
164179165165-Normally, fixed output derivations can and should be cached by their output
166166-hash only, but for testing we want to re-fetch everytime the fetcher changes.
180180+Normally, fixed output derivations can and should be cached by their output hash only, but for testing we want to re-fetch everytime the fetcher changes.
181181+182182+Changes to the fetcher become apparent in the drvPath, which is a hash of how to fetch, rather than a fixed store path.
183183+By inserting this hash into the name, we can make sure to re-run the fetcher every time the fetcher changes.
167184168168-Changes to the fetcher become apparent in the drvPath, which is a hash of
169169-how to fetch, rather than a fixed store path.
170170-By inserting this hash into the name, we can make sure to re-run the fetcher
171171-every time the fetcher changes.
185185+This relies on the assumption that Nix isn't clever enough to reuse its database of local store contents to optimize fetching.
172186173173-This relies on the assumption that Nix isn't clever enough to reuse its
174174-database of local store contents to optimize fetching.
187187+You might notice that the "salted" name derives from the normal invocation, not the final derivation.
188188+`invalidateFetcherByDrvHash` has to invoke the fetcher function twice:
189189+once to get a derivation hash, and again to produce the final fixed output derivation.
175190176176-You might notice that the "salted" name derives from the normal invocation,
177177-not the final derivation. `invalidateFetcherByDrvHash` has to invoke the fetcher
178178-function twice: once to get a derivation hash, and again to produce the final
179179-fixed output derivation.
191191+:::{.example #ex-invalidateFetcherByDrvHash-nix}
180192181181-Example:
193193+# Prevent nix from reusing the output of a fetcher
182194183195```nix
184196tests.fetchgit = testers.invalidateFetcherByDrvHash fetchgit {
···189201};
190202```
191203204204+:::
205205+192206## `runNixOSTest` {#tester-runNixOSTest}
193207194208A helper function that behaves exactly like the NixOS `runTest`, except it also assigns this Nixpkgs package set as the `pkgs` of the test and makes the `nixpkgs.*` options read-only.
195209196210If your test is part of the Nixpkgs repository, or if you need a more general entrypoint, see ["Calling a test" in the NixOS manual](https://nixos.org/manual/nixos/stable/index.html#sec-calling-nixos-tests).
197211198198-Example:
212212+:::{.example #ex-runNixOSTest-hello}
213213+214214+# Run a NixOS test using `runNixOSTest`
199215200216```nix
201217pkgs.testers.runNixOSTest ({ lib, ... }: {
···209225})
210226```
211227228228+:::
229229+212230## `nixosTest` {#tester-nixosTest}
213231214232Run a NixOS VM network test using this evaluation of Nixpkgs.
215233216234NOTE: This function is primarily for external use. NixOS itself uses `make-test-python.nix` directly. Packages defined in Nixpkgs [reuse NixOS tests via `nixosTests`, plural](#ssec-nixos-tests-linking).
217235218218-It is mostly equivalent to the function `import ./make-test-python.nix` from the
219219-[NixOS manual](https://nixos.org/nixos/manual/index.html#sec-nixos-tests),
220220-except that the current application of Nixpkgs (`pkgs`) will be used, instead of
221221-letting NixOS invoke Nixpkgs anew.
236236+It is mostly equivalent to the function `import ./make-test-python.nix` from the [NixOS manual](https://nixos.org/nixos/manual/index.html#sec-nixos-tests), except that the current application of Nixpkgs (`pkgs`) will be used, instead of letting NixOS invoke Nixpkgs anew.
222237223223-If a test machine needs to set NixOS options under `nixpkgs`, it must set only the
224224-`nixpkgs.pkgs` option.
238238+If a test machine needs to set NixOS options under `nixpkgs`, it must set only the `nixpkgs.pkgs` option.
225239226240### Parameter {#tester-nixosTest-parameter}
227241
+2
nixos/doc/manual/release-notes/rl-2405.section.md
···41414242- `k9s` was updated to v0.29. There have been breaking changes in the config file format, check out the [changelog](https://github.com/derailed/k9s/releases/tag/v0.29.0) for details.
43434444+- `nitter` requires a `guest_accounts.jsonl` to be provided as a path or loaded into the default location at `/var/lib/nitter/guest_accounts.jsonl`. See [Guest Account Branch Deployment](https://github.com/zedeus/nitter/wiki/Guest-Account-Branch-Deployment) for details.
4545+4446- Invidious has changed its default database username from `kemal` to `invidious`. Setups involving an externally provisioned database (i.e. `services.invidious.database.createLocally == false`) should adjust their configuration accordingly. The old `kemal` user will not be removed automatically even when the database is provisioned automatically.(https://github.com/NixOS/nixpkgs/pull/265857)
45474648- `mkosi` was updated to v19. Parts of the user interface have changed. Consult the
···2626 };
2727 };
28282929- defaultSwayPackage = pkgs.sway.override {
3030- extraSessionCommands = cfg.extraSessionCommands;
3131- extraOptions = cfg.extraOptions;
3232- withBaseWrapper = cfg.wrapperFeatures.base;
3333- withGtkWrapper = cfg.wrapperFeatures.gtk;
3434- isNixOS = true;
3535- };
2929+ genFinalPackage = pkg:
3030+ let
3131+ expectedArgs = lib.naturalSort [
3232+ "extraSessionCommands"
3333+ "extraOptions"
3434+ "withBaseWrapper"
3535+ "withGtkWrapper"
3636+ "isNixOS"
3737+ ];
3838+ existedArgs = with lib;
3939+ naturalSort
4040+ (intersectLists expectedArgs (attrNames (functionArgs pkg.override)));
4141+ in if existedArgs != expectedArgs then
4242+ pkg
4343+ else
4444+ pkg.override {
4545+ extraSessionCommands = cfg.extraSessionCommands;
4646+ extraOptions = cfg.extraOptions;
4747+ withBaseWrapper = cfg.wrapperFeatures.base;
4848+ withGtkWrapper = cfg.wrapperFeatures.gtk;
4949+ isNixOS = true;
5050+ };
3651in {
3752 options.programs.sway = {
3853 enable = mkEnableOption (lib.mdDoc ''
···44594560 package = mkOption {
4661 type = with types; nullOr package;
4747- default = defaultSwayPackage;
6262+ default = pkgs.sway;
6363+ apply = p: if p == null then null else genFinalPackage p;
4864 defaultText = literalExpression "pkgs.sway";
4965 description = lib.mdDoc ''
5050- Sway package to use. Will override the options
5151- 'wrapperFeatures', 'extraSessionCommands', and 'extraOptions'.
5252- Set to `null` to not add any Sway package to your
5353- path. This should be done if you want to use the Home Manager Sway
5454- module to install Sway.
6666+ Sway package to use. If the package does not contain the override arguments
6767+ `extraSessionCommands`, `extraOptions`, `withBaseWrapper`, `withGtkWrapper`,
6868+ `isNixOS`, then the module options {option}`wrapperFeatures`,
6969+ {option}`wrapperFeatures` and {option}`wrapperFeatures` will have no effect.
7070+ Set to `null` to not add any Sway package to your path. This should be done if
7171+ you want to use the Home Manager Sway module to install Sway.
5572 '';
5673 };
5774
···304304 '';
305305 };
306306307307+ guestAccounts = mkOption {
308308+ type = types.path;
309309+ default = "/var/lib/nitter/guest_accounts.jsonl";
310310+ description = lib.mdDoc ''
311311+ Path to the guest accounts file.
312312+313313+ This file contains a list of guest accounts that can be used to
314314+ access the instance without logging in. The file is in JSONL format,
315315+ where each line is a JSON object with the following fields:
316316+317317+ {"oauth_token":"some_token","oauth_token_secret":"some_secret_key"}
318318+319319+ See https://github.com/zedeus/nitter/wiki/Guest-Account-Branch-Deployment
320320+ for more information on guest accounts and how to generate them.
321321+ '';
322322+ };
323323+307324 redisCreateLocally = mkOption {
308325 type = types.bool;
309326 default = true;
···333350 after = [ "network-online.target" ];
334351 serviceConfig = {
335352 DynamicUser = true;
353353+ LoadCredential="guestAccountsFile:${cfg.guestAccounts}";
336354 StateDirectory = "nitter";
337337- Environment = [ "NITTER_CONF_FILE=/var/lib/nitter/nitter.conf" ];
355355+ Environment = [
356356+ "NITTER_CONF_FILE=/var/lib/nitter/nitter.conf"
357357+ "NITTER_ACCOUNTS_FILE=%d/guestAccountsFile"
358358+ ];
338359 # Some parts of Nitter expect `public` folder in working directory,
339360 # see https://github.com/zedeus/nitter/issues/414
340361 WorkingDirectory = "${cfg.package}/share/nitter";
···11import ./make-test-python.nix ({ pkgs, ... }:
2233+let
44+ # In a real deployment this should naturally not common from the nix store
55+ # and be seeded via agenix or as a non-nix managed file.
66+ #
77+ # These credentials are from the nitter wiki and are expired. We must provide
88+ # credentials in the correct format, otherwise nitter fails to start. They
99+ # must not be valid, as unauthorized errors are handled gracefully.
1010+ guestAccountFile = pkgs.writeText "guest_accounts.jsonl" ''
1111+ {"oauth_token":"1719213587296620928-BsXY2RIJEw7fjxoNwbBemgjJhueK0m","oauth_token_secret":"N0WB0xhL4ng6WTN44aZO82SUJjz7ssI3hHez2CUhTiYqy"}
1212+ '';
1313+in
314{
415 name = "nitter";
516 meta.maintainers = with pkgs.lib.maintainers; [ erdnaxe ];
617718 nodes.machine = {
88- services.nitter.enable = true;
99- # Test CAP_NET_BIND_SERVICE
1010- services.nitter.server.port = 80;
1919+ services.nitter = {
2020+ enable = true;
2121+ # Test CAP_NET_BIND_SERVICE
2222+ server.port = 80;
2323+ # Provide dummy guest accounts
2424+ guestAccounts = guestAccountFile;
2525+ };
1126 };
12271328 testScript = ''
···22, buildPythonPackage
33, fetchPypi
44, protobuf
55-, setuptools-scm
66-, pythonRelaxDepsHook
75, pytestCheckHook
66+, pythonOlder
77+, pythonRelaxDepsHook
88+, setuptools-scm
89, uharfbuzz
910, youseedee
1011}:
11121213buildPythonPackage rec {
1314 pname = "gflanguages";
1414- version = "0.5.10";
1515+ version = "0.5.13";
1516 format = "setuptools";
16171818+ disabled = pythonOlder "3.7";
1919+1720 src = fetchPypi {
1821 inherit pname version;
1919- hash = "sha256-JVeI7TlJjbKCa+gGmjylbNiEhX3qmpbLXiH3VpFqgXc=";
2222+ hash = "sha256-LoppJHzX0dOpHnwMCyS1ACdIO4cqwb370ksvsXDFHzQ=";
2023 };
21242222- propagatedBuildInputs = [
2323- protobuf
2525+ # Relax the dependency on protobuf 3. Other packages in the Google Fonts
2626+ # ecosystem have begun upgrading from protobuf 3 to protobuf 4,
2727+ # so we need to use protobuf 4 here as well to avoid a conflict
2828+ # in the closure of fontbakery. It seems to be compatible enough.
2929+ pythonRelaxDeps = [
3030+ "protobuf"
2431 ];
3232+2533 nativeBuildInputs = [
2634 setuptools-scm
2735 ];
28362929- doCheck = true;
3737+ propagatedBuildInputs = [
3838+ protobuf
3939+ ];
4040+3041 nativeCheckInputs = [
3142 pythonRelaxDepsHook
3243 pytestCheckHook
···3445 youseedee
3546 ];
36473737- # Relax the dependency on protobuf 3. Other packages in the Google Fonts
3838- # ecosystem have begun upgrading from protobuf 3 to protobuf 4,
3939- # so we need to use protobuf 4 here as well to avoid a conflict
4040- # in the closure of fontbakery. It seems to be compatible enough.
4141- pythonRelaxDeps = [ "protobuf" ];
4242-4348 meta = with lib; {
4449 description = "Python library for Google Fonts language metadata";
4550 homepage = "https://github.com/googlefonts/lang";
5151+ changelog = "https://github.com/googlefonts/lang/releases/tag/v${version}";
4652 license = licenses.asl20;
4753 maintainers = with maintainers; [ danc86 ];
4854 };