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;
|
packages.default = packages.kyouma-www;
|
||||||
nixosModules.default =
|
nixosModules.default =
|
||||||
{ config, options, pkgs, ... }:
|
{ config, options, pkgs, ... }: with lib;
|
||||||
let
|
let
|
||||||
cfg = config.services.vyosBld;
|
cfg = config.services.vyosBld;
|
||||||
buildFlags = (attrsets.mapAttrsToList (flag: opt: "--" + flag + " " + opt) cfg.buildFlags);
|
bldFlags = (attrsets.mapAttrsToList (flag: opt: "--" + flag + " " + opt) cfg.buildFlags);
|
||||||
in {
|
in {
|
||||||
options.services.vyosBld = with lib; {
|
options.services.vyosBld = {
|
||||||
enable = mkEnableOption "VyOS automatic build";
|
enable = mkEnableOption "VyOS automatic build";
|
||||||
|
|
||||||
output = mkOption {
|
output = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = null;
|
default = null;
|
||||||
description = "Where the iso should be copied to";
|
description = "Where the iso should be copied";
|
||||||
};
|
};
|
||||||
|
|
||||||
keep = mkOption {
|
keep = mkOption {
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
buildFlags = mkOption {
|
buildFlags = mkOption {
|
||||||
type = types.set;
|
type = types.attrs;
|
||||||
default = "";
|
default = "";
|
||||||
description = "Build Flags see https://docs.vyos.io/en/latest/contributing/build-vyos.html
|
description = "Build Flags see https://docs.vyos.io/en/latest/contributing/build-vyos.html
|
||||||
example:
|
example:
|
||||||
|
@ -71,7 +71,30 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
config = with lib; mkIf cfg.enable rec {
|
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 = {
|
systemd.services.vyosBld = {
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
|
Loading…
Reference in a new issue