add custom nixos install iso
This commit is contained in:
@@ -10,5 +10,6 @@
|
||||
./minecraft-server
|
||||
./monitoring
|
||||
./nginx-port-forward
|
||||
./nixfiles
|
||||
];
|
||||
}
|
||||
|
95
modules/nixfiles/default.nix
Normal file
95
modules/nixfiles/default.nix
Normal file
@@ -0,0 +1,95 @@
|
||||
{ config, pkgs, lib, ...}:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
nixfiles-generate-config = pkgs.writeScriptBin "nixfiles-generate-config" ''
|
||||
#!${pkgs.bash}/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
hostname=$(hostname --short)
|
||||
root=""
|
||||
ngcroot=""
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--root)
|
||||
root=$2
|
||||
ngcroot="--root ''${root}"
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
--hostname)
|
||||
hostname=$2
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "unknown option: $1"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
mkdir -p ''${root}/etc/nixos
|
||||
|
||||
if [[ ! -d "''${root}/etc/nixos/.git" ]]; then
|
||||
${pkgs.git}/bin/git clone https://git.clerie.de/clerie/nixfiles.git ''${root}/etc/nixos
|
||||
${pkgs.git}/bin/git -C ''${root}/etc/nixos remote set-url origin gitea@git.clerie.de:clerie/nixfiles.git
|
||||
fi
|
||||
|
||||
mkdir -p ''${root}/etc/nixos/hosts/''${hostname}
|
||||
|
||||
nixos-generate-config ''${ngcroot} --dir ''${root}/etc/nixos/hosts/''${hostname}
|
||||
|
||||
# make sure host is added to flake.nix
|
||||
if ! grep -q "''${hostname} = generateNixosSystem \"''${hostname}\";" ''${root}/etc/nixos/flake.nix; then
|
||||
sed -i "s/\(\s*\)_iso = generateNixosSystem \"_iso\";/\1''${hostname} = generateNixosSystem \"''${hostname}\";\n&/g" ''${root}/etc/nixos/flake.nix
|
||||
fi
|
||||
|
||||
sed -i "s/\%HOSTNAME\%/''${hostname}/g" ''${root}/etc/nixos/hosts/''${hostname}/configuration.nix
|
||||
'';
|
||||
|
||||
nixfiles-install = pkgs.writeScriptBin "nixfiles-install" ''
|
||||
#!${pkgs.bash}/bin/bash
|
||||
nixos-install --flake /etc/nixos $@
|
||||
'';
|
||||
|
||||
nixfiles-rebuild = pkgs.writeScriptBin "nixfiles-rebuild" ''
|
||||
#!${pkgs.bash}/bin/bash
|
||||
nixos-rebuild --flake /etc/nixos $@
|
||||
'';
|
||||
|
||||
in {
|
||||
options.clerie.nixfiles.enable = mkEnableOption "clerie nixfiles tools";
|
||||
config = mkIf config.clerie.nixfiles.enable {
|
||||
system.nixos-generate-config.configuration = ''
|
||||
{ config, pkgs, lib, ... }:
|
||||
|
||||
{
|
||||
imports =
|
||||
[
|
||||
./hardware-configuration.nix
|
||||
];
|
||||
|
||||
$bootLoaderConfig
|
||||
|
||||
networking.hostName = "%HOSTNAME%";
|
||||
|
||||
clerie.monitoring = {
|
||||
# enable = true;
|
||||
id = "%MONITORING_ID%";
|
||||
pubkey = "%MONITORING_PUBKEY%";
|
||||
};
|
||||
|
||||
system.stateVersion = "${config.system.nixos.release}";
|
||||
}
|
||||
'';
|
||||
|
||||
environment.systemPackages = [
|
||||
nixfiles-generate-config
|
||||
nixfiles-install
|
||||
nixfiles-rebuild
|
||||
];
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user