added build script
This commit is contained in:
parent
34a674872f
commit
dd2eec1797
1 changed files with 29 additions and 6 deletions
35
flake.nix
35
flake.nix
|
@ -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" ];
|
||||
|
|
Loading…
Reference in a new issue