1
0

pkgs/nixfiles: expose nixfiles-generate-config as pkg

This commit is contained in:
2023-10-20 22:57:33 +02:00
parent 30cc2e4f15
commit b9af028fa7
5 changed files with 14 additions and 11 deletions

View File

@@ -0,0 +1,10 @@
{ pkgs, ... }:
pkgs.writeShellApplication {
name = "nixfiles-generate-config";
text = builtins.readFile ./nixfiles-generate-config.sh;
runtimeInputs = with pkgs; [
git
];
checkPhase = "";
}

View File

@@ -0,0 +1,46 @@
#!/usr/bin/env 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
git clone https://git.clerie.de/clerie/nixfiles.git "${root}/etc/nixos"
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"
git -C "${root}/etc/nixos" add "${root}/etc/nixos/hosts/${hostname}"

View File

@@ -4,6 +4,7 @@ self: super: {
iot-data = self.python3.pkgs.callPackage ./iot-data {};
nixfiles-add-secret = self.callPackage ./nixfiles/nixfiles-add-secret.nix {};
nixfiles-generate-backup-secrets = self.callPackage ./nixfiles/nixfiles-generate-backup-secrets.nix {};
nixfiles-generate-config = self.callPackage ./nixfiles/nixfiles-generate-config.nix {};
nixfiles-updated-inputs = self.callPackage ./nixfiles/nixfiles-updated-inputs.nix {};
nixfiles-update-ssh-host-keys = self.callPackage ./nixfiles/nixfiles-update-ssh-host-keys.nix {};
pyexcel-xlsx = self.python3.pkgs.callPackage ./pyexcel-xlsx {};