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

Using lib.makeDiskoTest in my own flake #881

Open
johnjameswhitman opened this issue Nov 15, 2024 · 1 comment
Open

Using lib.makeDiskoTest in my own flake #881

johnjameswhitman opened this issue Nov 15, 2024 · 1 comment
Labels
enhancement New feature or request question Not a bug or issue, but a question asking for help or information

Comments

@johnjameswhitman
Copy link

I'm working on cleaning up my NixOS configs, and am curious about running some of my own integration tests in CI. I'm also planning to use disko, so was thinking it might be nice to use lib.makeDiskoTest with my own layout instead of NixOS's runNixOSTest.

Using Disko's own flake checks as inspiration I've got something that's half-working by accessing disko.lib.makeDiskoTest directly within my flake; however, doing it this way requires running nix flake check with the --impure option, which doesn't seem ideal.

When I try to import lib like below (my flake is here: https://github.com/johnjameswhitman/kipos/pull/4/files#r1844406285), it fails with an error:

error: cannot coerce a set to a string: { config = «thunk»; create = «thunk»; createScript = «thunk»; createScriptNoDeps = «thunk»; deepMergeMap = «thunk»; defineHookVariables = «thunk»; deviceList = «thunk»; deviceNumbering = «thunk»; deviceType = «thunk»; disko = «thunk»; «34 attributes elided» }

    makeTest = import (pkgs.path + "/nixos/tests/make-test-python.nix");
    eval-config = import (pkgs.path + "/nixos/lib/eval-config.nix");
    lib = pkgs.lib;
    diskoLib = import disko.lib { inherit lib makeTest eval-config; };

Any idea why that might be?

@iFreilicht
Copy link
Contributor

iFreilicht commented Nov 19, 2024

You figured out a lot on your own already, props for that!

There's just two pieces missing:

error: cannot coerce a set to a string: { config = «thunk»; create = «thunk»; createScript = «thunk»; createScriptNoDeps = «thunk»; deepMergeMap = «thunk»; defineHookVariables = «thunk»; deviceList = «thunk»; deviceNumbering = «thunk»; deviceType = «thunk»; disko = «thunk»; «34 attributes elided» }

It's exactly as the error says: disko.lib is a set, not a string, but to import something you need to pass a string. You need to do something similar like with pkgs.path, except the disko flake doesn't have such an attribute. Instead, you can just append a string to the flake input itself. This will coerce the input into a string.

      diskoLib = import (disko + "/lib") { inherit lib makeTest eval-config; };

This alone will not be enough; if you now run nix build .#checks.x86_64-linux.silverAlt it will download another version of nixpkgs and then end with this:

       … while calling the 'findFile' builtin
         at /nix/store/2927l33kdrl0qwzcjks6mrhg7zp6zd2h-source/lib/tests.nix:48:24:
           47|       , extendModules ? null
           48|       , pkgs ? import <nixpkgs> { }
             |                        ^
           49|       , extraTestScript ? ""

       error: cannot look up '<nixpkgs>' in pure evaluation mode (use '--impure' to override)

You can fix this by changing the way you invoke makeTest:

silverAlt = diskoLib.testLib.makeDiskoTest ((import ./tests/silver.nix) // { inherit pkgs; });

Now it evaluates, though I didn't run the entire test.


This a bit awkward, but I'm not sure if it is fixable. We use pkgs ? import <nixpkgs> pretty extensively in many files, but maybe we could eliminate it in some cases? If someone wants to try, feel free :)

@iFreilicht iFreilicht added enhancement New feature or request question Not a bug or issue, but a question asking for help or information labels Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Not a bug or issue, but a question asking for help or information
Projects
None yet
Development

No branches or pull requests

2 participants