2026-10-08 11:41:37 -04:00
#
# Initial setup:
# doas -u nixworker env NIX_REMOTE='local?root=/.disk/root' RUST_BACKTRACE=1 RUST_LOG=nix_builder=DEBUG nix copy --from 'https://cache.nixos.org' /nix/store/4f7nm8dblrdy74gmsl62b25rjrh4jcz3-stage0-posix-1.9.1-source
#
2025-03-28 17:26:50 -04:00
{
config ,
lib ,
2026-01-11 16:38:56 -05:00
pkgs ,
2026-07-05 16:15:33 -04:00
nix_builder ,
2025-03-28 17:26:50 -04:00
. . .
} :
{
imports = [ ] ;
options . me = {
hydra . enable = lib . mkOption {
type = lib . types . bool ;
default = false ;
example = true ;
description = " W h e t h e r w e w a n t t o i n s t a l l h y d r a . " ;
} ;
} ;
2025-10-11 00:08:02 -04:00
config = lib . mkIf config . me . hydra . enable {
2026-01-11 16:38:56 -05:00
environment . systemPackages = with pkgs ; [
2026-07-05 16:15:33 -04:00
nix_builder . packages . x86_64-linux . default
2026-02-21 14:43:38 -05:00
sqlite # For manually inspecting the database.
2026-01-11 16:38:56 -05:00
] ;
environment . persistence . " / p e r s i s t " = lib . mkIf ( config . me . mountPersistence ) {
hideMounts = true ;
users . nixworker = {
directories = [
{
directory = " p e r s i s t " ;
user = " n i x w o r k e r " ;
group = " n i x w o r k e r " ;
mode = " 0 7 0 0 " ;
}
] ;
} ;
} ;
# Nix 2.30.0 (2025-07-07) changed the build directory from /tmp to /nix/var/nix/builds which broke a number of builds because my ZFS datasets were utf8only.
2026-04-03 07:55:23 -04:00
fileSystems . " / . d i s k / r o o t / n i x / v a r / n i x / b u i l d s " = {
2026-01-11 16:38:56 -05:00
device = " t m p f s " ;
fsType = " t m p f s " ;
options = [
2026-04-03 07:55:23 -04:00
" s i z e = 5 0 G " # adjust for your situation and needs
2026-01-11 16:38:56 -05:00
" m o d e = 7 0 0 "
" u i d = 1 1 4 0 0 "
" g i d = 1 1 4 0 0 "
] ;
2025-10-11 00:08:02 -04:00
} ;
2025-03-28 17:26:50 -04:00
2026-01-11 16:38:56 -05:00
systemd . timers . " b u i l d - c a c h e " = {
wantedBy = [ " t i m e r s . t a r g e t " ] ;
timerConfig = {
2026-02-21 14:43:38 -05:00
OnCalendar = " * - * - * 0 3 : 0 0 : 0 0 A m e r i c a / N e w _ Y o r k " ;
2026-01-11 16:38:56 -05:00
Unit = " b u i l d - c a c h e . s e r v i c e " ;
} ;
} ;
2026-06-23 15:08:44 -04:00
systemd . services . " b u i l d - c a c h e " =
let
enabled_targets = [
2026-10-06 17:42:47 -04:00
# "wip"
2026-06-23 15:08:44 -04:00
" o d o "
2026-10-06 17:42:47 -04:00
# "odo_update"
# "odowork"
# "odowork_update"
# "quark"
# "quark_update"
# "hydra"
# "hydra_update"
# "controller0"
# "controller0_update"
# "controller1"
# "controller1_update"
# "controller2"
# "controller2_update"
# "worker0"
# "worker0_update"
# "worker1"
# "worker1_update"
# "worker2"
# "worker2_update"
# "family_disks"
# "family_disks_update"
# "nixbsd"
# "nix_builder_develop"
# "organic_develop"
# "natter_develop"
2026-06-23 15:08:44 -04:00
] ;
build_flags = lib . concatMap ( target : [
" - - t a r g e t "
( lib . escapeShellArg target )
] ) enabled_targets ;
in
{
script = ''
set - euo pipefail
IFS = $ ' \ n \ t'
DIR = " $ ( c d " $ ( dirname " ' ' ${ BASH_SOURCE [ 0 ] } " ) " & & p w d ) "
2026-09-03 22:21:07 -04:00
NIX_REMOTE = ' local ? root = /.disk/root ' RUST_BACKTRACE = 1 RUST_LOG = nix_builder = DEBUG $ { nix_builder . packages . x86_64-linux . default } /bin/nix-builder clean - - config $ { ./files/nix_builder.toml }
2026-07-05 16:15:33 -04:00
NIX_REMOTE = ' local ? root = /.disk/root ' RUST_BACKTRACE = 1 RUST_LOG = nix_builder = DEBUG $ { nix_builder . packages . x86_64-linux . default } /bin/nix-builder build - - config $ { ./files/nix_builder.toml } $ { builtins . concatStringsSep " " build_flags }
2026-06-23 15:08:44 -04:00
'' ;
restartIfChanged = false ;
serviceConfig = {
Type = " s i m p l e " ;
User = " n i x w o r k e r " ;
# restartIfChanged = false;
# RemainAfterExit = true; # Prevents the service from automatically starting on rebuild. See https://discourse.nixos.org/t/how-to-prevent-custom-systemd-service-from-restarting-on-nixos-rebuild-switch/43431
LimitNOFILE = 8192 ;
} ;
2026-02-21 14:43:38 -05:00
} ;
# TODO: This should move into nix-builder so we can only run clean when builds are passing. Otherwise partial builds will lose progress.
# TODO: In nix-builder maybe include setting to auto delete to make room during builds if we run out of space, just in case builds are failing for a long time and prevent cleanup from running.
2026-06-23 15:08:44 -04:00
# systemd.timers."clean-cache" = {
# wantedBy = [ "timers.target" ];
# timerConfig = {
# OnCalendar = "*-*-01 02:00:00 America/New_York";
# Unit = "clean-cache.service";
# };
# };
2026-02-21 14:43:38 -05:00
systemd . services . " c l e a n - c a c h e " = {
script = ''
set - euo pipefail
IFS = $ ' \ n \ t'
DIR = " $ ( c d " $ ( dirname " ' ' ${ BASH_SOURCE [ 0 ] } " ) " & & p w d ) "
2026-04-03 07:55:23 -04:00
NIX_REMOTE = ' local ? root = /.disk/root ' nix-collect-garbage - d
2026-01-11 16:38:56 -05:00
'' ;
2026-02-21 14:43:38 -05:00
path = with pkgs ; [
pkgs . nix
] ;
2026-01-11 16:38:56 -05:00
restartIfChanged = false ;
serviceConfig = {
Type = " s i m p l e " ;
User = " n i x w o r k e r " ;
2026-02-21 14:43:38 -05:00
# restartIfChanged = false;
# RemainAfterExit = true; # Prevents the service from automatically starting on rebuild. See https://discourse.nixos.org/t/how-to-prevent-custom-systemd-service-from-restarting-on-nixos-rebuild-switch/43431
2026-01-11 16:38:56 -05:00
LimitNOFILE = 8192 ;
} ;
} ;
2025-10-11 00:08:02 -04:00
} ;
2025-03-28 17:26:50 -04:00
}