### Start a service named 'server' Source: https://flox.dev/docs/reference/command-reference/flox-services-start Example of how to start a specific service named 'server' using the flox services start command. ```bash $ flox services start server ``` -------------------------------- ### Start all services Source: https://flox.dev/docs/reference/command-reference/flox-services-start Example demonstrating how to start all available services by omitting the service name argument. ```bash $ flox services start ``` -------------------------------- ### Example Darwin System Flake Configuration for Flox Source: https://flox.dev/docs/install-flox/install This snippet shows a complete example of a Nix flake configuration for a Darwin system, demonstrating how to integrate Flox and specify system packages and Nix settings. It includes definitions for trusted substituters and public keys. ```nix { decription = "Example Darwin system flake"; nixConfig = { extra-trusted-substituters = ["https://cache.flox.dev"]; extra-trusted-public-keys = ["flox-cache-public-1:7F4OyH7ZCnFhcze3fJdfyXYLQw/aV7GEed86nQ7IsOs="]; }; inputs = { nixpkgs = { url = "github:NixOS/nixpkgs/nixpkgs-23.11-darwin"; }; nix-darwin = { url = "github:LnL7/nix-darwin"; inputs.nixpkgs.follows = "nixpkgs"; }; flox = { url = "github:flox/flox/v1.7.3"; }; }; outputs = inputs@{ self, nix-darwin, nixpkgs, flox }: let configuration = { pkgs, ... }: { environment.systemPackages = [ pkgs.{{ YOUR_PACKAGES }} inputs.flox.packages.${pkgs.system}.default ]; nix.settings = { experimental-features = "nix-command flakes"; substituters = [ "https://cache.flox.dev" ]; trusted-public-keys = [ "flox-cache-public-1:7F4OyH7ZCnFhcze3fJdfyXYLQw/aV7GEed86nQ7IsOs=" ]; }; {{ YOUR_CONFIG }} }; in { darwinConfigurations."{{ YOUR_HOST }}" = nix-darwin.lib.darwinSystem { modules = [ configuration ]; specialArgs = { inherit inputs; }; }; }; } ``` -------------------------------- ### flox services start command synopsis Source: https://flox.dev/docs/reference/command-reference/flox-services-start The synopsis of the 'flox services start' command, outlining its general structure and available options for starting services. ```bash flox [] services start [-d= | -r=] [] ... ``` -------------------------------- ### Configure nix-daemon to start on activation Source: https://flox.dev/docs/install-flox/install Adds logic to ~/.bashrc to automatically start the nix-daemon when a WSL instance begins. This ensures the daemon runs after Flox installation. ```shell cat >> ~/.bashrc <&1 >/dev/null ) || wsl.exe -d $WSL_DISTRO_NAME -u root service nix-daemon start EOF ``` -------------------------------- ### Initialize Flox Project and Install Go Source: https://flox.dev/docs/tutorials/build-and-publish This snippet demonstrates initializing a new Flox project, installing the Go compiler, and listing installed packages within the environment. ```shell mkdir myproject cd myproject flox init flox install go flox list ``` -------------------------------- ### Install Multiple Dependencies Source: https://flox.dev/docs/tutorials/migrations/nvm Installs multiple dependencies, such as PostgreSQL and Nginx, into the Flox environment simultaneously. This simplifies the setup of complex development environments. ```bash flox install postgresql nginx ``` -------------------------------- ### Example usage of `flox show` Source: https://flox.dev/docs/reference/command-reference/flox-show Demonstrates how to use the `flox show` command to get detailed information about the 'ripgrep' package. ```bash $ flox show ripgrep ripgrep - A utility that combines the usability of The Silver Searcher with the raw speed of grep ripgrep@13.0.0 ripgrep@14.1.0 ``` -------------------------------- ### Set up PyTorch with CUDA using Flox Source: https://flox.dev/docs/tutorials/cuda This snippet illustrates how to set up a PyTorch environment with CUDA acceleration using Flox. It includes cloning the PyTorch examples repository, initializing a Flox environment, installing necessary packages, and verifying CUDA availability. ```bash git clone pytorch-examples cd pytorch-examples/mnist flox init flox install python3 flox-cuda/python3Packages.torch flox-cuda/python3Packages.torchvision flox activate python -c "import torch; print(torch.cuda.is_available())" python main.py ``` -------------------------------- ### Install a Flox Package Source: https://flox.dev/docs/tutorials/build-and-publish Shows the command to install a specific package, 'myuser/hello', into the current Flox environment named 'myproject'. It confirms the successful installation. ```bash flox [myproject] $ flox install myuser/hello ✅ 'myuser/hello' installed to environment 'myproject' ``` -------------------------------- ### Install a Package with Flox Source: https://flox.dev/docs/flox-5-minutes This command installs the specified package into the current environment. It fetches and sets up the package and its dependencies. ```shell flox install ripgrep ``` -------------------------------- ### Install jq package with Flox Source: https://flox.dev/docs/tutorials/migrations/homebrew Installs the 'jq' package into the default Flox environment. It prompts the user to confirm the installation and optionally configure shell activation. ```shell flox install jq ``` ```shell % flox install jq Packages must be installed into a Flox environment, which can be a user 'default' environment or attached to a directory. ! Would you like to install 'jq' to the 'default' environment? > Yes No [↑↓ to move, enter to select, type to filter] The 'default' environment can be activated automatically for every new shell by adding one line to your .bashrc file: eval "$(flox activate -d ~ -m run)" ! Would you like Flox to add this configuration to your .bashrc now? > Yes No [↑↓ to move, enter to select, type to filter] ✅ Configuration added to your .bashrc file. The 'default' environment will be activated for every new shell. -> Restart your shell to continue using the default environment. -> Read more about the 'default' environment at: https://flox.dev/docs/tutorials/layering-multiple-environments/#create-your-default-home-environment ✅ 'jq' installed to environment 'default' ``` -------------------------------- ### Install Package to Default Environment from Another Environment Source: https://flox.dev/docs/tutorials/default-environment Shows how to install a package (`hello`) into the default environment (`-d ~`) even when currently operating within a different Flox environment. ```shell flox install -d ~ hello ✅ 'hello' installed to environment 'default' ``` -------------------------------- ### Example manifest.toml for Flox Environment Customization Source: https://flox.dev/docs/tutorials/creating-environments A TOML file demonstrating how to define package installations, environment variables, and a custom activation hook for a Flox environment. ```toml # List packages you wish to install in your environment under # the `[install]` table [install] nodejs.pkg-path = "nodejs" mkcert.pkg-path = "mkcert" # hello.pkg-path = "hello" # nodejs = { version = "^18.4.2", pkg-path = "nodejs_18" } # Set an environment variable. These variables may not reference once another. [vars] # message = "Howdy" # pass-in = "$some-env-var" # Set your activation hook ( run when entering the environment ) # You can write this inline with the `on-activate` field. [hook] on-activate = """ echo "" echo "Start the server with 'npm start'" echo "" "" ``` -------------------------------- ### CircleCI Workflow with Flox Orb Source: https://flox.dev/docs/tutorials/ci-cd_h=ci An example CircleCI configuration (.circleci/config.yml) demonstrating the use of the Flox Orb. It includes steps to check out code, install Flox using the 'flox/install' job, and activate a Flox environment to run a command like 'npm run build' using the 'flox/activate' job. ```yaml version: 2.1 orbs: flox: flox/flox@0.1.0 jobs: build: machine: image: ubuntu-2204:current steps: - checkout - orb-steps: flox/install - orb-steps: flox/activate: command: "npm run build" ``` -------------------------------- ### Install Go Binary Directly to $out Source: https://flox.dev/docs/cookbook/languages/go Installs a Go binary directly into the $out directory using the go install command. This method leverages the GOBIN environment variable to specify the installation path. ```go [build.myproject] command = ''' GOBIN=$out/bin go install -trimpath ''' ``` -------------------------------- ### List installed packages Source: https://flox.dev/docs/tutorials/migrations/homebrew Displays a list of packages installed in the current Flox environment, along with their versions. This is used to verify package installation. ```shell flox [default] % flox list jq: jq (1.7.1) ``` -------------------------------- ### Build and Run HSOpticalFlow Example Source: https://flox.dev/docs/tutorials/cuda This snippet shows the commands to build and run the HSOpticalFlow CUDA example. It involves creating a build directory, configuring with CMake, compiling with make, and then executing the compiled program. ```bash mkdir build && cd build && cmake .. && make -j8 ./HSOpticalFlow ``` -------------------------------- ### Build and Run Julia Set Example Source: https://flox.dev/docs/tutorials/cuda This snippet demonstrates the process of building and running a Julia set rendering example. Similar to the optical flow example, it uses CMake and make for building. ```bash mkdir build && cd build && cmake .. && make -j8 ./Mandelbrodt ``` -------------------------------- ### Example Package Path Configuration Source: https://flox.dev/docs/reference/command-reference/flox-install This TOML snippet demonstrates how to configure package paths within a Flox manifest file. It shows the mapping between a package's install ID (e.g., 'ripgrep') and its corresponding package path (e.g., 'ripgrep'). This is useful for managing packages with complex or non-standard names. ```toml [install] ripgrep.pkg-path = "ripgrep" pip.pkg-path = "python310Packages.pip" ``` -------------------------------- ### Flox Environment Manifest Configuration Source: https://flox.dev/docs/flox-5-minutes This TOML snippet shows an example of a Flox environment manifest. It defines package installations, environment variables, and background services. ```toml version = 1 [install] go.pkg-path = "go" nodejs_24.pkg-path = "nodejs_24" ripgrep.pkg-path = "ripgrep" coreutils.pkg-path = "coreutils" bun.pkg-path = "bun" nasm.pkg-path = "nasm" [vars] MY_VAR = "pretty neat" [services.stopwatch] command = ''' while true; do date; sleep 5; done ''' ``` -------------------------------- ### Building and Verifying a Package Source: https://flox.dev/docs/reference/command-reference/flox-build Example of building a package named 'hello' and verifying its output. ```APIDOC ## Build and Verify ```bash $ flox build hello $ ls ./result-hello hello.txt $ cat ./result-hello/hello.txt hello, world ``` ``` -------------------------------- ### Test Package Availability in Default Environment Source: https://flox.dev/docs/tutorials/default-environment Tests the functionality of the default environment by creating a temporary directory, installing a package (`hello`), and verifying its availability. ```shell cd $(mktemp -d) $ flox install hello ✅ 'hello' installed to environment 'default' ``` -------------------------------- ### Run Container Interactively Source: https://flox.dev/docs/reference/command-reference/flox-containerize Illustrates the steps to initialize a Flox environment, install a package, containerize it, load it into Docker, and run it interactively. ```bash $ flox init $ flox install hello $ flox containerize -f - | docker load $ docker run --rm -it [floxenv] $ hello Hello, world! ``` -------------------------------- ### Flox Catalog Commands Source: https://flox.dev/docs/concepts/packages-and-catalog Demonstrates core commands for interacting with the Flox Catalog to search, show, and install packages. ```bash flox search flox show flox install ``` -------------------------------- ### Activate Flox with Services Source: https://flox.dev/docs/tutorials/migrations/nvm Activates a Flox environment and starts associated services, useful for managing development environments with running dependencies. ```bash flox activate --start-services ``` -------------------------------- ### Install Packages with flox Source: https://flox.dev/docs/reference/command-reference/flox-install The `flox install` command installs packages into a specified environment. It supports transactional installations, ensuring environment integrity. Packages can be specified by their install ID or package path, with optional versioning. The command includes general options for verbosity and help. ```bash flox [] install [-i ] [[-i ] ] ... ``` -------------------------------- ### Install Node.js Package Source: https://flox.dev/docs/tutorials/migrations/nvm Installs a specific version of Node.js from the Flox Catalog into the current environment. It's recommended to use versioned packages like `nodejs_20` instead of the generic `nodejs`. ```bash flox install nodejs_20 ``` -------------------------------- ### flox install Source: https://flox.dev/docs/reference/command-reference/flox-install Installs packages into a Flox environment. Package installation is transactional, ensuring environment integrity. Supports specifying packages by install ID or pkg-path, including Nix flake installables. ```APIDOC ## POST /install ### Description Installs one or more packages into the current or specified Flox environment. The installation process is transactional, meaning the environment is validated before an atomic update. If the validation fails, the environment remains unchanged. ### Method POST ### Endpoint /install ### Parameters #### Query Parameters - **-i, --id** (string) - Optional - The install ID of the package, providing a shorthand for packages with long or complex pkg-paths. - **** (string) - Required - The pkg-path of the package to install. Can be suffixed with `@` to specify a version. Alternatively, a Nix flake installable or store path can be specified. - **-d, --dir** (string) - Optional - Path to the directory containing the `.flox/` configuration for the target environment. - **-r, --remote** (string) - Optional - Specifies a remote environment on FloxHub in the format `/`. - **-h, --help** (boolean) - Optional - Prints help information. - **-v, --verbose** (boolean) - Optional - Increases logging verbosity. Can be invoked multiple times for greater detail. - **-q, --quiet** (boolean) - Optional - Silences logs except for errors. ### Request Example ```json { "packages": [ {"name": "ripgrep"}, {"name": "python310Packages.pip", "installId": "pip"} ], "environment": { "dir": "./my-flox-env" } } ``` ### Response #### Success Response (200) - **message** (string) - A confirmation message indicating successful installation. #### Response Example ```json { "message": "Packages installed successfully." } ``` ``` -------------------------------- ### Initialize and install packages with flox Source: https://flox.dev/docs/tutorials/multi-arch-environments Initialize a new Flox environment with a specified name and then install desired packages into it. This sets up a consistent environment for development. ```bash $ flox init --name eng-team-tools ✨ Created environment eng-team-tools (aarch64-linux) ... $ flox install gnupg vim ✅ 'gnupg' installed to environment eng-team-tools at /home/youruser ✅ 'vim' installed to environment eng-team-tools at /home/youruser ``` -------------------------------- ### Initialize and Share Environment with Files (Bash) Source: https://flox.dev/docs/tutorials/sharing-environments Demonstrates initializing a new Flox environment, installing packages, committing the .flox directory to git, and activating it on another machine. Assumes git is installed. ```bash $ mkdir example-project $ cd example-project $ git init ... $ flox init ... $ flox install inetutils neovim curl ✅ 'inetutils' installed to environment example-project at /Users/youruser/example-project ✅ 'neovim' installed to environment example-project at /Users/youruser/example-project ✅ 'curl' installed to environment example-project at /Users/youruser/example-project git add .flox; git commit -m "sharing flox environment" ... git clone ..example-project; flox activate ``` -------------------------------- ### Show top-level Homebrew formulae Source: https://flox.dev/docs/tutorials/migrations/homebrew Lists explicitly installed Homebrew formulae, helping to differentiate from dependencies. This output is used as input for searching Flox packages. ```shell % brew leaves ``` ```shell aider awscli ffmpeg flake8 gh gnupg go graphviz htop isort jq neovim pkgconf redo ripgrep tmux tree watch wget ``` -------------------------------- ### Attempt to start a non-existent service Source: https://flox.dev/docs/reference/command-reference/flox-services-start Illustrates the command's behavior and error message when attempting to start a service that does not exist. ```bash $ flox services start myservice doesnt_exist ❌ ERROR: Service 'doesnt_exist' not found. ``` -------------------------------- ### Install Caddy with Flox Source: https://flox.dev/docs/concepts/flox-vs-containers Installs the Caddy web server using the Flox package manager. This is the first step to setting up Caddy as a development service. ```bash flox install caddy ``` -------------------------------- ### Restrict runtime dependencies using runtime-packages in Flox manifest Source: https://flox.dev/docs/concepts/manifest-builds This example manifest demonstrates how to install multiple packages (`hello-go`, `ripgrep`) for development but restrict the runtime dependencies to only `hello-go` by specifying its `install-id` in the `runtime-packages` list. The `install-id` is the identifier preceding `.pkg-path`. ```Nix version = 1 [install] hello.pkg-path = "hello-go" ripgrep.pkg-path = "ripgrep" [build.hello-pkg] command = ''' mkdir -p $out/bin echo "hello-go" > $out/bin/hello-pkg chmod +x $out/bin/hello-pkg ''' runtime-packages = [ "hello" ] # List of `install-id`s [options] systems = ["aarch64-darwin", "x86_64-darwin", "aarch64-linux", "x86_64-linux"] ``` -------------------------------- ### Install prerequisites for Debian Source: https://flox.dev/docs/install-flox/install Installs necessary packages for Flox installation on Debian-based WSL distributions using apt-get. ```shell sudo apt-get install policycoreutils semodule-utils tar wget xz-utils ``` -------------------------------- ### Start a Flox Service Source: https://flox.dev/docs/flox-5-minutes This command starts a background service defined in the environment's manifest. The 'stopwatch' service is started here. ```shell $ flox services start ✅ Service 'stopwatch' started. ``` -------------------------------- ### Install Tools with Flox Source: https://flox.dev/docs/tutorials/layering-multiple-environments Installs a list of specified command-line tools into the 'default' Flox environment. These tools are intended for general use across different projects. ```bash $ flox install curl gitFull gnupg inetutils tree vim ✅ 'curl' installed to environment default at /Users/youruser ✅ 'gitFull' installed to environment default at /Users/youruser ✅ 'gnupg' installed to environment default at /Users/youruser ✅ 'inetutils' installed to environment default at /Users/youruser ✅ 'tree' installed to environment default at /Users/youruser ✅ 'vim' installed to environment default at /Users/youruser ``` -------------------------------- ### Attempt to start an already running service Source: https://flox.dev/docs/reference/command-reference/flox-services-start Shows the output when trying to start a service that is already active, including the warning message. ```bash $ flox services start running not_running ✅ Service 'not_running' started ⚠️ Service 'running' is already running ``` -------------------------------- ### Configure Node.js Package Group in Manifest Source: https://flox.dev/docs/tutorials/migrations/nvm Example of how to specify a package group for a Node.js installation within the `manifest.toml` file. This helps manage dependencies and ensures compatibility. ```toml ... [install] nodejs_20 = { pkg-path = "nodejs_20", pkg-group = "node-toolchain" } ... ``` -------------------------------- ### Follow logs for a subset of services Source: https://flox.dev/docs/reference/command-reference/flox-services-logs Example of how to follow logs for a specific selection of services using the `--follow` flag along with service names. ```bash $ flox services logs --follow service1 service3 service1: hello service3: hello ... ``` -------------------------------- ### Show package details in Flox Source: https://flox.dev/docs/tutorials/creating-environments Displays detailed information about a specific package, including available versions. This helps in selecting the correct version for installation. ```bash $ flox show nodejs nodejs - Event-driven I/O framework for the V8 JavaScript engine nodejs@18.18.2 nodejs@18.18.0 nodejs@18.17.1 nodejs@18.16.1 nodejs@18.9.0 nodejs@18.7.0 ... ``` -------------------------------- ### flox build Package Build Instructions Source: https://flox.dev/docs/reference/command-reference/flox-build Example of how to define build instructions for a package within `manifest.toml`. ```APIDOC ## file: .flox/env/manifest.toml [build] hello.command = ''' ## produce something and move it to $out mkdir -p $out echo "hello world" >> $out/hello.txt ''' description = "Produces a file containing 'hello world'" version = "0.0.0" ``` -------------------------------- ### Install Flox imperatively with Nix (System-wide) Source: https://flox.dev/docs/install-flox/install Command to install Flox to the system-wide default profile as root. Requires root privileges and enables experimental features. ```bash sudo -H nix profile install \ --profile /nix/var/nix/profiles/default \ --experimental-features "nix-command flakes" \ --accept-flake-config \ 'github:flox/flox' ``` -------------------------------- ### Install packages into a Flox environment Source: https://flox.dev/docs/tutorials/creating-environments Installs a specified package into the current Flox environment. It confirms the successful installation and the location where the package was added. ```bash $ flox install nodejs ✅ 'nodejs' installed to environment example-project at /Users/myuser/example-project ``` ```bash $ flox install mkcert ✅ 'mkcert' installed to environment example-project at /Users/myuser/example-project ``` -------------------------------- ### Activate Environment and Start Services with Flox Source: https://flox.dev/docs/flox-5-minutes This command activates a Flox environment and optionally starts any associated services. The `-s` or `--start-services` flag ensures services are running upon activation. ```shell flox activate -s ``` -------------------------------- ### Install Specific CUDA Component with Flox Source: https://flox.dev/docs/tutorials/cuda Demonstrates how to install a specific component of the CUDA Toolkit, such as the `nvcc` compiler, using Flox. This allows for installing only the necessary parts of the toolkit, reducing download size. ```shell flox install flox-cuda/cudaPackages.cuda_nvcc ``` -------------------------------- ### Initialize and Install Tools with Flox Source: https://flox.dev/docs/tutorials/customizing-environments Initializes a new Flox environment, installs necessary tools like rustc, cargo, and libiconv, and sets up a Rust project. ```bash mkdir mycli; cd mycli; flox init; flox install rustc cargo libiconv ``` -------------------------------- ### List installed packages and system constraints Source: https://flox.dev/docs/tutorials/multi-arch-environments Use `flox list` to view installed packages and `flox list -c` to inspect the configuration, including system-specific constraints. This helps verify which packages are available for the current system. ```bash $ flox list gnupg: gnupg (2.4.5) vim: vim (9.1.0377) $ flox list -c ... [install] gnupg.pkg-path = "gnupg" vim.pkg-path = "vim" systemd.pkg-path = "systemd" systemd.systems = ["aarch64-linux", "x86_64-linux"] ... ``` -------------------------------- ### Automate Flox Python Environment Setup Source: https://flox.dev/docs/cookbook/languages/python Initializes a Flox environment and automatically applies recommended setups for Python projects. This bypasses the interactive prompts for environment configuration. ```bash flox init --auto-setup ``` -------------------------------- ### Install Flox (Personal Profile) Source: https://flox.dev/docs/install-flox/install Command to install Flox into the user's personal profile using Nix package management. ```bash nix profile install \ --experimental-features "nix-command flakes" \ --accept-flake-config \ 'github:flox/flox' ``` -------------------------------- ### Activate and Test Flox Environment Source: https://flox.dev/docs/tutorials/layering-multiple-environments Activates the 'default' Flox environment and demonstrates how to verify the installation of a package, specifically 'git', by checking its path and version. ```bash $ flox activate flox [default] $ which git /Users/youruser/.flox/run/aarch64-darwin.default/bin/git flox [default] $ git --version git version 2.42.0 ``` -------------------------------- ### Install Flox imperatively with Nix (User Profile) Source: https://flox.dev/docs/install-flox/install Command to install Flox to the user's personal profile using Nix. It enables experimental features and accepts flake configurations. ```bash nix profile install \ --experimental-features "nix-command flakes" \ --accept-flake-config \ 'github:flox/flox' ``` -------------------------------- ### Flox Manifest Include Syntax Example Source: https://flox.dev/docs/reference/command-reference/manifest This example demonstrates the basic syntax for the `[include]` section in a Flox manifest, showing how to specify local environments with optional name overrides. ```toml [include] environments = [ { dir = "../path/to/env" }, { dir = "../path/to/other/env", name = "myenv" } ] ``` -------------------------------- ### Search for a package in Flox Source: https://flox.dev/docs/tutorials/migrations/homebrew Searches the Flox catalog for a package, providing a list of potential matches. The first result is often the direct equivalent to the Homebrew package. ```shell % flox search jq ``` ```shell jq Lightweight and flexible command-line JSON processor ijq Interactive wrapper for jq jql JSON Query Language CLI tool built with Rust jqp TUI playground to experiment with jq gojq Pure Go implementation of jq jq-lsp jq language server jquake Real-time earthquake map of Japan jq-zsh-plugin Interactively build jq expressions in Zsh vimPlugins.jq-vim python37Packages.jq Python bindings for jq, the flexible JSON processor Showing 10 of 80 results. Use `flox search jq --all` to see the full list. Use 'flox show ' to see available versions ``` -------------------------------- ### Example Workflow: Activate, Build, and Run Source: https://flox.dev/docs/tutorials/customizing-environments Demonstrates a typical workflow after configuring the Flox environment: activating the environment, building the Rust project with cargo, and running the compiled program. ```bash $ flox activate ... $ cargo build ... $ mycli Hello, World! ``` -------------------------------- ### flox build: Building and verifying a package Source: https://flox.dev/docs/reference/command-reference/flox-build Demonstrates how to build a package named 'hello' using `flox build` and then verify the output by checking the created `result-hello` directory and its contents. ```bash $ flox build hello $ ls ./result-hello hello.txt $ cat ./result-hello/hello.txt hello, world ``` -------------------------------- ### List Installed Tools in Flox Environment Source: https://flox.dev/docs/flox-5-minutes Displays a list of all tools and their versions installed within the current Flox environment. This includes language runtimes and development utilities. ```shell $ flox list bun: bun (1.2.20) coreutils: coreutils (9.7) go: go (1.24.5) nasm: nasm (2.16.03) nodejs_24: nodejs_24 (24.5.0) ``` -------------------------------- ### Update Flox in Flake Configuration Source: https://flox.dev/docs/install-flox/install Example snippet showing how to update the Flox version within a Nix flake definition by modifying the 'url' attribute. ```nix ... flox = { url = "github:flox/flox/v1.7.3"; }; ... ``` -------------------------------- ### Install Packages in manifest.toml (TOML) Source: https://flox.dev/docs/reference/command-reference/manifest This snippet demonstrates how to specify packages to be installed within a Flox environment using the `[install]` table in `manifest.toml`. It shows different TOML syntaxes for defining package paths. ```toml [install] ripgrep.pkg-path = "ripgrep" pip.pkg-path = "python310Packages.pip" ``` ```toml [install] ripgrep = { pkg-path = "ripgrep" } pip = { pkg-path = "python310Packages.pip" } ``` ```toml [install.ripgrep] pkg-path = "ripgrep" [install.pip] pkg-path = "python310Packages.pip" ``` -------------------------------- ### Upgrade notification message example Source: https://flox.dev/docs/reference/command-reference/flox-config Provides an example of the notification message displayed when upgrades are available for packages in an environment. ```bash Upgrades are available for packages in 'environment-name'. Use 'flox upgrade --dry-run' for details. ``` -------------------------------- ### flox build: Manifest-defined package build instructions Source: https://flox.dev/docs/reference/command-reference/flox-build Example of defining build instructions for a package named 'hello' within the `manifest.toml` file. This includes the command to execute, a description, and the version. ```toml ## file: .flox/env/manifest.toml ... [build] hello.command = ''' ## produce something and move it to $out mkdir -p $out echo "hello world" >> $out/hello.txt ''' description = "Produces a file containing 'hello world'" version = "0.0.0" ``` -------------------------------- ### Activate CUDA Environment with Flox Source: https://flox.dev/docs/tutorials/cuda This snippet shows how to clone the CUDA samples repository, check out the Flox environment branch, and activate the environment. This process sets up the necessary CUDA Toolkit and dependencies for running examples. ```shell git clone https://github.com/flox/cuda-samples.git cd cuda-samples git checkout flox-env flox activate ``` -------------------------------- ### GitHub Actions Workflow for Building Website with Flox Source: https://flox.dev/docs/tutorials/ci-cd_h=ci This YAML snippet defines a GitHub Actions workflow for building a website. It includes steps for checking out the repository, installing Flox using the `flox/install-flox-action`, and activating the Flox environment to run a build command (e.g., `npm run build`) using the `flox/activate-action`. This workflow is designed for the `ubuntu-latest` runner. ```yaml jobs: build: name: "Build website" runs-on: "ubuntu-latest" steps: - name: "Checkout" uses: "actions/checkout@v4" - name: "Install Flox" # (2)! uses: "flox/install-flox-action@v2" - name: "Build" # (3)! uses: "flox/activate-action@v1" with: command: "npm run build" ``` -------------------------------- ### Clone Flox Sample Project Source: https://flox.dev/docs/flox-5-minutes Clones the official Flox sample project from GitHub and navigates into the project directory. This is the first step to setting up the development environment. ```shell git clone https://github.com/flox/flox-in-5min.git cd flox-in-5min ``` -------------------------------- ### Ruby Manifest Build Script Example Source: https://flox.dev/docs/cookbook/languages/ruby An example shell script for a Ruby manifest build. It utilizes 'bundle exec' to run the application and assumes dependencies are managed by Bundler. ```bash #!/usr/bin/env bash bundle exec ruby app.rb ``` -------------------------------- ### Dockerfile for Ubuntu with Package Installation Source: https://flox.dev/docs/concepts/flox-vs-containers A Dockerfile specifying an Ubuntu base image and including commands to install system packages. ```dockerfile FROM ubuntu:noble RUN apt update && apt install curl npm RUN sudo add-apt-repository ppa:deadsnakes/ppa -y && \ sudo apt update && \ sudo apt install python3.10 ``` -------------------------------- ### Build C/C++ Project with Autotools using Flox Source: https://flox.dev/docs/cookbook/languages/c This snippet demonstrates how to configure, build, and install a C/C++ project using Autotools with Flox. It requires setting the install prefix to the output directory ($out). ```toml [build.myproject] command = ''' ./configure --prefix=$out make make install ''' ``` -------------------------------- ### Follow logs for all services Source: https://flox.dev/docs/reference/command-reference/flox-services-logs Example of using the `--follow` flag without specifying any service names to view logs from all services in real-time. ```bash $ flox services logs --follow service1: hello service2: hello ... ``` -------------------------------- ### Configure Flox binary cache in Nix flake Source: https://flox.dev/docs/install-flox/install Example of how to configure Flox's binary cache within a Nix flake's configuration. This ensures the cache is used for flake operations. ```nix { nixConfig = { extra-trusted-substituters = ["https://cache.flox.dev"]; extra-trusted-public-keys = ["flox-cache-public-1:7F4OyH7ZCnFhcze3fJdfyXYLQw/aV7GEed86nQ7IsOs="]; }; } ``` -------------------------------- ### Build the optimized 'hello-opt' program with Flox Source: https://flox.dev/docs/tutorials/build-and-publish Executes 'flox build hello-opt' to build the specifically optimized version of the 'hello' program. The output confirms the optimized build process and the creation of './result-hello-opt'. ```bash flox [myproject] $ flox build hello-opt Rendering hello-opt build script to /var/folders/qn/77rf0syj2s7djp588bzp5vkm0000gn/T//60dfcc45-hello-opt-build.bash Building hello-opt-1.0.0 in local mode 00:00:00.004522 + go build '-ldflags=-s -w' -gcflags=-l=4 00:00:00.155021 + mkdir -p /tmp/store_60dfcc45203ccd97815dbc9aecc6d84d-hello-opt-1.0.0/bin 00:00:00.157435 + cp hello /tmp/store_60dfcc45203ccd97815dbc9aecc6d84d-hello-opt-1.0.0/bin/hello this derivation will be built: /nix/store/k6za2nx7jla6rwzs7lj1qm4rc03v9z7q-hello-opt-1.0.0.drv building '/nix/store/k6za2nx7jla6rwzs7lj1qm4rc03v9z7q-hello-opt-1.0.0.drv'... hello-opt-1.0.0> signing /nix/store/nbykbq9fy0z67hhlf1kvf8wk7wb29x59-hello-opt-1.0.0 hello-opt-1.0.0> patching script interpreter paths in /nix/store/nbykbq9fy0z67hhlf1kvf8wk7wb29x59-hello-opt-1.0.0/bin/hello Completed build of hello-opt-1.0.0 in local mode ✨ Build completed successfully. Output created: ./result-hello-opt ``` -------------------------------- ### Access Built Project Binary Source: https://flox.dev/docs/concepts/builds Provides an example of how to access the compiled binary of a project after a successful Flox build. It demonstrates navigating to the build output via a symlink. ```bash ./result-myproject/bin/myproject ``` -------------------------------- ### Flox 'on-activate' Hook Script Example (Bash) Source: https://flox.dev/docs/reference/command-reference/manifest Provides an example of an `on-activate` hook script in Bash for Flox environments. This script runs during environment activation, allowing for initialization tasks like setting environment variables, creating directories, and running commands. It inherits variables from `[vars]` and its output is redirected to stderr. ```bash [hook] on-activate = """ # Interact with the tty as you would in any script echo "Starting up $FLOX_ENV_DESCRIPTION environment ..." read -e -p "Favourite colour or favorite color? " value # Set variables, create files and directories venv_dir=\"$(mktemp -d)\" export venv_dir # Perform initialization steps, e.g. create a python venv python -m venv "$venv_dir" # Invoke apps that configure the environment via stdout eval \"$(ssh-agent)\""" ``` -------------------------------- ### Flox Python Environment Configuration Source: https://flox.dev/docs/cookbook/languages/python Shows a detailed configuration snippet for a Flox Python environment, including installation of Python, setup for a virtual environment, and activation hooks for different shells. ```nix [install] python3.pkg-path = "python3" python3.version = ">=3.8" [hook] on-activate = ''' # Setup a Python virtual environment export PYTHON_DIR="$FLOX_ENV_CACHE/python" if [ ! -d "$PYTHON_DIR" ]; then echo "Creating python virtual environment in $PYTHON_DIR" python -m venv "$PYTHON_DIR" fi # Quietly activate venv and install packages in a subshell so # that the venv can be freshly activated in the profile section. ( source "$PYTHON_DIR/bin/activate" # install the dependencies for this project based on pyproject.toml # pip install -e . --quiet ) ''' [profile] bash = ''' echo "Activating python virtual environment" >&2 source "$PYTHON_DIR/bin/activate" ''' fish = ''' echo "Activating python virtual environment" >&2 source "$PYTHON_DIR/bin/activate.fish" ''' tcsh = ''' echo "Activating python virtual environment" >&2 source "$PYTHON_DIR/bin/activate.csh" ''' zsh = ''' echo "Activating python virtual environment" >&2 source "$PYTHON_DIR/bin/activate" ''' ``` -------------------------------- ### Verify Node.js Version Source: https://flox.dev/docs/tutorials/migrations/nvm Checks the installed Node.js version within the active Flox environment. This command confirms that the correct Node.js version is accessible in the shell. ```bash node -v ``` -------------------------------- ### Example Build Definition in Flox Source: https://flox.dev/docs/reference/command-reference/manifest Defines a package named 'hello' that creates a file 'hello.txt' with 'Hello, World!' content. It utilizes a bash command within triple quotes for multi-line execution. ```flox [build.hello] command = ''' mkdir -p $out echo 'Hello, World!' >> $out/hello.txt ''' ``` -------------------------------- ### Flox Activation Command Example Source: https://flox.dev/docs/concepts/activation Demonstrates the command used to activate a Flox environment, which internally execs a Bash subshell. ```bash flox activate ``` -------------------------------- ### Initialize a new project with Flox Source: https://flox.dev/docs/tutorials/creating-environments Initializes a new Git repository and creates a Flox environment for the project. This sets up the basic structure for managing project dependencies. ```bash $ git init example-project && cd example-project Initialized empty Git repository in /Users/your-username/example-project/.git/ ``` ```bash $ flox init ✨ Created environment example-project (aarch64-darwin) Next: $ flox search <- Search for a package $ flox install <- Install a package into an environment $ flox activate <- Enter the environment ``` -------------------------------- ### Configure Shell for Default Environment Activation Source: https://flox.dev/docs/tutorials/default-environment Configures various shells (Bash, Zsh, Fish, Tcsh) to automatically activate the default Flox environment upon starting a new shell session. This ensures packages in the default environment are always available. ```bash eval "$(flox activate -d ~ -m run)" ``` ```zsh eval "$(flox activate -d ~ -m run)" ``` ```fish flox activate -d ~ -m run | source ``` ```tcsh eval "`flox activate -d ~ -m run`" ``` -------------------------------- ### Search for a Flox Package Source: https://flox.dev/docs/tutorials/build-and-publish Demonstrates how to search for a package named 'hello' using the `flox search` command. It displays a list of matching packages, including the one published by a user. ```bash flox [myproject] $ flox search hello myuser/hello My custom program printing hello world in Go hello Program that produces a familiar, friendly greeting hello-go Simple program printing hello world in Go hello-cpp Basic sanity check that C++ and cmake infrastructure are working nwg-hello GTK3-based greeter for the greetd daemon, written in python hello-unfree Example package with unfree license (for testing) hello-wayland Hello world Wayland client sbclPackages.hello-clog texlivePackages.othello Modification of a Go package to create othello boards sbclPackages.hello-builder Showing 10 of 23 results. Use `flox search hello --all` to see the full list. Use 'flox show ' to see available versions ``` -------------------------------- ### Verify Flox Installation (General) Source: https://flox.dev/docs/install-flox/install This command verifies if Flox is installed correctly. It should return the installed version number without any errors. This is a common step after any installation or upgrade. ```bash $ flox --version 1.7.3 ``` -------------------------------- ### View installed packages in a flox environment Source: https://flox.dev/docs/tutorials/composition Lists the packages installed in a specific flox environment, including those inherited from included environments. This helps verify that composition is working correctly. ```bash $ flox list -d composed_python_project poetry: poetry (2.1.1) python312: python312 (python3-3.12.9) ``` -------------------------------- ### Build 'hello' program with Flox Source: https://flox.dev/docs/tutorials/build-and-publish Executes the 'flox build' command to compile the 'hello' program. It shows the build process output and confirms successful completion, creating a 'result-hello' symbolic link. ```bash flox [myproject] $ flox build Rendering hello build script to /var/folders/qn/77rf0syj2s7djp588bzp5vkm0000gn/T//d6f2efa3-hello-build.bash Building hello-0.0.0 in local mode 00:00:00.004571 + go build 00:00:00.205192 + mkdir -p /tmp/store_d6f2efa321a606aebf3b41d0d96ace1d-hello-0.0.0/bin 00:00:00.207584 + cp hello /tmp/store_d6f2efa321a606aebf3b41d0d96ace1d-hello-0.0.0/bin/hello this derivation will be built: /nix/store/g3z03h4p2xa9rf6y78d0xamryggawvha-hello-0.0.0.drv building '/nix/store/g3z03h4p2xa9rf6y78d0xamryggawvha-hello-0.0.0.drv'... hello-0.0.0> patching script interpreter paths in /nix/store/2hc9mjxs6wqcd8cscw9ll650jv1k6wn1-hello-0.0.0/bin/hello Completed build of hello-0.0.0 in local mode ✨ Build completed successfully. Output created: ./result-hello ``` -------------------------------- ### Install prerequisites for OracleLinux Source: https://flox.dev/docs/install-flox/install Installs necessary packages for Flox installation on OracleLinux 8.5 using yum. ```shell sudo yum install tar xz ```