[GH-ISSUE #696] Please add documentation on using nix in an action #442

Closed
opened 2026-03-01 21:43:26 +03:00 by kerem · 10 comments
Owner

Originally created by @dsyer on GitHub (May 21, 2021).
Original GitHub issue: https://github.com/nektos/act/issues/696

It's really great that the nix package for act is up to date, and that the README has instructions about how to install it. It is surprising therefore that you can't use it to run an action with cachix/install-nix-action (cf #559). The fact that the README tells me how to use nix makes me think there might be a way to do it, but I can't figure it out on my own.

Originally created by @dsyer on GitHub (May 21, 2021). Original GitHub issue: https://github.com/nektos/act/issues/696 It's really great that the nix package for act is up to date, and that the README has instructions about how to install it. It is surprising therefore that you can't use it to run an action with `cachix/install-nix-action` (cf #559). The fact that the README tells me how to use nix makes me think there might be a way to do it, but I can't figure it out on my own.
kerem 2026-03-01 21:43:26 +03:00
Author
Owner

@catthehacker commented on GitHub (May 21, 2021):

Docker containers are much different than OS running on your host so it's not possible to replicate behaviour 1:1. I've not used nix or NixOS so I don't know much about them.

<!-- gh-comment-id:845954717 --> @catthehacker commented on GitHub (May 21, 2021): Docker containers are much different than OS running on your host so it's not possible to replicate behaviour 1:1. I've not used `nix` or NixOS so I don't know much about them.
Author
Owner

@dsyer commented on GitHub (May 21, 2021):

It's hard to figure out who maintains the nix part of act then (the package and the docs). Is it @ryantm (or is that you anyway)? If someone cares enough to want to create that package they probably understand nix enough to figure this one out.

<!-- gh-comment-id:845965457 --> @dsyer commented on GitHub (May 21, 2021): It's hard to figure out who maintains the nix part of `act` then (the package and the docs). Is it @ryantm (or is that you anyway)? If someone cares enough to want to create that package they probably understand nix enough to figure this one out.
Author
Owner

@catthehacker commented on GitHub (May 21, 2021):

The package of act for Nix is totally different thing comparing to have nix working in act (Docker container)

<!-- gh-comment-id:845966315 --> @catthehacker commented on GitHub (May 21, 2021): The package of `act` for Nix is totally different thing comparing to have `nix` working in `act` (Docker container)
Author
Owner

@catthehacker commented on GitHub (May 21, 2021):

As I've mentioned in #559 it is currently not possible to run nix action in act due to the way that action works and how act works.
act currently doesn't work well with non-root account due to the way how Docker works and it's long road before it's going to be fixed.
nix action doesn't work with root account.

<!-- gh-comment-id:845967094 --> @catthehacker commented on GitHub (May 21, 2021): As I've mentioned in #559 it is currently not possible to run `nix` action in `act` due to the way that action works and how `act` works. `act` currently doesn't work well with non-root account due to the way how Docker works and it's long road before it's going to be fixed. `nix` action doesn't work with root account.
Author
Owner

@ryantm commented on GitHub (May 21, 2021):

Plenty of nix commands work on top of act but maybe not the installer.

<!-- gh-comment-id:845968912 --> @ryantm commented on GitHub (May 21, 2021): Plenty of nix commands work on top of act but maybe not the installer.
Author
Owner

@dsyer commented on GitHub (May 21, 2021):

I'm not sure I understand, and it will be hard work to educate me, so forget about it unless you are feeling kind. I can create a docker image like this:

FROM catthehacker/ubuntu:act-latest

RUN addgroup --system nixbld && \
  adduser --home /home/nix --disabled-password --gecos "" --shell /bin/bash nix && \
  adduser nix nixbld && \
  mkdir -m 0755 /nix && chown nix /nix && \
  mkdir -p /etc/nix && echo 'sandbox = false' > /etc/nix/nix.conf

CMD /bin/bash -l
USER nix
ENV USER nix
WORKDIR /home/nix

and then run it and install nix (RUN curl -L https://nixos.org/nix/install | sh). So it works in a container if you set up the right base. Can we not somehow persuade act with cachix to do the same thing?

<!-- gh-comment-id:845980229 --> @dsyer commented on GitHub (May 21, 2021): I'm not sure I understand, and it will be hard work to educate me, so forget about it unless you are feeling kind. I can create a docker image like this: ``` FROM catthehacker/ubuntu:act-latest RUN addgroup --system nixbld && \ adduser --home /home/nix --disabled-password --gecos "" --shell /bin/bash nix && \ adduser nix nixbld && \ mkdir -m 0755 /nix && chown nix /nix && \ mkdir -p /etc/nix && echo 'sandbox = false' > /etc/nix/nix.conf CMD /bin/bash -l USER nix ENV USER nix WORKDIR /home/nix ``` and then run it and install nix (`RUN curl -L https://nixos.org/nix/install | sh`). So it works in a container if you set up the right base. Can we not somehow persuade `act` with `cachix` to do the same thing?
Author
Owner

@dsyer commented on GitHub (May 21, 2021):

I can also do this and then I think the cachix action is running successfully:

FROM catthehacker/ubuntu:act-latest

RUN mkdir -p /etc/nix && echo "build-users-group =" > /etc/nix/nix.conf && \
  curl -L https://nixos.org/nix/install | sh

But when I try to use nix in a workflow step it crashes with error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I). So it feels like I blundered into something that nearly works, but since I don't really know how I got here it's going to be hard to get any further on my own.

<!-- gh-comment-id:845989416 --> @dsyer commented on GitHub (May 21, 2021): I can also do this and then I think the cachix action is running successfully: ``` FROM catthehacker/ubuntu:act-latest RUN mkdir -p /etc/nix && echo "build-users-group =" > /etc/nix/nix.conf && \ curl -L https://nixos.org/nix/install | sh ``` But when I try to use nix in a workflow step it crashes with `error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)`. So it feels like I blundered into something that nearly works, but since I don't really know how I got here it's going to be hard to get any further on my own.
Author
Owner

@catthehacker commented on GitHub (May 21, 2021):

Can we not somehow persuade act with cachix to do the same thing?

Well, no, because act is running everything as root currently and it has to be fixed first, either in act or cachix/install-nix/action has to support root installation.

<!-- gh-comment-id:845992099 --> @catthehacker commented on GitHub (May 21, 2021): > Can we not somehow persuade `act` with `cachix` to do the same thing? Well, no, because `act` is running everything as root currently and it has to be fixed first, either in `act` or `cachix/install-nix/action` has to support root installation.
Author
Owner

@dsyer commented on GitHub (May 25, 2021):

OK, so I have something that works. It it a hack? I don't know. Could we make it work more easily? Please advise. I wrote some notes here: https://github.com/scratches/act-demo.

The base image is this:

FROM catthehacker/ubuntu:act-latest

RUN mkdir -p /etc/nix && echo "build-users-group =" > /etc/nix/nix.conf && \
  curl -L https://nixos.org/nix/install | sh

ENV USER=root
CMD /bin/bash
ENTRYPOINT ["/bin/bash", "--login", "-c"]

Despite the entrypoint, act always runs the action using bash --noprofile ... (I think), so I also have to add . ~/.profile to my job step:

name: CI

on:
  push:
    branches:
    - '**'
    - '!dependabot/**'
  pull_request: {}

jobs:

  test:
    name: test
    runs-on: ubuntu-latest
    env:
      DOCKER_BUILDKIT: 1
    steps:
    - uses: actions/checkout@v2
    - uses: cachix/install-nix-action@v13
      with:
        nix_path: nixpkgs=channel:nixos-unstable
    - name: Setup env
      run: |
        . ~/.profile
        nix-env -i -f default.nix
        docker ps
      shell: bash

Then I run act as normal, but using the custom base image built from the Dockerfile above (in -P).

<!-- gh-comment-id:847843934 --> @dsyer commented on GitHub (May 25, 2021): OK, so I have something that works. It it a hack? I don't know. Could we make it work more easily? Please advise. I wrote some notes here: https://github.com/scratches/act-demo. The base image is this: ``` FROM catthehacker/ubuntu:act-latest RUN mkdir -p /etc/nix && echo "build-users-group =" > /etc/nix/nix.conf && \ curl -L https://nixos.org/nix/install | sh ENV USER=root CMD /bin/bash ENTRYPOINT ["/bin/bash", "--login", "-c"] ``` Despite the entrypoint, `act` always runs the action using `bash --noprofile ...` (I think), so I also have to add `. ~/.profile` to my job step: ``` name: CI on: push: branches: - '**' - '!dependabot/**' pull_request: {} jobs: test: name: test runs-on: ubuntu-latest env: DOCKER_BUILDKIT: 1 steps: - uses: actions/checkout@v2 - uses: cachix/install-nix-action@v13 with: nix_path: nixpkgs=channel:nixos-unstable - name: Setup env run: | . ~/.profile nix-env -i -f default.nix docker ps shell: bash ``` Then I run `act` as normal, but using the custom base image built from the `Dockerfile` above (in `-P`).
Author
Owner

@github-actions[bot] commented on GitHub (Jun 25, 2021):

Issue is stale and will be closed in 14 days unless there is new activity

<!-- gh-comment-id:868096916 --> @github-actions[bot] commented on GitHub (Jun 25, 2021): Issue is stale and will be closed in 14 days unless there is new activity
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/act#442
No description provided.