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

actions-runner-controller: install-nix.sh: line 20: USER: unbound variable #122

Open
bbigras opened this issue Feb 16, 2022 · 14 comments · Fixed by #125
Open

actions-runner-controller: install-nix.sh: line 20: USER: unbound variable #122

bbigras opened this issue Feb 16, 2022 · 14 comments · Fixed by #125

Comments

@bbigras
Copy link

bbigras commented Feb 16, 2022

I'm trying to use install-nix action with https://github.com/actions-runner-controller/actions-runner-controller and I get:

/runner/_work/_actions/cachix/install-nix-action/v16/lib/install-nix.sh: line 20: USER: unbound variable
child_process.js:642
    throw err;
    ^

Error: Command failed: /runner/_work/_actions/cachix/install-nix-action/v16/lib/install-nix.sh
    at checkExecSyncError (child_process.js:621:11)
    at Object.execFileSync (child_process.js:639:15)
    at Object.<anonymous> (/runner/_work/_actions/cachix/install-nix-action/v16/lib/main.js:4:17)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
    at internal/main/run_main_module.js:17:11 {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 312,
  stdout: null,
  stderr: null
}

If I set USER to runner, I get permission error on /etc.
If I run sudo chmod 777 /etc, it fails when trying to mount /proc.

cc @hiroqn beacuse of #43 (comment)

@lovesegfault
Copy link
Contributor

Hit this today while trying to use Nix at work

@lovesegfault
Copy link
Contributor

Alright, I went down the rabbit hole on this and a number of things are involved in this failure.

Firstly, there's an issue where the default config of actions-runner-controller does not lend itself to having user sandboxing in it's RunnerDeployment. This is why they, by default, implement Docker support using a sidecar container. Maybe we could get the same thing to work by adding a sidecar that runs nix-daemon and bind-mounting /nix but that seemed like a lot of work.

The simple solution is to set the following in your RunnerDeployment:

spec:
  template:
    spec:
      image: "summerwind/actions-runner-dind"
      dockerdWithinRunnerContainer: true

This will avoid the installer failing due to the sandbox not being able to work.

Secondly, there's the issue of USER not being set. I'm not sure why it's like this, but you can work around this by adding it to the RunnerDeployment env:

spec:
  template:
    spec:
      env:
        - name: USER
          value: runner

Once the above are out of the way, we're still in trouble because the installation script here will trigger this bit of code:

else
# "fix" the following error when running nix*
# error: the group 'nixbld' specified in 'build-users-group' does not exist
add_config "build-users-group ="
mkdir -m 0755 /etc/nix
cp $workdir/nix.conf /etc/nix/nix.conf
fi

And L46 there is, I believe, wrong on two levels:

  1. It doesn't use -p, so if you manually create the folder it explodes
  2. It doesn't use sudo, so it can't mkdir in /etc

If you attempt to work around this by chmod'ing /etc you will break sudo.

Finally, you can avoid using this action altogether and just manually doing what it would (kind of):

jobs:
  test-nix:
    runs-on: [self-hosted, linux, x64]
    steps:
      - name: install nix
        run : |
          sh <(curl -L https://nixos.org/nix/install) --no-daemon --no-channel-add
          mkdir -p ~/.config/nix
          touch ~/.config/nix/nix.conf
          echo "max-jobs = auto" >> ~/.config/nix/nix.conf
          echo "cores = 0" >> ~/.config/nix/nix.conf
          echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
          echo "/nix/var/nix/profiles/per-user/$USER/profile/bin" >> "$GITHUB_PATH"
          echo "/nix/var/nix/profiles/default/bin" >> "$GITHUB_PATH"
          echo "NIX_PATH=nixpkgs=channel:nixos-unstable" >> "$GITHUB_ENV"
      - name: nix-hello
        run: nix run nixpkgs\#hello

@bbigras, can you try this out?

@lovesegfault
Copy link
Contributor

Oh, another thing, if you're running your cluster on GKE you need to force your node pool to use the ubuntu_containerd image; I couldn't get cos_containerdto work for some reason.

@grantbevis
Copy link

I'm still encountering this issue using cachix/install-nix-action@master with #125 merged

<snip>/_actions/cachix/install-nix-action/master/install-nix.sh: line 20: USER: unbound variable

Any ideas?

@domenkozar
Copy link
Member

Are you running those runners yourself?

@grantbevis
Copy link

Yeah I am, corporate restrictions means I need to self-host our runners. I do however have complete control over the runner image as it’s homebrewed.

I set the env: to have USER=runner like the other poster but it wasn’t happy still

@domenkozar
Copy link
Member

Did you see the post above from @lovesegfault how to set $USER correctly?

@grantbevis
Copy link

I'm still having issues @domenkozar but these are relating to my custom runner image in use. I will leave this for now and revisit when I have some time to resolve this.

@gthomson31
Copy link

Did this ever get a confirmed resolution? We are also seeing this problem with runners deployed via the actions runner controller

@domenkozar domenkozar reopened this Feb 13, 2023
@domenkozar
Copy link
Member

@gthomson31 could you post the full log and other specific things about your environment?

@gthomson31
Copy link

gthomson31 commented Feb 13, 2023

We are also using the Actions-Runner-Controller to manage the runners -
For the Runners we are building our own images built on top off

https://hub.docker.com/r/summerwind/actions-runner/tags

Have tested using images built from the following versions

Have not yet implemented the steps above mentioned to enabled dockerdWithinRunnerContainer fix but going to give these a try and will feedback

Dockerfile for Image

FROM summerwind/actions-runner:latest
<REDACTED INTERNAL ENVS>

USER root

<REDACTED INTERNAL SCRIPTS>
Hashistack installation , etc

USER runner

Error Message

Run cachix/install-nix-action@v19
Run /runner/_work/_actions/cachix/install-nix-action/v19/install-nix.sh
  /runner/_work/_actions/cachix/install-nix-action/v19/install-nix.sh
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    INPUT_EXTRA_NIX_CONFIG: 
    INPUT_GITHUB_ACCESS_TOKEN: 
    INPUT_INSTALL_OPTIONS: 
    INPUT_INSTALL_URL: 
    INPUT_NIX_PATH: 
    GITHUB_TOKEN: ***
Installing Nix
  /runner/_work/_actions/cachix/install-nix-action/v19/install-nix.sh: line 2[3](https://github.com/<redacted>/actions/runs/4162773921/jobs/7202357119#step:3:4): USER: unbound variable
  Error: Process completed with exit code 1.

@gthomson31
Copy link

Also tried to set the ENV variable as part of the workflow run which threw up a new error.

Workflow

name: Testing Nix
on: workflow_dispatch

env:
  USER: "runner"

jobs:
  example-job:
    # Custom Runner Label - base-x.x.x
    runs-on: base-1.0.0 
    steps:
      - uses: cachix/install-nix-action@v19

Error

Run cachix/install-nix-action@v19
  with:
  env:
    USER: runner
    
Run /runner/_work/_actions/cachix/install-nix-action/v19/install-nix.sh
Installing Nix
  installer options: --no-channel-add --darwin-use-unencrypted-nix-store-volume --nix-extra-conf-file /tmp/tmp.eTXGg50kNs/nix.conf
  *   Trying 34.141.28.239:443...
 <REDACTED TLS HANDSHAKE>
  * Connection #1 to host releases.nixos.org left intact
  downloading Nix 2.13.2 binary tarball for x86_64-linux from 'https://releases.nixos.org/nix/nix-2.13.2/nix-2.13.2-x86_64-linux.tar.xz' to '/tmp/nix-binary-tarball-unpack.8CoAyqmlNS'...
    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                   Dload  Upload   Total   Spent    Left  Speed
  
    0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
    0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  100 20.0M  100 20.0M    0     0  29.8M      0 --:--:-- --:--:-- --:--:-- 29.8M
  Note: a multi-user installation is possible. See https://nixos.org/manual/nix/stable/installation/installing-binary.html#multi-user-installation
  Warning: the flag --darwin-use-unencrypted-nix-store-volume
           is no longer needed and will be removed in the future.
  
  performing a single-user installation of Nix...
  directory /nix does not exist; creating it by running 'mkdir -m 0755 /nix && chown runner /nix' using sudo
  
  copying Nix to /nix/store...
  installing 'nix-2.13.2'
  error: mounting /proc: Operation not permitted
  (use '--show-trace' to show detailed location information)
  /tmp/nix-binary-tarball-unpack.8CoAyqmlNS/unpack/nix-2.13.2-x86_64-linux/install: unable to install Nix into your default profile
  Error: Process completed with exit code 1.

@domenkozar
Copy link
Member

Could you try this workaround: NixOS/nix#4107 (comment)

@gthomson31
Copy link

@domenkozar trying to get this to work but it is not allowing me to unmount the directory within the summerwind image.
Raising this with the project for support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants