From 62ccc0282b4058d8547df66aefe4333705dfa4b1 Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Mon, 22 Jul 2024 15:41:47 +0200 Subject: [PATCH] fix(ows): per-job runtime directories + proper local refspec The local refspec was weird and exploiting a edge case for the nixpkgs jobs where local and from were the same. We are more explicit now, which fixes the sandbox jobs. Signed-off-by: Raito Bezarius --- hosts/gerrit01/default.nix | 6 +++--- services/gerrit/one-way-sync.nix | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/hosts/gerrit01/default.nix b/hosts/gerrit01/default.nix index de3a056..806dc8b 100755 --- a/hosts/gerrit01/default.nix +++ b/hosts/gerrit01/default.nix @@ -51,7 +51,7 @@ name = "nixpkgs-${branchName}"; fromUri = "https://github.com/NixOS/nixpkgs"; fromRefspec = branchName; - localRefspec = "refs/remotes/origin/${branchName}"; + localRefspec = branchName; inherit timer; }; in @@ -81,7 +81,7 @@ name = "raito-unstable-sync"; fromUri = "https://github.com/NixOS/nixpkgs"; fromRefspec = "nixos-unstable-small"; - localRefspec = "refs/remotes/origin/sandbox/raito/raito-unstable-small"; + localRefspec = "sandbox/raito/raito-unstable-small"; timer = "*-*-* 12:00:00"; }; @@ -89,7 +89,7 @@ name = "raito-release-sync"; fromUri = "https://github.com/NixOS/nixpkgs"; fromRefspec = "nixos-24.05"; - localRefspec = "refs/remotes/origin/sandbox/raito/raito-nixos-24.05"; + localRefspec = "sandbox/raito/raito-nixos-24.05"; timer = "daily"; }; }; diff --git a/services/gerrit/one-way-sync.nix b/services/gerrit/one-way-sync.nix index 4ace69a..c8248c5 100644 --- a/services/gerrit/one-way-sync.nix +++ b/services/gerrit/one-way-sync.nix @@ -16,7 +16,8 @@ let path = [ pkgs.gitFull pkgs.openssh pkgs.lix ]; script = '' set -xe - trap "git worktree prune && git worktree remove -f ${name}" EXIT + RUNTIME_DIRECTORY="/run/onewaysync-${name}" + trap "git worktree remove -f "$RUNTIME_DIRECTORY"/${name}" EXIT if [ ! -d "/var/lib/onewaysync/nixpkgs" ]; then echo "First run, synchronizing nixpkgs..." @@ -26,19 +27,19 @@ let cd /var/lib/onewaysync/nixpkgs echo "Syncing ${fromUri}:${fromRefspec} to /var/lib/onewaysync/nixpkgs:${targetRef}" echo "Current ref: $EXPECTED_REF" - git worktree add -f ${cfg.workingDir}/${name} ${localRefspec} - cd ${cfg.workingDir}/${name} - git pull origin ${fromRefspec} - EXPECTED_REF=$(git rev-list ${localRefspec} | head -1) + git worktree add -f "$RUNTIME_DIRECTORY"/${name} refs/remotes/origin/${localRefspec} + cd "$RUNTIME_DIRECTORY"/${name} + git pull origin ${localRefspec} + EXPECTED_REF=$(git rev-list refs/remotes/origin/${localRefspec} | head -1) git config user.name Fork-o-Tron git config user.email noreply@forkos.org git fetch ${fromUri} ${fromRefspec} '' + lib.optionalString (!(lib.hasInfix "staging" localRefspec)) '' - OLD_STDENV=$(nix eval -f . stdenv.outPath --store /run/onewaysync) + OLD_STDENV=$(nix eval -f . stdenv.outPath --store "$RUNTIME_DIRECTORY") '' + '' git merge FETCH_HEAD '' + lib.optionalString (!(lib.hasInfix "staging" localRefspec)) '' - NEW_STDENV=$(nix eval -f . stdenv.outPath --store /run/onewaysync) + NEW_STDENV=$(nix eval -f . stdenv.outPath --store "$RUNTIME_DIRECTORY") # Do not allow auto-merging a staging iteration test "$OLD_STDENV" = "$NEW_STDENV" '' + '' @@ -48,8 +49,8 @@ let User = "git"; Group = "git"; Type = "oneshot"; - RuntimeDirectory = "onewaysync"; - WorkingDirectory = cfg.workingDir; + RuntimeDirectory = "onewaysync-${name}"; + WorkingDirectory = "/run/onewaysync-${name}"; StateDirectory = "onewaysync"; }; };