Add basic systemd service to build configs

This commit is contained in:
Malte Tammena 2021-11-06 09:57:25 +01:00
parent 12945f91f0
commit 2eeb1a5fc1
2 changed files with 44 additions and 0 deletions

View file

@ -82,6 +82,7 @@
nix.extraOptions = ''
experimental-features = nix-command flakes
'';
nixpkgs.overlays = [ (self: super: { nix = super.nixUnstable; }) ];
};
# Some basics that every machine should have
@ -193,6 +194,7 @@
self.nixosModules.x86_64-linux-basics
./hosts/elysia-clarki.nix
./hardware/intel-nuc.nix
./modules/local-build-service.nix
#./modules/nginx-reverse-proxy.nix
#./modules/binary-cache.nix

View file

@ -0,0 +1,42 @@
{ pkgs, ... }:
let
targetHosts = [ "helix-texta" "elysia-clarki" ];
remote = "https://git.sr.ht/~megamanmalte/nixos";
buildForHost = host:
with pkgs; ''
nixos-rebuild build --flake .#${host} || exit 1
'';
build = with pkgs;
writeScriptBin "build" ''
#!${stdenv.shell}
rm -rf nixos
git clone ${remote} || exit 2
cd nixos
${builtins.concatStringsSep "\n" (map buildForHost targetHosts)}
rm result
'';
in {
systemd.services.local-build-service = {
unitConfig = {
Description = ''
Regularly pull and build various configuration to populate the local store
'';
After = [ "network.target" ];
};
serviceConfig = {
Type = "oneshot";
ExecStart = [ "${build}/bin/build" ];
RuntimeDirectory = "local-build-service";
CacheDirectory = "local-build-service";
CacheDirectoryMode = "0777";
Environment = with pkgs;
"PATH=${git}/bin:${coreutils}/bin:${nixos-rebuild}/bin";
};
};
}