Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ func Read(path string) (config types.Configuration, err error) {

func MkGitConfig(config types.Configuration) types.GitConfig {
return types.GitConfig{
Path: filepath.Join(config.StateDir, "repository"),
Dir: config.FlakeSubdirectory,
Remotes: config.Remotes,
GpgPublicKeyPaths: config.GpgPublicKeyPaths,
Path: filepath.Join(config.StateDir, "repository"),
Dir: config.FlakeSubdirectory,
Remotes: config.Remotes,
GpgPublicKeyPaths: config.GpgPublicKeyPaths,
AllowForcePushMain: config.AllowForcePushMain,
}
}
6 changes: 5 additions & 1 deletion internal/repository/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ func getHeadFromRemoteAndBranch(r repository, remoteName, branchName, currentMai
}

if err = hasNotBeenHardReset(r, branchName, currentMainHash, head); err != nil {
return
if r.GitConfig.AllowForcePushMain {
logrus.Infof("Force-push detected but ignored due to 'allowForcePushMain' being set")
} else {
return
}
}

commitObject, err := r.Repository.CommitObject(*head)
Expand Down
8 changes: 5 additions & 3 deletions internal/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ type GitConfig struct {
// The repository Path
Path string
// The directory in the repository
Dir string
Remotes []Remote
GpgPublicKeyPaths []string
Dir string
Remotes []Remote
GpgPublicKeyPaths []string
AllowForcePushMain bool
}

type Auth struct {
Expand Down Expand Up @@ -59,4 +60,5 @@ type Configuration struct {
Exporter HttpServer `yaml:"exporter"`
GpgPublicKeyPaths []string `yaml:"gpg_public_key_paths"`
PostDeploymentCommand string `yaml:"post_deployment_command"`
AllowForcePushMain bool `yaml:"allow_force_push_main"`
}
23 changes: 18 additions & 5 deletions nix/module-options.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{ config, pkgs, lib, ... }: {
options = with lib; with types; {
{
config,
pkgs,
lib,
...
}: {
options = with lib;
with types; {
services.comin = {
enable = mkOption {
type = types.bool;
Expand All @@ -8,9 +14,11 @@
Whether to run the comin service.
'';
};
package = lib.mkPackageOption pkgs "comin" { nullable = true; } // {
defaultText = "pkgs.comin or comin.packages.\${system}.default or null";
};
package =
lib.mkPackageOption pkgs "comin" {nullable = true;}
// {
defaultText = "pkgs.comin or comin.packages.\${system}.default or null";
};
hostname = mkOption {
type = str;
default = config.networking.hostName;
Expand Down Expand Up @@ -189,6 +197,11 @@
pkgs.writers.writeBash "post" "echo $COMIN_GIT_SHA";
'';
};
allowForcePushMain = mkOption {
description = "Switch to configuration even when a force-push was detected on main.";
type = bool;
default = false;
};
};
};
}
16 changes: 14 additions & 2 deletions nix/module.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
{ self }: { config, pkgs, lib, ... }:
let
cfg = config;
cominConfigLib = import ./comin-config.nix { inherit config pkgs lib; };
inherit (cominConfigLib) cominConfig cominConfigYaml;
yaml = pkgs.formats.yaml { };
cominConfig = {
hostname = cfg.services.comin.hostname;
state_dir = "/var/lib/comin";
flake_subdirectory = cfg.services.comin.flakeSubdirectory;
remotes = cfg.services.comin.remotes;
exporter = {
listen_address = cfg.services.comin.exporter.listen_address;
port = cfg.services.comin.exporter.port;
};
gpg_public_key_paths = cfg.services.comin.gpgPublicKeyPaths;
allow_force_push_main = cfg.services.comin.allowForcePushMain;
};
cominConfigYaml = yaml.generate "comin.yaml" cominConfig;

inherit (pkgs.stdenv.hostPlatform) system;
inherit (cfg.services.comin) package;
Expand Down