Skip to content

Commit

Permalink
Merge branch 'cachix:main' into logger/n8n
Browse files Browse the repository at this point in the history
  • Loading branch information
i-am-logger authored Jan 9, 2025
2 parents 8c87d38 + cc48e04 commit b24dc21
Show file tree
Hide file tree
Showing 47 changed files with 1,780 additions and 1,885 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -euo pipefail
nix build --print-out-paths --accept-flake-config || echo "nix build failed, using previous build"
PATH_add "result/bin"

# External users should use `source_url` to load this file
# External users should eval `devenv direnvrc` or use `source_url` to load this file
source_env ./direnvrc

use devenv
225 changes: 128 additions & 97 deletions .github/workflows/buildtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,62 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [[self-hosted, linux, X64], [macos-13], [self-hosted, macOS, ARM64], [self-hosted, linux, ARM64]]
os:
[
[self-hosted, linux, X64],
[macos-13],
[self-hosted, macOS, ARM64],
[self-hosted, linux, ARM64],
]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v30
with:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- uses: cachix/cachix-action@v15
with:
name: devenv
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- id: build
run: |
bin=$(nix build --print-out-paths)
echo "bin=$bin" >> $GITHUB_OUTPUT
- name: Run tests
run: ./result/bin/devenv test
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v30
with:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- uses: cachix/cachix-action@v15
with:
name: devenv
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
- id: build
run: |
bin=$(nix build --print-out-paths)
echo "bin=$bin" >> $GITHUB_OUTPUT
- name: Run tests
run: ./result/bin/devenv test

tests:
needs: build
strategy:
fail-fast: false
matrix:
os: [[self-hosted, linux, X64], [macos-13], [self-hosted, macOS, ARM64], [self-hosted, linux, ARM64]]
os:
[
[self-hosted, linux, X64],
[macos-13],
[self-hosted, macOS, ARM64],
[self-hosted, linux, ARM64],
]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v30
with:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- uses: cachix/cachix-action@v15
with:
name: devenv
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Build devenv
run: |
nix build
echo "$PWD/result/bin" >> $GITHUB_PATH
- name: Run devenv-test-cli
run: devenv shell devenv-test-cli
- name: Run tests
run: devenv-run-tests tests
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v30
with:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- uses: cachix/cachix-action@v15
with:
name: devenv
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
- name: Build devenv
run: |
nix build
echo "$PWD/result/bin" >> $GITHUB_PATH
- name: Run devenv-test-cli
run: devenv shell devenv-test-cli
- name: Run tests
run: devenv-run-tests tests

pin:
needs: build
Expand All @@ -69,95 +81,114 @@ jobs:
outputs:
examples: ${{ steps.set-examples.outputs.examples }}
steps:
- name: Checkout base repo
uses: actions/checkout@v4
- name: Fetch examples to run
id: set-examples
run: |
json=$(nix shell nixpkgs#tree -c tree -J -L 1 examples | nix shell nixpkgs#jq -c jq -c '[.[0].contents[] | .name]')
echo "examples=$json" >> $GITHUB_OUTPUT
- name: Checkout base repo
uses: actions/checkout@v4
- name: Fetch examples to run
id: set-examples
run: |
set -euxo pipefail
json=$(nix shell nixpkgs#tree -c tree -J -L 1 examples | nix shell nixpkgs#jq -c jq -c '[.[0].contents[] | .name]')
echo "examples=$json" >> $GITHUB_OUTPUT
examples:
name: ${{ matrix.example }} (${{ join(matrix.os) }})
needs: [generate-examples, build]
strategy:
fail-fast: false
matrix:
os: [[self-hosted, linux, X64], [macos-13], [self-hosted, macOS, ARM64], [self-hosted, linux, ARM64]]
os:
[
[self-hosted, linux, X64],
[macos-13],
[self-hosted, macOS, ARM64],
[self-hosted, linux, ARM64],
]
example: ${{ fromJSON(needs.generate-examples.outputs.examples) }}
runs-on: ${{ matrix.os }}
steps:
- run: sudo rm -rf /opt&
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v30
with:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- uses: cachix/cachix-action@v15
with:
name: devenv
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Build devenv
run: |
nix build
echo "$PWD/result/bin" >> $GITHUB_PATH
- name: Run examples
run: devenv-run-tests --only ${{ matrix.example }} examples
- run: sudo rm -rf /opt&
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v30
with:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- uses: cachix/cachix-action@v15
with:
name: devenv
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
- name: Build devenv
run: |
nix build
echo "$PWD/result/bin" >> $GITHUB_PATH
- name: Run examples
run: devenv-run-tests --only ${{ matrix.example }} examples

direnv:
name: direnv (${{ join(matrix.os) }})
needs: build
strategy:
fail-fast: false
matrix:
os: [[ubuntu-latest], [macos-13], [self-hosted, macOS, ARM64], [self-hosted, Linux, ARM64]]
os:
[
[ubuntu-latest],
[macos-13],
[self-hosted, macOS, ARM64],
[self-hosted, Linux, ARM64],
]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v30
with:
nix_path: nixpkgs=channel:nixos-unstable
- uses: cachix/cachix-action@v15
with:
name: devenv
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Build devenv
run: |
nix build
echo "$PWD/result/bin" >> $GITHUB_PATH
- run: |
mkdir -p ~/.config/direnv/
cat > ~/.config/direnv/direnv.toml << 'EOF'
[global]
strict_env = true
EOF
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v30
with:
nix_path: nixpkgs=channel:nixos-unstable
- uses: cachix/cachix-action@v15
with:
name: devenv
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
- name: Build devenv
run: |
nix build
echo "$PWD/result/bin" >> $GITHUB_PATH
- run: |
mkdir -p ~/.config/direnv/
cat > ~/.config/direnv/direnv.toml << 'EOF'
[global]
strict_env = true
EOF
devenv_dir=$PWD
tmp="$(mktemp -d)"
pushd "$tmp"
nix shell nixpkgs#direnv -c devenv --override-input devenv path:$devenv_dir?dir=src/modules init
popd
devenv_dir=$PWD
tmp="$(mktemp -d)"
pushd "$tmp"
nix shell nixpkgs#direnv -c devenv --override-input devenv path:$devenv_dir?dir=src/modules init
popd
fish-zsh:
name: zsh/fish (${{ join(matrix.os) }})
needs: build
strategy:
fail-fast: false
matrix:
os: [[ubuntu-latest], [macos-13], [self-hosted, macOS, ARM64], [self-hosted, linux, ARM64]]
os:
[
[ubuntu-latest],
[macos-13],
[self-hosted, macOS, ARM64],
[self-hosted, linux, ARM64],
]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v30
with:
nix_path: nixpkgs=channel:nixos-unstable
- uses: cachix/cachix-action@v15
with:
name: devenv
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Build devenv
run: nix build
- name: Test devenv in fish and zsh
run: |
nix shell nixpkgs#zsh -c zsh -c "./result/bin/devenv version"
nix shell nixpkgs#fish -c fish -c "./result/bin/devenv version"
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v30
with:
nix_path: nixpkgs=channel:nixos-unstable
- uses: cachix/cachix-action@v15
with:
name: devenv
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
- name: Build devenv
run: nix build
- name: Test devenv in fish and zsh
run: |
nix shell nixpkgs#zsh -c zsh -c "./result/bin/devenv version"
nix shell nixpkgs#fish -c fish -c "./result/bin/devenv version"
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions devenv-eval-cache/src/db.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use super::command::FilePath;
use sqlx::sqlite::{Sqlite, SqliteConnectOptions, SqliteJournalMode, SqliteRow, SqliteSynchronous};
use sqlx::{Acquire, Row, SqlitePool};
use sqlx::{migrate::MigrateDatabase, Acquire, Row, SqlitePool};
use std::ffi::OsStr;
use std::os::unix::ffi::OsStrExt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::{SystemTime, UNIX_EPOCH};
use tracing::error;

pub async fn setup_db<P: AsRef<str>>(database_url: P) -> Result<SqlitePool, sqlx::Error> {
let conn_options = SqliteConnectOptions::from_str(database_url.as_ref())?
Expand All @@ -19,7 +20,14 @@ pub async fn setup_db<P: AsRef<str>>(database_url: P) -> Result<SqlitePool, sqlx

let pool = SqlitePool::connect_with(conn_options).await?;

sqlx::migrate!("./migrations").run(&pool).await?;
if let Err(err) = sqlx::migrate!().run(&pool).await {
error!(error = %err, "Failed to migrate the Nix evaluation cache database. Attempting to recreate the database.");

// Delete the database and rerun the migrations
Sqlite::drop_database(database_url.as_ref()).await?;

sqlx::migrate!().run(&pool).await?;
}

Ok(pool)
}
Expand Down
Loading

0 comments on commit b24dc21

Please sign in to comment.