1/* 2 3 This file is for options that NixOS and nix-darwin have in common. 4 5 Platform-specific code is in the respective default.nix files. 6 7*/ 8 9{ config, lib, options, pkgs, ... }: 10let 11 inherit (lib) 12 filterAttrs 13 literalExpression 14 mkIf 15 mkOption 16 mkRemovedOptionModule 17 mkRenamedOptionModule 18 types 19 mkPackageOption 20 ; 21 22 cfg = config.services.hercules-ci-agent; 23 24 inherit (import ./settings.nix { inherit pkgs lib; }) format settingsModule; 25 26in 27{ 28 imports = [ 29 (mkRenamedOptionModule [ "services" "hercules-ci-agent" "extraOptions" ] [ "services" "hercules-ci-agent" "settings" ]) 30 (mkRenamedOptionModule [ "services" "hercules-ci-agent" "baseDirectory" ] [ "services" "hercules-ci-agent" "settings" "baseDirectory" ]) 31 (mkRenamedOptionModule [ "services" "hercules-ci-agent" "concurrentTasks" ] [ "services" "hercules-ci-agent" "settings" "concurrentTasks" ]) 32 (mkRemovedOptionModule [ "services" "hercules-ci-agent" "patchNix" ] "Nix versions packaged in this version of Nixpkgs don't need a patched nix-daemon to work correctly in Hercules CI Agent clusters.") 33 ]; 34 35 options.services.hercules-ci-agent = { 36 enable = mkOption { 37 type = types.bool; 38 default = false; 39 description = '' 40 Enable to run Hercules CI Agent as a system service. 41 42 [Hercules CI](https://hercules-ci.com) is a 43 continuous integation service that is centered around Nix. 44 45 Support is available at [help@hercules-ci.com](mailto:help@hercules-ci.com). 46 ''; 47 }; 48 package = mkPackageOption pkgs "hercules-ci-agent" { }; 49 settings = mkOption { 50 description = '' 51 These settings are written to the `agent.toml` file. 52 53 Not all settings are listed as options, can be set nonetheless. 54 55 For the exhaustive list of settings, see <https://docs.hercules-ci.com/hercules-ci/reference/agent-config/>. 56 ''; 57 type = types.submoduleWith { modules = [ settingsModule ]; }; 58 }; 59 60 /* 61 Internal and/or computed values. 62 63 These are written as options instead of let binding to allow sharing with 64 default.nix on both NixOS and nix-darwin. 65 */ 66 tomlFile = mkOption { 67 type = types.path; 68 internal = true; 69 defaultText = lib.literalMD "generated `hercules-ci-agent.toml`"; 70 description = '' 71 The fully assembled config file. 72 ''; 73 }; 74 }; 75 76 config = mkIf cfg.enable { 77 # Make sure that nix.extraOptions does not override trusted-users 78 assertions = [ 79 { 80 assertion = 81 (cfg.settings.nixUserIsTrusted or false) -> 82 builtins.match ".*(^|\n)[ \t]*trusted-users[ \t]*=.*" config.nix.extraOptions == null; 83 message = '' 84 hercules-ci-agent: Please do not set `trusted-users` in `nix.extraOptions`. 85 86 The hercules-ci-agent module by default relies on `nix.settings.trusted-users` 87 to be effectful, but a line like `trusted-users = ...` in `nix.extraOptions` 88 will override the value set in `nix.settings.trusted-users`. 89 90 Instead of setting `trusted-users` in the `nix.extraOptions` string, you should 91 set an option with additive semantics, such as 92 - the NixOS option `nix.settings.trusted-users`, or 93 - the Nix option in the `extraOptions` string, `extra-trusted-users` 94 ''; 95 } 96 ]; 97 nix.extraOptions = '' 98 # A store path that was missing at first may well have finished building, 99 # even shortly after the previous lookup. This *also* applies to the daemon. 100 narinfo-cache-negative-ttl = 0 101 ''; 102 services.hercules-ci-agent = { 103 tomlFile = 104 format.generate "hercules-ci-agent.toml" cfg.settings; 105 settings.config._module.args = { 106 packageOption = options.services.hercules-ci-agent.package; 107 inherit pkgs; 108 }; 109 }; 110 }; 111}