From 345c054448f47eb00e8b7f8d34224d2c3b5afb96 Mon Sep 17 00:00:00 2001 From: derped Date: Sat, 14 Dec 2019 07:46:00 +0100 Subject: [PATCH] nix-serve should no longer use the default store. Move binaryCaches into the machine submodule. --- config/nix.nix | 12 ++++++------ options/machine.nix | 7 +++++++ services/hydra.nix | 9 ++++++--- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/config/nix.nix b/config/nix.nix index a8d854a..058747e 100644 --- a/config/nix.nix +++ b/config/nix.nix @@ -1,6 +1,8 @@ { config, lib, ... }: -{ +let + cfg = config.machine; +in { nix = { maxJobs = 4; buildCores = 1; @@ -9,14 +11,12 @@ extraOptions = '' build-timeout = 86400 # 24 hours ''; - binaryCachePublicKeys = [ (lib.fileContents "${config.machine.secretPath}/hydra_cache.pub") ]; + binaryCachePublicKeys = [ (lib.fileContents "${cfg.secretPath}/hydra_cache.pub") ]; trustedBinaryCaches = [ "https://cache.nixos.org" - "https://cache.ophanim.de" - ]; + ] ++ cfg.binaryCaches; binaryCaches = [ "https://cache.nixos.org" - "https://cache.ophanim.de" - ]; + ] ++ cfg.binaryCaches; }; } diff --git a/options/machine.nix b/options/machine.nix index 66f089a..322cde6 100644 --- a/options/machine.nix +++ b/options/machine.nix @@ -59,6 +59,13 @@ in { The Machines HostName ''; }; + binaryCaches = mkOption { + type = types.listOf types.str; + default = []; + description = '' + Adds binary caches to both nix.trustedBinaryCaches and nix.binaryCaches. ("https://cache.nixos.org" is kept by default) + ''; + }; secretPath = mkOption { type = types.str; default = (findFirst (elem: elem.prefix == "secretPath") { path = "/secret"; } builtins.nixPath).path; diff --git a/services/hydra.nix b/services/hydra.nix index 89a6ae8..39604db 100644 --- a/services/hydra.nix +++ b/services/hydra.nix @@ -10,7 +10,9 @@ with lib; -mkIf (elem "hydra" config.machine.services) { +let + cacheDir = "/var/cache/hydra"; +in mkIf (elem "hydra" config.machine.services) { # also take a look at ../conf/nix.nix nix.buildMachines = [ { @@ -40,7 +42,7 @@ mkIf (elem "hydra" config.machine.services) { # hydra.conf: binary_cache_secret_key_file is deprecated and ignored. use store_uri=...?secret-key= instead extraConfig = '' max_output_size = 4294967296 - store_uri = file:///var/cache/hydra?secret-key=${cfg.secretPath}/hydra_cache&write-nar-listing=1&ls-compression=br&log-compression=br + store_uri = file://${cacheDir}?secret-key=${cfg.secretPath}/hydra_cache&write-nar-listing=1&ls-compression=br&log-compression=br # add ?local-nar-cache= to set nar cache location server_store_uri = https://cache.${cfg.domain} binary_cache_public_uri https://cache.${cfg.domain} @@ -59,5 +61,6 @@ mkIf (elem "hydra" config.machine.services) { # --group hydra ''; }; - }; + }; + systemd.services.nix-serve.environment.NIX_STORE_DIR = cacheDir; }