diff --git a/hosts/gerrit01/default.nix b/hosts/gerrit01/default.nix index 5527fb6..f2409b7 100755 --- a/hosts/gerrit01/default.nix +++ b/hosts/gerrit01/default.nix @@ -47,12 +47,13 @@ }; bagel.nixpkgs.one-way-sync = let - mkNixpkgsJob = { timer, branchName, localRefspec ? null }: { - name = "nixpkgs-${branchName}"; + mkNixpkgsJob = { timer, fromRefspec, localRefspec ? fromRefspec }: { fromUri = "https://github.com/NixOS/nixpkgs"; - fromRefspec = branchName; - localRefspec = if localRefspec != null then localRefspec else branchName; - inherit timer; + inherit fromRefspec localRefspec timer; + }; + mkLocalJob = { timer, fromRefspec, localRefspec }: { + fromUri = "https://cl.forkos.org/nixpkgs"; + inherit fromRefspec localRefspec timer; }; in { @@ -61,48 +62,59 @@ pushUrl = "ssh://ows_bot@cl.forkos.org:29418/nixpkgs"; deployKeyPath = config.age.secrets.ows-deploy-key.path; - branches."refs/heads/main" = mkNixpkgsJob { + # Sync main -> staging-next -> staging + branches."main-to-staging-next" = mkLocalJob { timer = "hourly"; - branchName = "master"; + fromRefspec = "main"; + localRefspec = "staging-next"; + }; + branches."staging-next-to-staging" = mkLocalJob { + timer = "hourly"; + fromRefspec = "staging-next"; + localRefspec = "staging"; + }; + + # Sync nixpkgs -> fork + branches."nixpkgs-master" = mkNixpkgsJob { + timer = "hourly"; + fromRefspec = "master"; localRefspec = "main"; }; - branches."refs/heads/staging" = mkNixpkgsJob { + branches."nixpkgs-staging" = mkNixpkgsJob { timer = "hourly"; - branchName = "staging"; + fromRefspec = "staging"; }; - branches."refs/heads/release-24.05" = mkNixpkgsJob { + branches."nixpkgs-release-24.05" = mkNixpkgsJob { timer = "hourly"; - branchName = "release-24.05"; + fromRefspec = "release-24.05"; }; - branches."refs/heads/staging-24.05" = mkNixpkgsJob { + branches."nixpkgs-staging-24.05" = mkNixpkgsJob { timer = "hourly"; - branchName = "staging-24.05"; + fromRefspec = "staging-24.05"; }; - branches."refs/heads/release-23.11" = mkNixpkgsJob { + branches."nixpkgs-release-23.11" = mkNixpkgsJob { timer = "hourly"; - branchName = "release-23.11"; + fromRefspec = "release-23.11"; }; - branches."refs/heads/staging-23.11" = mkNixpkgsJob { + branches."nixpkgs-staging-23.11" = mkNixpkgsJob { timer = "hourly"; - branchName = "staging-23.11"; + fromRefspec = "staging-23.11"; }; # Testing jobs for personal sandbox branches - branches."refs/heads/sandbox/raito/raito-unstable-small" = { - name = "raito-unstable-sync"; + branches."raito-unstable-sync" = { fromUri = "https://github.com/NixOS/nixpkgs"; fromRefspec = "nixos-unstable-small"; localRefspec = "sandbox/raito/raito-unstable-small"; timer = "*-*-* 12:00:00"; }; - branches."refs/heads/sandbox/raito/raito-nixos-24.05" = { - name = "raito-release-sync"; + branches."raito-release-sync" = { fromUri = "https://github.com/NixOS/nixpkgs"; fromRefspec = "nixos-24.05"; localRefspec = "sandbox/raito/raito-nixos-24.05"; diff --git a/services/gerrit/one-way-sync.nix b/services/gerrit/one-way-sync.nix index 250b59f..39570b0 100644 --- a/services/gerrit/one-way-sync.nix +++ b/services/gerrit/one-way-sync.nix @@ -3,7 +3,7 @@ let cfg = config.bagel.nixpkgs.one-way-sync; inherit (lib) mkIf mkOption mkEnableOption types mapAttrs'; - mkSyncTimer = { name, timer, ... }: { + mkSyncTimer = name: { timer, ... }: { wantedBy = [ "timers.target" ]; timerConfig = { @@ -12,7 +12,7 @@ let Unit = "ows-${name}.service"; }; }; - mkSyncService = targetRef: { name, fromUri, fromRefspec, localRefspec, ... }: { + mkSyncService = name: { fromUri, fromRefspec, localRefspec, ... }: { path = [ pkgs.gitFull pkgs.openssh pkgs.lix ]; script = '' set -xe @@ -25,7 +25,7 @@ let fi cd /var/lib/onewaysync/nixpkgs - echo "Syncing ${fromUri}:${fromRefspec} to /var/lib/onewaysync/nixpkgs:${targetRef}" + echo "Syncing ${fromUri}:${fromRefspec} to ${cfg.pushUrl}:refs/heads/${localRefspec}" echo "Current ref: $EXPECTED_REF" git worktree add -f "$RUNTIME_DIRECTORY"/${name} refs/remotes/origin/${localRefspec} cd "$RUNTIME_DIRECTORY"/${name} @@ -43,7 +43,7 @@ let # Do not allow auto-merging a staging iteration test "$OLD_STDENV" = "$NEW_STDENV" '' + '' - GIT_SSH_COMMAND='ssh -i ${cfg.deployKeyPath}' git push ${cfg.pushUrl} HEAD:${targetRef} + GIT_SSH_COMMAND='ssh -i ${cfg.deployKeyPath}' git push ${cfg.pushUrl} HEAD:refs/heads/${localRefspec} ''; serviceConfig = { User = "git"; @@ -120,12 +120,12 @@ in config = mkIf cfg.enable { systemd.timers = mapAttrs' (name: value: { - name = "ows-${value.name}"; - value = mkSyncTimer value; + name = "ows-${name}"; + value = mkSyncTimer name value; }) cfg.branches; systemd.services = mapAttrs' (name: value: { - name = "ows-${value.name}"; + name = "ows-${name}"; value = mkSyncService name value; }) cfg.branches; };