### Install Nix Source: https://docs.cachix.org/deploy/running-an-agent/darwin Installs Nix using the official installation script. Ensure to restart your terminal after installation for the environment to load. ```shell curl -L https://nixos.org/nix/install | sh ``` -------------------------------- ### Install Nix Source: https://docs.cachix.org/_sources/deploy/running-an-agent/home-manager.rst.txt Installs Nix with daemon support. Ensure to exit and restart your terminal after installation. ```shell sh <(curl -L https://nixos.org/nix/install) --daemon ``` -------------------------------- ### Start Cachix Agent Source: https://docs.cachix.org/deploy/running-an-agent/home-manager Starts the cachix deploy agent using a pre-generated token. Replace '...' with your actual agent token. ```sh CACHIX_AGENT_TOKEN=... cachix deploy agent myagent ``` -------------------------------- ### Install Cachix using Nix Source: https://docs.cachix.org/_sources/installation.rst.txt Use this command to install Cachix with Nix. Ensure Nix is installed first. ```bash $ nix-env -iA cachix -f https://cachix.org/api/v1/install ``` -------------------------------- ### Install Cachix Tool Source: https://docs.cachix.org/_sources/deploy/running-an-agent/home-manager.rst.txt Installs the Cachix tool using nix-shell. This command fetches and imports the Cachix installation. ```shell nix-shell -I cachix=https://cachix.org/api/v1/install -p '(import {}).cachix' ``` -------------------------------- ### Install Cachix Source: https://docs.cachix.org/_sources/deploy/running-an-agent/darwin.rst.txt Installs the Cachix command-line tool using Nix. Ensure Nix is in your environment's PATH. ```bash nix-env -iA cachix -f https://cachix.org/api/v1/install ``` -------------------------------- ### Install Cachix with nix-env Source: https://docs.cachix.org/installation Use this command to install the latest stable version of Cachix using nix-env. Ensure Nix is installed before running. ```bash $ nix-env -iA cachix -f https://cachix.org/api/v1/install ``` -------------------------------- ### Install Cachix using Nix Profile and Flakes Source: https://docs.cachix.org/_sources/installation.rst.txt Install Cachix using the Nix profile command with Flakes enabled. This method uses the nixpkgs#cachix input. ```bash $ nix profile install --accept-flake-config nixpkgs#cachix ``` -------------------------------- ### Install Nix Source: https://docs.cachix.org/_sources/deploy/running-an-agent/darwin.rst.txt Installs the Nix package manager on your system. This is a prerequisite for installing Cachix. ```bash curl -L https://nixos.org/nix/install | sh ``` -------------------------------- ### Start Cachix Agent Source: https://docs.cachix.org/deploy/running-an-agent/darwin Starts the Cachix agent with a provided token and agent name. The agent will appear in your workspace upon successful startup. Ensure you have a valid CACHIX_AGENT_TOKEN. ```shell sudo -H CACHIX_AGENT_TOKEN=... cachix deploy agent --bootstrap myagent ``` -------------------------------- ### Install Cachix Tool Source: https://docs.cachix.org/deploy/running-an-agent/home-manager Installs the cachix tool using nix-shell. This command fetches the latest version from the specified URL and makes the 'cachix' executable available. ```sh nix-shell -I cachix=https://cachix.org/api/v1/install -p '(import {}).cachix' ``` -------------------------------- ### Travis CI Configuration for Nix and Cachix Source: https://docs.cachix.org/_sources/continuous-integration-setup/travis-ci.rst.txt Configure your `.travis.yml` file to use Nix as the language, specify the Nix version, and set up Cachix for binary caching. This includes installing Cachix and using your cache. ```yaml language: nix nix: 2.3.7 sudo: false env: global: - CACHIX_CACHE=mycache install: - echo "trusted-users = $USER" | sudo tee -a /etc/nix/nix.conf - sudo systemctl restart nix-daemon - nix-env -iA nixpkgs.cachix - cachix use $CACHIX_CACHE script: - cachix watch-exec $CACHIX_NAME nix-build - cachix watch-exec $CACHIX_NAME -- nix-shell --run "echo nix-shell successfully entered" ``` -------------------------------- ### Install Cachix using Nixpkgs or NixOS Source: https://docs.cachix.org/_sources/installation.rst.txt When using pkgs.cachix, the latest stable version is installed. This is a common method for Nixpkgs and NixOS users. ```nix pkgs.cachix ``` -------------------------------- ### Install Cachix with Nix Flakes Source: https://docs.cachix.org/installation Install Cachix using Nix flakes with the nix profile command. This method is suitable for users managing their Nix environment with flakes. ```bash $ nix profile install --accept-flake-config nixpkgs#cachix ``` -------------------------------- ### Install Cachix Agent Source: https://docs.cachix.org/deploy/running-an-agent/darwin Installs the Cachix agent using nix-env. This command fetches the latest version from the official Cachix channel. ```shell nix-env -iA cachix -f https://cachix.org/api/v1/install ``` -------------------------------- ### Buildkite Pipeline Configuration for Cachix Source: https://docs.cachix.org/_sources/continuous-integration-setup/buildkite.rst.txt Configure your `.buildkite/pipeline.yml` to install Cachix, set up your cache, and use it for build commands. Ensure the `CACHIX_AUTH_TOKEN` is set as a Buildkite secret. ```yaml env: CACHE_NAME: mycache steps: - label: Set up Cachix commands: - nix-env -iA nixpkgs.cachix - cachix use $CACHE_NAME - wait - label: Build commands: - cachix watch-exec $CACHE_NAME nix-build - cachix watch-exec $CACHE_NAME -- nix-shell --run "echo nix-shell successfully entered" ``` -------------------------------- ### Instantiate and Push Derivation to Cachix Source: https://docs.cachix.org/_sources/faq.rst.txt Instantiate a Nix derivation and push it to Cachix, then retrieve it on another machine. This is useful for ensuring derivations are available. ```shell $ nix-instantiate default.nix | cachix push mycache $ nix-store -r /nix/store/hash.drv ``` -------------------------------- ### Deploy Simple Nix Profile to Agent Source: https://docs.cachix.org/deploy/deploying-to-agents A minimal specification to deploy a simple Nix profile, such as git, to an agent named 'myagent'. ```nix { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05"; flake-utils.url = "github:numtide/flake-utils"; cachix-deploy-flake.url = "github:cachix/cachix-deploy-flake"; }; outputs = { self, flake-utils, nixpkgs, cachix-deploy-flake }: flake-utils.lib.eachDefaultSystem ( system: { defaultPackage = let pkgs = import nixpkgs { inherit system; }; cachix-deploy-lib = cachix-deploy-flake.lib pkgs; in cachix-deploy-lib.spec { agents = { myagent = pkgs.git; }; }; } ); } ``` -------------------------------- ### Deploy Simple Nix Profile to Agent Source: https://docs.cachix.org/_sources/deploy/deploying-to-agents/index.rst.txt A basic Nix flake to deploy a simple Nix profile, such as the 'git' package, to an agent. ```nix { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05"; flake-utils.url = "github:numtide/flake-utils"; cachix-deploy-flake.url = "github:cachix/cachix-deploy-flake"; }; outputs = { self, flake-utils, nixpkgs, cachix-deploy-flake }: flake-utils.lib.eachDefaultSystem ( system: { defaultPackage = let pkgs = import nixpkgs { inherit system; }; cachix-deploy-lib = cachix-deploy-flake.lib pkgs; in cachix-deploy-lib.spec { agents = { myagent = pkgs.git; }; }; } ); } ``` -------------------------------- ### Activate Cachix Deployment Source: https://docs.cachix.org/_sources/deploy/deploying-to-agents/index.rst.txt Set up authentication tokens, build the machine specification, push binaries to a cache, and activate the deployment on the agent. Ensure you replace placeholder tokens with your actual cache and activation tokens. ```bash export CACHIX_ACTIVATE_TOKEN=ACTIVATE-TOKEN export CACHIX_AUTH_TOKEN=CACHE-TOKEN spec=$(nix build --print-out-paths) cachix push mycache $spec cachix deploy activate $spec ``` -------------------------------- ### Configure Cachix Agent NixOS Options Source: https://docs.cachix.org/_sources/deploy/running-an-agent/nixos.rst.txt Enable the Cachix agent service and set the hostname. The agent token should be placed in `/etc/cachix-agent.token`. ```nix services.cachix-agent.enable = true; # agent name is inferred from the hostname networking.hostName = "myhostname"; ``` -------------------------------- ### Deploy Simple Nix Profile to Agent Source: https://docs.cachix.org/deploy/deploying-to-agents/index.html This flake.nix deploys a simple Nix profile, specifically the git package, to the agent named 'myagent'. ```nix { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05"; flake-utils.url = "github:numtide/flake-utils"; cachix-deploy-flake.url = "github:cachix/cachix-deploy-flake"; }; outputs = { self, flake-utils, nixpkgs, cachix-deploy-flake }: flake-utils.lib.eachDefaultSystem ( system: { defaultPackage = let pkgs = import nixpkgs { inherit system; }; cachix-deploy-lib = cachix-deploy-flake.lib pkgs; in cachix-deploy-lib.spec { agents = { myagent = pkgs.git; }; }; } ); } ``` -------------------------------- ### Push Flake Runtime Closure Source: https://docs.cachix.org/_sources/pushing.rst.txt Pushes the runtime closure of the default package or a specified set of packages in a Flake to Cachix. The `--no-link` and `--print-out-paths` flags are used to get the store paths. ```shell $ nix build --no-link --print-out-paths \ | cachix push mycache ``` ```shell $ nix build --no-link --print-out-paths .#package-a .#package-b \ | cachix push mycache ``` -------------------------------- ### Import Cachix Cache from S3 Source: https://docs.cachix.org/importing-from-s3 Initiate the import process by specifying your cache name and the S3 bucket URI. Ensure the machine running this command has a fast network connection as data will be streamed. ```bash $ cachix import mycache s3://mybucket ``` -------------------------------- ### Deploy NixOS Configuration to Agent Source: https://docs.cachix.org/_sources/deploy/deploying-to-agents/index.rst.txt Use this Nix flake to deploy a NixOS configuration to a specified agent. Ensure the agent is running and accessible. ```nix { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05"; cachix-deploy-flake.url = "github:cachix/cachix-deploy-flake"; flake-utils.url = "github:numtide/flake-utils"; }; outputs = { self, nixpkgs, flake-utils, cachix-deploy-flake }: flake-utils.lib.eachDefaultSystem ( system: { defaultPackage = let pkgs = import nixpkgs { inherit system; }; cachix-deploy-lib = cachix-deploy-flake.lib pkgs; in cachix-deploy-lib.spec { agents = { myagent = cachix-deploy-lib.nixos { fileSystems."/" = { device = "/dev/disk/by-label/nixos"; }; boot.loader.grub.devices = [ "/dev/sda" ]; boot.loader.grub.enable = true; networking.hostName = "myagent"; }; }; }; } ); } ``` -------------------------------- ### Push Binaries to Cachix Cache Source: https://docs.cachix.org/_sources/getting-started.rst.txt Build a Nix project and push the resulting binaries to your specified Cachix cache. ```bash $ nix-build | cachix push mycache ``` -------------------------------- ### Check Binary Cache Entry Availability Source: https://docs.cachix.org/faq Verify if a specific store path exists in your binary cache by querying its `.narinfo` file. This helps diagnose why Nix might not be picking up pre-built artifacts. ```bash $ curl https://mycache.cachix.org/spznih45c56kfwygx8qyq1skd1rs4zv1.narinfo ``` -------------------------------- ### Deploy NixOS to Agent Source: https://docs.cachix.org/deploy/deploying-to-agents Use this specification to deploy NixOS to an agent. Ensure the agent is named 'myagent' and the file system is correctly configured. ```nix { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05"; cachix-deploy-flake.url = "github:cachix/cachix-deploy-flake"; flake-utils.url = "github:numtide/flake-utils"; }; outputs = { self, nixpkgs, flake-utils, cachix-deploy-flake }: flake-utils.lib.eachDefaultSystem ( system: { defaultPackage = let pkgs = import nixpkgs { inherit system; }; cachix-deploy-lib = cachix-deploy-flake.lib pkgs; in cachix-deploy-lib.spec { agents = { myagent = cachix-deploy-lib.nixos { fileSystems."/" = { device = "/dev/disk/by-label/nixos"; }; boot.loader.grub.devices = [ "/dev/sda" ]; boot.loader.grub.enable = true; networking.hostName = "myagent"; }; }; }; } ); } ``` -------------------------------- ### Deploy NixOS to Agent Source: https://docs.cachix.org/deploy/deploying-to-agents/index.html This flake.nix deploys NixOS to an agent. Ensure the agent is configured with the specified file system labels and boot loader settings. ```nix { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05"; cachix-deploy-flake.url = "github:cachix/cachix-deploy-flake"; flake-utils.url = "github:numtide/flake-utils"; }; outputs = { self, nixpkgs, flake-utils, cachix-deploy-flake }: flake-utils.lib.eachDefaultSystem ( system: { defaultPackage = let pkgs = import nixpkgs { inherit system; }; cachix-deploy-lib = cachix-deploy-flake.lib pkgs; in cachix-deploy-lib.spec { agents = { myagent = cachix-deploy-lib.nixos { fileSystems."/" = { device = "/dev/disk/by-label/nixos"; }; boot.loader.grub.devices = [ "/dev/sda" ]; boot.loader.grub.enable = true; networking.hostName = "myagent"; }; }; }; } ); } ``` -------------------------------- ### Expose Files with Artifacts Source: https://docs.cachix.org/pins Expose specific files from a pinned store path by using the `--artifact` option. Multiple artifacts can be specified when creating a new pin. ```bash $ cachix pin mycache v1.0 /nix/store/xxx-name-1.0 --artifact etc/nginx.conf --artifact bin/name ``` -------------------------------- ### Configure Nix to Use Cachix Cache Source: https://docs.cachix.org/_sources/getting-started.rst.txt Configure Nix to use your specified Cachix binary cache for faster builds. Ensure you have authenticated with `cachix authtoken` for private caches. ```bash $ cachix use mycache ``` -------------------------------- ### Watch and Push Newly Built Store Paths Source: https://docs.cachix.org/_sources/pushing.rst.txt Monitors the Nix store for newly built paths and automatically pushes them to the specified Cachix cache. This is useful for continuous integration or build systems. ```shell $ cachix watch-store mycache ``` -------------------------------- ### Configure Nix to Use a Binary Cache Source: https://docs.cachix.org/getting-started Invoke this command to configure Nix to use your specified binary cache. For private caches, ensure your authentication token is set via environment variable or `cachix authtoken`. ```bash $ cachix use mycache ``` -------------------------------- ### Compare Derivations with nix-diff Source: https://docs.cachix.org/_sources/faq.rst.txt Use `nix-diff` to compare two derivations and identify differences in their hashes. Ensure both derivations are locally available before running. ```shell $ nix-shell -p nix-diff --run "nix-diff drv1 drv" ``` -------------------------------- ### deploy.json Configuration Structure Source: https://docs.cachix.org/_sources/deploy/reference.rst.txt Defines the structure for deploy.json, specifying agents and optional rollback scripts for deployments. ```json { "agents": { "": "", ... }, "rollbackScript": { "": "", } } ``` -------------------------------- ### Deploy Home Manager Configuration to Agent Source: https://docs.cachix.org/_sources/deploy/deploying-to-agents/index.rst.txt This Nix flake deploys a standalone Home Manager configuration to an agent. It sets the username, home directory, and state version. ```nix { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05"; flake-utils.url = "github:numtide/flake-utils"; cachix-deploy-flake.url = "github:cachix/cachix-deploy-flake"; cachix-deploy-flake.inputs.home-manager.follows = "home-manager"; home-manager.url = "github:nix-community/home-manager"; home-manager.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = { self, flake-utils, home-manager, nixpkgs, cachix-deploy-flake }: flake-utils.lib.eachDefaultSystem ( system: { defaultPackage = let pkgs = nixpkgs.legacyPackages."${system}"; cachix-deploy-lib = cachix-deploy-flake.lib pkgs; in cachix-deploy-lib.spec { agents = { myagent = cachix-deploy-lib.homeManager ( } ( { pkgs, ... }: { home.username = "jdoe"; home.homeDirectory = "/home/jdoe"; home.stateVersion = "22.05"; ``` -------------------------------- ### Push Binaries to Cachix Source: https://docs.cachix.org/getting-started Build your Nix project and push the resulting binaries to your specified Cachix cache. This is commonly used after a successful build in a CI environment. ```bash $ nix-build | cachix push mycache ``` -------------------------------- ### Push Build and Runtime Dependencies to Cachix Source: https://docs.cachix.org/pushing This command pushes both build and runtime dependencies to your Cachix cache. It queries the Nix store for required paths, excludes derivations, and then pushes them. ```bash $ nix-store -qR --include-outputs $(nix-store -qd $(nix-build)) \ | grep -v '\.drv$' \ | cachix push mycache ``` -------------------------------- ### Generate Signing Keypair with Cachix Source: https://docs.cachix.org/getting-started Use this command to generate a local signing keypair for your cache. Ensure you back up the generated key as it's the only copy. This command requires your authentication token to be set. ```bash $ cachix authtoken $ cachix generate-keypair ``` -------------------------------- ### Create a Pin Source: https://docs.cachix.org/pins Use the `cachix pin` command to assign a persistent name to a store path in your cache. This protects the pinned path from garbage collection. ```bash $ cachix pin mycache v1.0 /nix/store/xxx-name-1.0 ``` -------------------------------- ### Configure AWS Credentials Source: https://docs.cachix.org/_sources/importing-from-s3.rst.txt Before importing, configure your AWS credentials using the AWS CLI. Follow the prompts to enter your Access Key ID, Secret Access Key, and default region. ```bash $ aws configure ``` -------------------------------- ### Deploy nix-darwin to Agent Source: https://docs.cachix.org/deploy/deploying-to-agents/index.html This flake.nix deploys nix-darwin to an agent. It enables the cachix-agent service and ensures Nix is up-to-date. ```nix { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05"; flake-utils.url = "github:numtide/flake-utils"; cachix-deploy-flake.url = "github:cachix/cachix-deploy-flake"; cachix-deploy-flake.inputs.darwin.follows = "darwin"; darwin.url = "github:LnL7/nix-darwin"; darwin.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = { self, flake-utils, darwin, nixpkgs, cachix-deploy-flake }: flake-utils.lib.eachDefaultSystem ( system: { defaultPackage = let pkgs = import nixpkgs { inherit system; }; cachix-deploy-lib = cachix-deploy-flake.lib pkgs; in cachix-deploy-lib.spec { agents = { myagent = cachix-deploy-lib.darwin ( { pkgs, ... }: { networking.hostName = "myagent"; services.cachix-agent.enable = true; # Auto upgrade nix package and the daemon service. services.nix-daemon.enable = true; nix.package = pkgs.nix; } ); }; }; } ); } ``` -------------------------------- ### Expose Files as Artifacts with --artifact Source: https://docs.cachix.org/_sources/pins.rst.txt Use the --artifact option to expose specific files from a pinned store path. These files can then be served by Cachix. ```bash $ cachix pin mycache v1.0 /nix/store/xxx-name-1.0 --artifact etc/nginx.conf --artifact bin/name ``` -------------------------------- ### Watch and Push Store Paths During Command Execution Source: https://docs.cachix.org/_sources/pushing.rst.txt Executes a given command and pushes all store paths produced during its execution to Cachix. The `--max-jobs` option can control the parallelism of the Nix build. ```shell $ cachix watch-exec mycache -- nix-build --max-jobs 4 ``` -------------------------------- ### Push Build and Runtime Dependencies to Cachix Source: https://docs.cachix.org/_sources/pushing.rst.txt This command pushes both build and runtime dependencies, excluding derivations themselves, to your Cachix cache. It first queries the Nix store for all outputs of a build and then filters out the .drv files. ```shell $ nix-store -qR --include-outputs $(nix-store -qd $(nix-build)) \ | grep -v '\.drv$' \ | cachix push mycache ``` -------------------------------- ### Deploy Standalone Home Manager Configuration Source: https://docs.cachix.org/deploy/deploying-to-agents Defines a standalone Home Manager configuration for an agent named 'myagent' within a flake.nix file. Ensure Home Manager and cachix-deploy-flake are properly configured as inputs. ```nix { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05"; flake-utils.url = "github:numtide/flake-utils"; cachix-deploy-flake.url = "github:cachix/cachix-deploy-flake"; cachix-deploy-flake.inputs.home-manager.follows = "home-manager"; home-manager.url = "github:nix-community/home-manager"; home-manager.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = { self, flake-utils, home-manager, nixpkgs, cachix-deploy-flake }: flake-utils.lib.eachDefaultSystem ( system: { defaultPackage = let pkgs = nixpkgs.legacyPackages."${system}"; cachix-deploy-lib = cachix-deploy-flake.lib pkgs; in cachix-deploy-lib.spec { agents = { myagent = cachix-deploy-lib.homeManager { } ( { pkgs, ... }: { home.username = "jdoe"; home.homeDirectory = "/home/jdoe"; home.stateVersion = "22.05"; services.cachix-agent = { enable = true; name = "myagent"; }; } ); }; }; } ); } ``` -------------------------------- ### Configure Cachix Agent on NixOS Source: https://docs.cachix.org/deploy/running-an-agent/nixos Enable the Cachix agent service and set the agent name by configuring NixOS options. Ensure the agent token is placed in `/etc/cachix-agent.token`. ```nix services.cachix-agent.enable = true; # agent name is inferred from the hostname networking.hostName = "myhostname"; ``` -------------------------------- ### Deploy Nix-Darwin Configuration to Agent Source: https://docs.cachix.org/_sources/deploy/deploying-to-agents/index.rst.txt This Nix flake deploys a nix-darwin configuration to an agent. It enables the cachix-agent service and ensures Nix is up-to-date. ```nix { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05"; flake-utils.url = "github:numtide/flake-utils"; cachix-deploy-flake.url = "github:cachix/cachix-deploy-flake"; cachix-deploy-flake.inputs.darwin.follows = "darwin"; darwin.url = "github:LnL7/nix-darwin"; darwin.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = { self, flake-utils, darwin, nixpkgs, cachix-deploy-flake }: flake-utils.lib.eachDefaultSystem ( system: { defaultPackage = let pkgs = import nixpkgs { inherit system; }; cachix-deploy-lib = cachix-deploy-flake.lib pkgs; in cachix-deploy-lib.spec { agents = { myagent = cachix-deploy-lib.darwin ( { pkgs, ... }: { networking.hostName = "myagent"; services.cachix-agent.enable = true; # Auto upgrade nix package and the daemon service. services.nix-daemon.enable = true; nix.package = pkgs.nix; } ); }; }; } ); } ``` -------------------------------- ### Check if Store Path Exists in Binary Cache Source: https://docs.cachix.org/_sources/faq.rst.txt Verify if a specific store path exists in your binary cache by using `curl` to query the `.narinfo` file. ```shell $ curl https://mycache.cachix.org/spznih45c56kfwygx8qyq1skd1rs4zv1.narinfo ``` -------------------------------- ### Deploy Cachix Agent Source: https://docs.cachix.org/_sources/deploy/running-an-agent/darwin.rst.txt Deploys the Cachix agent to your system. Replace '...' with your generated agent token. ```bash sudo -H CACHIX_AGENT_TOKEN=... cachix deploy agent --bootstrap myagent ``` -------------------------------- ### View Cachix Agent Logs Source: https://docs.cachix.org/_sources/deploy/running-an-agent/darwin.rst.txt Tails the log file for the Cachix agent to help diagnose startup issues. ```bash tail -f /var/log/cachix-agent.log ``` -------------------------------- ### Push Whole /nix/store to Cachix Source: https://docs.cachix.org/_sources/pushing.rst.txt This command pushes all store paths currently available in the /nix/store to your Cachix cache. Use with caution as it can upload a large amount of data. ```shell $ nix path-info --all | cachix push mycache ``` -------------------------------- ### Generate Signing Key Pair Source: https://docs.cachix.org/_sources/getting-started.rst.txt Generate a signing key pair for your cache. This is an advanced step for users who want to manage their own signing process. ```bash $ cachix authtoken $ cachix generate-keypair ``` -------------------------------- ### Deploy nix-darwin to Agent Source: https://docs.cachix.org/deploy/deploying-to-agents This specification deploys nix-darwin to an agent. It configures the host name and enables the Cachix agent service. ```nix { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05"; flake-utils.url = "github:numtide/flake-utils"; cachix-deploy-flake.url = "github:cachix/cachix-deploy-flake"; cachix-deploy-flake.inputs.darwin.follows = "darwin"; darwin.url = "github:LnL7/nix-darwin"; darwin.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = { self, flake-utils, darwin, nixpkgs, cachix-deploy-flake }: flake-utils.lib.eachDefaultSystem ( system: { defaultPackage = let pkgs = import nixpkgs { inherit system; }; cachix-deploy-lib = cachix-deploy-flake.lib pkgs; in cachix-deploy-lib.spec { agents = { myagent = cachix-deploy-lib.darwin ( { pkgs, ... }: { networking.hostName = "myagent"; services.cachix-agent.enable = true; # Auto upgrade nix package and the daemon service. services.nix-daemon.enable = true; nix.package = pkgs.nix; } ); }; }; } ); } ``` -------------------------------- ### Deploy Standalone Home Manager to Agent Source: https://docs.cachix.org/deploy/deploying-to-agents/index.html Defines a standalone Home Manager configuration for an agent named 'myagent' within a flake. Requires NixOS 22.05 and the cachix-deploy-flake. Ensure the agent has the cachix-agent service enabled. ```nix { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05"; flake-utils.url = "github:numtide/flake-utils"; cachix-deploy-flake.url = "github:cachix/cachix-deploy-flake"; cachix-deploy-flake.inputs.home-manager.follows = "home-manager"; home-manager.url = "github:nix-community/home-manager"; home-manager.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = { self, flake-utils, home-manager, nixpkgs, cachix-deploy-flake }: flake-utils.lib.eachDefaultSystem ( system: { defaultPackage = let pkgs = nixpkgs.legacyPackages."${system}"; cachix-deploy-lib = cachix-deploy-flake.lib pkgs; in cachix-deploy-lib.spec { agents = { myagent = cachix-deploy-lib.homeManager ( { pkgs, ... }: { home.username = "jdoe"; home.homeDirectory = "/home/jdoe"; home.stateVersion = "22.05"; services.cachix-agent = { enable = true; name = "myagent"; }; } ); }; }; } ); } ``` -------------------------------- ### Push All Nix Store Paths to Cachix Source: https://docs.cachix.org/pushing This command pushes all paths present in the Nix store to your Cachix cache. Use with caution as this can be a large operation. ```bash $ nix path-info --all | cachix push mycache ``` -------------------------------- ### Push Shell Environment to Cachix Source: https://docs.cachix.org/_sources/pushing.rst.txt Uploads the Nix shell environment to Cachix. This involves building a shell environment and then pushing the resulting profile. ```shell $ nix-build shell.nix -A inputDerivation \ | cachix push mycache ``` ```shell $ nix develop --profile dev-profile -c true $ cachix push mycache dev-profile ``` -------------------------------- ### Configure AWS Credentials Source: https://docs.cachix.org/importing-from-s3 Use the AWS CLI to configure your access key ID, secret access key, and default region. This is a prerequisite for interacting with S3. ```bash $ aws configure ``` -------------------------------- ### Deploy Cachix Agent Manually Source: https://docs.cachix.org/_sources/deploy/running-an-agent/manually.rst.txt Use this command to deploy a Cachix agent. Ensure you have your AGENT-TOKEN and AGENT-NAME ready. The NIX-PROFILE-NAME is optional. ```bash $ CACHIX_AGENT_TOKEN=AGENT-TOKEN cachix deploy agent AGENT-NAME [NIX-PROFILE-NAME] ``` ```bash $ CACHIX_AGENT_TOKEN=... cachix deploy agent myagentname ``` -------------------------------- ### Verify API Authentication Token with Curl Source: https://docs.cachix.org/faq Use this command to check if your API authentication token is correctly configured for accessing user information. ```bash $ curl -v -H "Authorization: Bearer ${CACHIX_AUTH_TOKEN}" https://app.cachix.org/api/v1/user ``` -------------------------------- ### Import Cache from S3 Source: https://docs.cachix.org/_sources/importing-from-s3.rst.txt Use this command to import your binary cache from an S3 bucket to Cachix. Replace placeholders with your specific cache and bucket names. Ensure the machine running this command has a fast network connection as data will be streamed. ```bash cachix import s3://?endpoint=®ion= ``` ```bash cachix import mycache s3://mybucket ``` -------------------------------- ### Watch and Push Store Paths from a Command Source: https://docs.cachix.org/pushing This command executes a given command and pushes all store paths produced by that command to your Cachix cache. It includes a job limit for the execution. ```bash $ cachix watch-exec mycache -- nix-build --max-jobs 4 ``` -------------------------------- ### Configure CircleCI for Cachix Source: https://docs.cachix.org/_sources/continuous-integration-setup/circleci.rst.txt This YAML configuration defines a CircleCI job that uses a NixOS Docker image, sets up Cachix, and executes build commands using `cachix watch-exec`. ```yaml version: 2.1 workflows: version: 2 workflow: jobs: - build jobs: build: docker: - image: nixos/nix:2.3.12 environment: CACHIX_NAME: mycache steps: - checkout - run: name: Set up Cachix command: | nix-env -iA nixpkgs.cachix nixpkgs.bash cachix use $CACHIX_NAME - run: cachix watch-exec $CACHIX_NAME nix-build - run: cachix watch-exec $CACHIX_NAME -- nix-shell --run "echo nix-shell successfully entered" ``` -------------------------------- ### Deploy Cachix Agent Source: https://docs.cachix.org/_sources/deploy/running-an-agent/home-manager.rst.txt Deploys a Cachix agent to your workspace using a previously generated token. Replace '...' with your actual token. ```shell CACHIX_AGENT_TOKEN=... cachix deploy agent myagent ``` -------------------------------- ### Push Runtime Closure of Specific Flake Packages Source: https://docs.cachix.org/pushing Use this command to push the runtime closure of specific packages (e.g., '.#package-a', '.#package-b') within a Flake to your Cachix cache. It builds the specified packages without creating symlinks and prints their output paths. ```bash $ nix build --no-link --print-out-paths .#package-a .#package-b \ | cachix push mycache ``` -------------------------------- ### Authenticate with Cachix API Source: https://docs.cachix.org/_sources/faq.rst.txt Use this command to authenticate with the Cachix API using an authorization token. Ensure the CACHIX_AUTH_TOKEN environment variable is set. ```shell-session $ curl -v -H "Authorization: Bearer ${CACHIX_AUTH_TOKEN}" https://app.cachix.org/api/v1/user ``` -------------------------------- ### Push Shell Environment Dependencies to Cachix Source: https://docs.cachix.org/pushing Use this to push the dependencies required for a shell environment defined in 'shell.nix' to your Cachix cache. ```bash $ nix-build shell.nix -A inputDerivation \ | cachix push mycache ``` -------------------------------- ### Bootstrap Cachix Agent with New Name Source: https://docs.cachix.org/deploy/troubleshooting Use this command to bootstrap a Cachix agent with a new name. Existing agents cannot pick up the new name and must be bootstrapped again. The daemon will exit after successful deployment. ```bash CACHIX_AGENT_TOKEN=XXX cachix deploy agent --bootstrap new-agent-name ``` -------------------------------- ### Pin Multiple Store Paths Source: https://docs.cachix.org/_sources/pins.rst.txt This demonstrates pinning two different store paths with distinct pin names. Ensure you are using Cachix 1.5 or later. ```bash $ cachix pin mycache go-1.7 /nix/store/nd3ssg3hiqj6ivvkv2n5q7ppdwh0wqcf-go-1.7 $ cachix pin mycache go-1.8 /nix/store/canq1nwdhxk4d2yj8pgywz7lqhkpyq2d-go-1.8 ``` -------------------------------- ### deploy.json Configuration Structure Source: https://docs.cachix.org/deploy/reference Defines the structure for deploy.json, specifying agent mappings and optional rollback scripts for Cachix deployments. The 'agents' key maps agent names to store paths, while 'rollbackScript' allows per-system rollback script definitions. New in version 1.0.0. ```json { "agents": { "": "", ... }, "rollbackScript": { "": "", } } ``` -------------------------------- ### Verify Cache Authentication Token with Curl Source: https://docs.cachix.org/faq This command verifies your cache authentication token using a netrc file for private binary caches. ```bash $ curl -s --netrc-file ~/.config/nix/netrc https://mycache.cachix.org/nix-cache-info ``` -------------------------------- ### Run Cachix Doctor for Troubleshooting Source: https://docs.cachix.org/_sources/faq.rst.txt Use `cachix doctor` to diagnose common configuration and authentication problems. Available since version 1.10. ```shell $ cachix doctor ``` -------------------------------- ### Pin a Store Path Source: https://docs.cachix.org/_sources/pins.rst.txt Use this command to assign a persistent name to a store path in your cache. This protects the path from garbage collection. ```bash $ cachix pin mycache v1.0 /nix/store/xxx-name-1.0 ```