cachix / install-nix-action

Installs Nix on GitHub Actions for the supported platforms: Linux and macOS.
Apache License 2.0
498 stars 78 forks source link

Nix is not usable on self-hosted runners #195

Closed jheidbrink closed 6 months ago

jheidbrink commented 10 months ago

We deploy self-hosted runners to EKS using the actions-runner-controller Helm chart. There is usually exactly one runner pod. When I initially tried install-nix-action, it worked without issues. After manually deleting the runner pod and waiting until a fresh pod is deployed, nix-install-action succeeds, but Nix is not usable.

The following workflow code

      - uses: cachix/install-nix-action@v22
      - name: Verify Nix installation
        run: nix-shell -p nix-info --run "nix-info -m"

leads to the following error (in the "Verify Nix installation" step):

Run nix-shell -p nix-info --run "nix-info -m"
  nix-shell -p nix-info --run "nix-info -m"
  shell: /usr/bin/bash -e {0}
error:
       … <borked>

         at «none»:0: (source not available)

       … while calling the 'import' builtin

         at «string»:1:18:

            1| {...}@args: with import <nixpkgs> args; (pkgs.runCommandCC or pkgs.runCommand) "shell" { buildInputs = [ (nix-info) ]; } ""
             |                  ^

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)

       at «none»:0: (source not available)
Error: Process completed with exit code 1.
jheidbrink commented 10 months ago

The one runner pod is persisted between workflow runs, not sure if this might be a problem.

jheidbrink commented 10 months ago

When spawning a shell in the runner I can run nix-info by doing the following:

git clone --depth 1 https://github.com/NixOS/nixpkgs
NIX_PATH="nixpkgs=$HOME/nixpkgs" $HOME/.nix-profile/bin/nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 5.10.186-179.751.amzn2.x86_64, Ubuntu, 20.04.6 LTS (Focal Fossa), nobuild`
 - multi-user?: `no`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.16.1`
 - nixpkgs: `/home/runner/nixpkgs`

edit: And this way I can also fix the workflow

domenkozar commented 10 months ago

It does not set NIX_PATH by default, so it must have been your self-hosted runner configuration that set it?

Either way, you should be able to pass nix_path input to address this.

jheidbrink commented 10 months ago

I have no clue how it has worked if the installation doesn't set NIX_PATH ;)

When adding

        with:
          nix_path: nixpkgs=channel:nixos-2305

I get

Run nix-shell -p nix-info --run "nix-info -m"

warning: Nix search path entry 'channel:nixos-2305' cannot be downloaded, ignoring

and then the same error as in my initial message.

sandydoo commented 8 months ago

@jheidbrink, aren't you missing a period in the channel version?

+ nix_path: nixpkgs=channel:nixos-23.05
- nix_path: nixpkgs=channel:nixos-2305