cachix-action

repository·master·Indexed 43 days ago

https://github.com/cachix/cachix-action

A GitHub Action that integrates Nix with Cachix to provide binary caching in CI/CD workflows. It allows developers to pull from and push to Cachix binary caches to reduce build times, supporting both Daemon and Store Scan push modes. Version 1.0.0.

Tokens
1.7K
Snippets
3
Records
11
Agent score
6%

What's inside cachix-action

  1. Understand Cachix push modes: Daemon vs Store Scan

    master

    The action supports two modes for pushing store paths to the cache, controlled by the useDaemon option.

    Daemon mode (default)

    Registers a post-build hook with Nix. Newly built store paths are pushed as they are built. Limitation: Nix does not trigger the hook for substituted paths. Security Note: Post-build hooks may run as root if the nix-daemon is root. Evaluate risks if running untrusted code.

    Store scan mode

    Looks for differences in the store at the file system level. It captures all store paths, including those substituted. Warning: This is not safe for multi-user stores as you may inadvertently upload and leak store paths built by other users. Prefer daemon mode for multi-user stores.

  2. Understand Cachix push modes

    master

    The action determines how to upload paths to Cachix based on your configuration. The available modes are:

    • None: Pushing is disabled. Occurs if skipPush is true or if no authentication (authToken or signingKey) is provided.
    • PushPaths: Only the specific paths provided in the pathsToPush input are uploaded.
    • Daemon: The most efficient mode. It uses the Cachix Daemon to register a post-build hook with the Nix Daemon, allowing paths to be uploaded as they are built. Requires useDaemon: true, a cachix version $\ge$ 1.7.0, and a trusted user environment.
    • StoreScan: The fallback mode. It scans the Nix store during pre- and post-build hooks and uploads the differences. It is simple but less efficient and may not be safe in multi-user environments.
  3. Use the Cachix Daemon for efficient uploads

    master

    To enable the Cachix Daemon mode, set useDaemon: true. This mode requires:

    1. cachix version 1.7.0 or higher.
    2. A trusted user environment (the user must be able to set Nix post-build hooks, typically meaning they are a trusted-user in nix.conf or have write access to /nix/store).

    When enabled, the action spawns a background daemon process, sets up a Unix socket, and registers a post-build-hook via NIX_USER_CONF_FILES or NIX_CONF to ensure paths are pushed immediately upon build completion.

  4. Use cachix-action for read-only cache access

    master

    To use the action to pull (substitute) packages from a Cachix cache without pushing any new builds, provide the name of your cache. This is useful for CI jobs that only need to consume existing binaries.

    - uses: cachix/cachix-action@v17
      with:
        name: mycache
  5. Use cachix-action to write to a cache with an auth token

    master

    To push newly built packages to a Cachix cache, you must provide an authToken. This token is required for private cache access or to push to any cache.

    - uses: cachix/cachix-action@v17
      with:
        name: mycache
        authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
  6. Use cachix-action to write to a cache with an auth token and signing key

    master

    For self-signed caches, you must provide both the authToken and the signingKey. The signing key is used in addition to the auth token to sign store paths.

    - uses: cachix/cachix-action@v17
      with:
        name: mycache
        authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
        signingKey: "${{ secrets.CACHIX_SIGNING_KEY }}"
  7. Configure cachix-action inputs

    master

    The cachix-action is configured via GitHub Action inputs. Below are the available configuration options:

    InputTypeDescription
    namestring (required)The name of the Cachix cache to use.
    authTokenstringAuthentication token for writing to the cache.
    signingKeystringSigning key for managed signing. If provided, CACHIX_SIGNING_KEY is exported.
    skipPushbooleanIf true, prevents pushing to the cache.
    pathsToPushstringA space-separated list of specific Nix store paths to push.
    pushFilterstringA regex filter used to exclude paths from being pushed.
    cachixArgsstringAdditional arguments passed to the cachix command.
    extraPullNamesstringA comma-separated list of additional Cachix cache names to use.
    useDaemonbooleanWhether to use the Cachix Daemon for efficient uploads.
    skipAddingSubstituterbooleanIf true, the action will not add the Cachix cache to Nix substituters.
    cachixBinstringPath to a specific cachix executable. If empty, it searches PATH or installs it.
    installCommandstringCommand used to install cachix if not found. Defaults to nix-env --quiet -j8 -iA cachix -f https://cachix.org/api/v1/install.
  8. Configure advanced cachix-action options

    master

    Fine-grained control over the action's execution and the Cachix binary.

    InputDescriptionRequiredDefault
    skipAddingSubstituterSet to true to skip adding the cache as a Nix substituterfalse
    cachixArgsAdditional command-line arguments to pass to Cachix commands. Defaults to -j8 for parallel processing
    cachixBinCustom path to the Cachix binary if not using the default installation
    installCommandCustom command to install Cachix instead of the default installation method
  9. Configure Cachix cache settings

    master

    Use these options to define which caches to interact with.

    InputDescriptionRequiredDefault
    nameName of the Cachix cache to pull (substitute) from and optionally push to✓
    extraPullNamesComma-separated list of additional Cachix cache names to pull (substitute) from
  10. Configure Cachix push behavior

    master

    Control how and what is pushed to your Cachix cache.

    InputDescriptionRequiredDefault
    skipPushSet to true to only pull from the cache without pushing any build resultsfalse
    useDaemonUse Cachix daemon mode to push store paths as they're built via post-build hooks. See Push modes for more informationtrue
    pathsToPushWhitespace-separated list of specific store paths to push. Leave empty to push all build results
    pushFilterRegular expression to exclude derivations from being pushed, for example "(-source$ | nixpkgs\.tar\.gz$)". Ignored if pathsToPush is set. Warning: paths may still be pushed if they are part of another path's closure
  11. Configure Cachix authentication

    master

    Use these options to provide credentials for private caches or for pushing builds.

    InputDescriptionRequiredDefault
    authTokenAuthentication token for Cachix, required for private cache access or to push to any cache
    signingKeyPrivate signing key for self-signed caches, used in addition to the auth token to sign store paths