Skip to content

need to inherit (lots of?) inputs into nix-unit for it to work #224

@maxheld83

Description

@maxheld83

this flake does not work, without the highlighted diff:

{
  description = "Description for the project";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-parts = {
      inputs.nixpkgs-lib.follows = "nixpkgs";
      url = "github:hercules-ci/flake-parts";
    };
    flake-iter.url = "https://flakehub.com/f/DeterminateSystems/flake-iter/0.1.*";
    nix-unit = {
      url = "github:nix-community/nix-unit/?tag=v2.24.1";
      inputs = {
        flake-parts.follows = "flake-parts";
        nixpkgs.follows = "nixpkgs";
      };
    };
    treefmt-nix.url = "github:numtide/treefmt-nix";
  };

  outputs =
    inputs@{ flake-parts, ... }:
    flake-parts.lib.mkFlake { inherit inputs; } {
      imports = [
        inputs.nix-unit.modules.flake.default
        inputs.treefmt-nix.flakeModule
      ];
      systems = [
        "x86_64-linux"
        "aarch64-linux"
        "aarch64-darwin"
        "x86_64-darwin"
      ];
      perSystem =
        { 
          pkgs,
          inputs',
          self',
          ...
        }:
        {
          devShells.default = pkgs.mkShell {
            packages = [
              inputs'.flake-iter.packages.default
            ];
          };
          nix-unit = {
            inputs = {
              # NOTE: a `nixpkgs-lib` follows rule is currently required
-              inherit (inputs) nixpkgs flake-parts nix-unit;
+              inherit (inputs) nixpkgs flake-parts nix-unit treefmt-nix;
            };
            tests = {
              "test example" = {
                expr = "123";
                expected = "123";
              };
            };
          };
        };
    };
}

Without the diff, building this flake with nix run 'https://flakehub.com/f/DeterminateSystems/flake-iter/*' -- --verbose build fails with:

nix-unit-check>        error: Failed to open archive (Source threw exception: error: unable to download 'https://github.com/numtide/treefmt-nix/archive/3d0579f5cc93436052d94b73925b48973a104204.tar.gz': Could not resolve hostname (6))
error: builder for '/nix/store/4qf483k2qp20v2k4cc7mczl5j7dbjl2x-nix-unit-check.drv' failed with exit code 1;
       last 25 log lines:
       >          at «nix-internal»/call-flake.nix:79:20:
       >            78|           if node.flake or true then
       >            79|             assert builtins.isFunction flake.outputs;
       >              |                    ^
       >            80|             result
       >
       >        … while calling the 'import' builtin
       >          at «nix-internal»/call-flake.nix:54:19:
       >            53|
       >            54|           flake = import (outPath + "/flake.nix");
       >              |                   ^
       >            55|
       >
       >        … while realising the context of a path
       >
       >        … while calling the 'fetchTree' builtin
       >          at «nix-internal»/call-flake.nix:48:15:
       >            47|               # FIXME: remove obsolete node.info.
       >            48|               fetchTree (node.info or {} // removeAttrs node.locked ["dir"]);
       >              |               ^
       >            49|
       >
       >        … while fetching the input 'github:numtide/treefmt-nix/3d0579f5cc93436052d94b73925b48973a104204?narHash=sha256-mL1szCeIsjh6Khn3nH2cYtwO5YXG6gBiTw1A30iGeDU%3D'
       >
       >        error: Failed to open archive (Source threw exception: error: unable to download 'https://github.com/numtide/treefmt-nix/archive/3d0579f5cc93436052d94b73925b48973a104204.tar.gz': Could not resolve hostname (6))
       For full logs, run:
         nix log /nix/store/4qf483k2qp20v2k4cc7mczl5j7dbjl2x-nix-unit-check.drv
Error: 
   0: failed to build derivation

With the diff, it passes.

A full reproducible example is here: https://github.com/dataheld/reprex-nixunit

I kind of stumbled upon the solution, but I don't really know why this is required and I find the error message baffling.

I'd love to (at least) add the documentation to clarify this behavior, but for that, I'd first have to understand it.

Ps.: There is an additional, confusing wrinkle, which is that this problem only occurs on linux (ubuntu + detsys nix) GHA runners, not on macOS runners nor local macOS.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions