added build script

This commit is contained in:
emily 2024-01-15 21:00:21 +01:00
parent 34a674872f
commit dd2eec1797
Signed by: emily
GPG key ID: F6F4C66207FCF995

View file

@ -30,18 +30,18 @@
};
packages.default = packages.kyouma-www;
nixosModules.default =
{ config, options, pkgs, ... }:
{ config, options, pkgs, ... }: with lib;
let
cfg = config.services.vyosBld;
buildFlags = (attrsets.mapAttrsToList (flag: opt: "--" + flag + " " + opt) cfg.buildFlags);
bldFlags = (attrsets.mapAttrsToList (flag: opt: "--" + flag + " " + opt) cfg.buildFlags);
in {
options.services.vyosBld = with lib; {
options.services.vyosBld = {
enable = mkEnableOption "VyOS automatic build";
output = mkOption {
type = types.str;
default = null;
description = "Where the iso should be copied to";
description = "Where the iso should be copied";
};
keep = mkOption {
@ -63,7 +63,7 @@
};
buildFlags = mkOption {
type = types.set;
type = types.attrs;
default = "";
description = "Build Flags see https://docs.vyos.io/en/latest/contributing/build-vyos.html
example:
@ -71,7 +71,30 @@
};
};
config = with lib; mkIf cfg.enable rec {
bldScript = pkgs.copyPathToStore ./vybld.nix;
bldScript = writeShellScrip "build-vyos" ''
cleanup() {
rmdir "$root"
}
root="$(mktemp -d)"
trap cleanup EXIT
iso_name="vyos-${cfg.buildFlags.version}-${cfg.buildFlags.architecture}.iso"
bld_dir="$root/vyos-build"
git clone -b current --single-branch https://github.com/vyos/vyos-build $root
docker run --rm -it --privileged -v $bld_dir:/vyos -w /vyos vyos/vyos-build:current /usr/bin/sudo ./build-vyos-image ${flavor} ${builtins.concatStringsSep " " bldFlags}
docker run --rm -it --privileged -v $bld_dir:/vyos -w /vyos vyos/vyos-build:current sudo chown -R ${config.users.users.vyos-bld.uid}:${config.users.groups.vyos-bld.uid}
cp $bld_dir/build/$iso_name ${cfg.output}
mapfile -t old_isos < <(ls ${cfg.output} | head -n -${cfg.keep})
for i in $\{old_isos[@]}; do
rm -r ${cfg.output}/$\{old_iso[$i]}
done
'';
virtualisation.docker.rootless = {
enable = true;
setSocketVariable = true;
};
systemd.services.vyosBld = {
wantedBy = [ "multi-user.target" ];