mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-28 08:33:54 +00:00
4a9d9928dc
The `nix.*` options, apart from options for setting up the daemon itself, currently provide a lot of setting mappings for the Nix daemon configuration. The scope of the mapping yields convience, but the line where an option is considered essential is blurry. For instance, the `extra-sandbox-paths` mapping is provided without its primary consumer, and the corresponding `sandbox-paths` option is also not mapped. The current system increases the maintenance burden as maintainers have to closely follow upstream changes. In this case, there are two state versions of Nix which have to be maintained collectively, with different options avaliable. This commit aims to following the standard outlined in RFC 42[1] to implement a structural setting pattern. The Nix configuration is encoded at its core as key-value pairs which maps nicely to attribute sets, making it feasible to express in the Nix language itself. Some existing options are kept such as `buildMachines` and `registry` which present a simplified interface to managing the respective settings. The interface is exposed as `nix.settings`. Legacy configurations are mapped to their corresponding options under `nix.settings` for backwards compatibility. Various options settings in other nixos modules and relevant tests have been updated to use structural setting for consistency. The generation and validation of the configration file has been modified to use `writeTextFile` instead of `runCommand` for clarity. Note that validation is now mandatory as strict checking of options has been pushed down to the derivation level due to freeformType consuming unmatched options. Furthermore, validation can not occur when cross-compiling due to current limitations. A new option `publicHostKey` was added to the `buildMachines` submodule corresponding to the base64 encoded public host key settings exposed in the builder syntax. The build machine generation was subsequently rewritten to use `concatStringsSep` for better performance by grouping concatenations. [1] - https://github.com/NixOS/rfcs/blob/master/rfcs/0042-config-option.md
102 lines
3.3 KiB
Nix
102 lines
3.3 KiB
Nix
/*
|
|
|
|
This file is for NixOS-specific options and configs.
|
|
|
|
Code that is shared with nix-darwin goes in common.nix.
|
|
|
|
*/
|
|
|
|
{ pkgs, config, lib, ... }:
|
|
let
|
|
inherit (lib) mkIf mkDefault;
|
|
|
|
cfg = config.services.hercules-ci-agent;
|
|
|
|
command = "${cfg.package}/bin/hercules-ci-agent --config ${cfg.tomlFile}";
|
|
testCommand = "${command} --test-configuration";
|
|
|
|
in
|
|
{
|
|
imports = [
|
|
./common.nix
|
|
(lib.mkRenamedOptionModule [ "services" "hercules-ci-agent" "user" ] [ "systemd" "services" "hercules-ci-agent" "serviceConfig" "User" ])
|
|
];
|
|
|
|
config = mkIf cfg.enable {
|
|
systemd.services.hercules-ci-agent = {
|
|
wantedBy = [ "multi-user.target" ];
|
|
after = [ "network-online.target" ];
|
|
wants = [ "network-online.target" ];
|
|
path = [ config.nix.package ];
|
|
startLimitBurst = 30 * 1000000; # practically infinite
|
|
serviceConfig = {
|
|
User = "hercules-ci-agent";
|
|
ExecStart = command;
|
|
ExecStartPre = testCommand;
|
|
Restart = "on-failure";
|
|
RestartSec = 120;
|
|
};
|
|
};
|
|
|
|
# Changes in the secrets do not affect the unit in any way that would cause
|
|
# a restart, which is currently necessary to reload the secrets.
|
|
systemd.paths.hercules-ci-agent-restart-files = {
|
|
wantedBy = [ "hercules-ci-agent.service" ];
|
|
pathConfig = {
|
|
Unit = "hercules-ci-agent-restarter.service";
|
|
PathChanged = [ cfg.settings.clusterJoinTokenPath cfg.settings.binaryCachesPath ];
|
|
};
|
|
};
|
|
systemd.services.hercules-ci-agent-restarter = {
|
|
serviceConfig.Type = "oneshot";
|
|
script = ''
|
|
# Wait a bit, with the effect of bundling up file changes into a single
|
|
# run of this script and hopefully a single restart.
|
|
sleep 10
|
|
if systemctl is-active --quiet hercules-ci-agent.service; then
|
|
if ${testCommand}; then
|
|
systemctl restart hercules-ci-agent.service
|
|
else
|
|
echo 1>&2 "WARNING: Not restarting agent because config is not valid at this time."
|
|
fi
|
|
else
|
|
echo 1>&2 "Not restarting hercules-ci-agent despite config file update, because it is not already active."
|
|
fi
|
|
'';
|
|
};
|
|
|
|
# Trusted user allows simplified configuration and better performance
|
|
# when operating in a cluster.
|
|
nix.settings.trusted-users = [ config.systemd.services.hercules-ci-agent.serviceConfig.User ];
|
|
services.hercules-ci-agent = {
|
|
settings = {
|
|
nixUserIsTrusted = true;
|
|
labels =
|
|
let
|
|
mkIfNotNull = x: mkIf (x != null) x;
|
|
in
|
|
{
|
|
nixos.configurationRevision = mkIfNotNull config.system.configurationRevision;
|
|
nixos.release = config.system.nixos.release;
|
|
nixos.label = mkIfNotNull config.system.nixos.label;
|
|
nixos.codeName = config.system.nixos.codeName;
|
|
nixos.tags = config.system.nixos.tags;
|
|
nixos.systemName = mkIfNotNull config.system.name;
|
|
};
|
|
};
|
|
};
|
|
|
|
users.users.hercules-ci-agent = {
|
|
home = cfg.settings.baseDirectory;
|
|
createHome = true;
|
|
group = "hercules-ci-agent";
|
|
description = "Hercules CI Agent system user";
|
|
isSystemUser = true;
|
|
};
|
|
|
|
users.groups.hercules-ci-agent = { };
|
|
};
|
|
|
|
meta.maintainers = [ lib.maintainers.roberth ];
|
|
}
|