Skip to content

Commit

Permalink
Merge pull request #182 from cachix/support-daemon-push-filter
Browse files Browse the repository at this point in the history
Support path filtering when using the daemon
  • Loading branch information
domenkozar authored Apr 26, 2024
2 parents ef8d8a4 + 5ee8857 commit 74587ee
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
17 changes: 16 additions & 1 deletion dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7957,11 +7957,26 @@ async function execToVariable(command, args, options) {
async function registerPostBuildHook(cachixBin, daemonDir) {
const postBuildHookScriptPath = `${daemonDir}/post-build-hook.sh`;
await fs.writeFile(postBuildHookScriptPath, `
#!/bin/sh
#!/usr/bin/env bash
set -eu
set -f # disable globbing
PUSH_FILTER="${pushFilter}"
filterPaths() {
local regex=$1
local paths=$2
for path in $paths; do
echo $path | grep -vEe $regex
done | xargs
}
if [ -n "$PUSH_FILTER" ]; then
OUT_PATHS=$(filterPaths $PUSH_FILTER "$OUT_PATHS")
fi
exec ${cachixBin} daemon push \
--socket ${daemonDir}/daemon.sock \
$OUT_PATHS
Expand Down
15 changes: 12 additions & 3 deletions dist/main/push-paths.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@ set -euo pipefail

cachix=$1 cachixArgs=${2:--j8} cache=$3 pathsToPush=$4 pushFilter=$5

if [[ $pathsToPush == "" ]]; then
filterPaths() {
local regex=$1
local paths=$2

for path in $paths; do
echo $path | grep -vEe $regex
done | xargs
}

if [[ -z $pathsToPush ]]; then
pathsToPush=$(comm -13 <(sort /tmp/store-path-pre-build) <("$(dirname "$0")"/list-nix-store.sh))

if [[ $pushFilter != "" ]]; then
pathsToPush=$(echo "$pathsToPush" | grep -vEe "$pushFilter")
if [[ -n $pushFilter ]]; then
pathsToPush=$(filterPaths $pushFilter "$pathsToPush")
fi
fi

Expand Down
17 changes: 16 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,26 @@ async function execToVariable(command: string, args?: string[], options?: exec.E
async function registerPostBuildHook(cachixBin: string, daemonDir: string) {
const postBuildHookScriptPath = `${daemonDir}/post-build-hook.sh`;
await fs.writeFile(postBuildHookScriptPath, `
#!/bin/sh
#!/usr/bin/env bash
set -eu
set -f # disable globbing
PUSH_FILTER="${pushFilter}"
filterPaths() {
local regex=$1
local paths=$2
for path in $paths; do
echo $path | grep -vEe $regex
done | xargs
}
if [ -n "$PUSH_FILTER" ]; then
OUT_PATHS=$(filterPaths $PUSH_FILTER "$OUT_PATHS")
fi
exec ${cachixBin} daemon push \
--socket ${daemonDir}/daemon.sock \
$OUT_PATHS
Expand Down

0 comments on commit 74587ee

Please sign in to comment.