feat: add set-nix-channel module to manage nix-channel automatically
This commit is contained in:
@@ -64,6 +64,7 @@
|
|||||||
|
|
||||||
# setup network
|
# setup network
|
||||||
./modules/setupnetwork.nix
|
./modules/setupnetwork.nix
|
||||||
|
./modules/set-nix-channel.nix # Automatically manage nix-channel from /var/bento/channel
|
||||||
|
|
||||||
|
|
||||||
./hardware-configuration.nix
|
./hardware-configuration.nix
|
||||||
|
|||||||
1
hosts/fw/modules/set-nix-channel.nix
Symbolic link
1
hosts/fw/modules/set-nix-channel.nix
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../../utils/modules/set-nix-channel.nix
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
./utils/modules/promtail
|
./utils/modules/promtail
|
||||||
./utils/modules/victoriametrics
|
./utils/modules/victoriametrics
|
||||||
./utils/modules/netdata.nix
|
./utils/modules/netdata.nix
|
||||||
|
./modules/set-nix-channel.nix # Automatically manage nix-channel from /var/bento/channel
|
||||||
|
|
||||||
./hardware-configuration.nix
|
./hardware-configuration.nix
|
||||||
];
|
];
|
||||||
|
|||||||
1
hosts/mail/modules/set-nix-channel.nix
Symbolic link
1
hosts/mail/modules/set-nix-channel.nix
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../../utils/modules/set-nix-channel.nix
|
||||||
@@ -42,6 +42,7 @@ in {
|
|||||||
|
|
||||||
# ./modules/steam.nix
|
# ./modules/steam.nix
|
||||||
./modules/fingerprint.nix
|
./modules/fingerprint.nix
|
||||||
|
./modules/set-nix-channel.nix # Automatically manage nix-channel from /var/bento/channel
|
||||||
|
|
||||||
./hardware-configuration.nix
|
./hardware-configuration.nix
|
||||||
|
|
||||||
|
|||||||
1
hosts/nb/modules/set-nix-channel.nix
Symbolic link
1
hosts/nb/modules/set-nix-channel.nix
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../../utils/modules/set-nix-channel.nix
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
./utils/modules/promtail
|
./utils/modules/promtail
|
||||||
./utils/modules/borgbackup.nix
|
./utils/modules/borgbackup.nix
|
||||||
./utils/modules/netdata.nix
|
./utils/modules/netdata.nix
|
||||||
|
./modules/set-nix-channel.nix # Automatically manage nix-channel from /var/bento/channel
|
||||||
|
|
||||||
./hardware-configuration.nix
|
./hardware-configuration.nix
|
||||||
|
|
||||||
|
|||||||
1
hosts/web-arm/modules/set-nix-channel.nix
Symbolic link
1
hosts/web-arm/modules/set-nix-channel.nix
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../../utils/modules/set-nix-channel.nix
|
||||||
40
utils/modules/set-nix-channel.nix
Normal file
40
utils/modules/set-nix-channel.nix
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
# utils/modules/set-nix-channel.nix
|
||||||
|
{ config, pkgs, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
systemd.services.set-nix-channel = {
|
||||||
|
description = "Set nix-channel from /var/bento/channel";
|
||||||
|
after = [ "network.target" ]; # Ensure network is up
|
||||||
|
wantedBy = [ "multi-user.target" ]; # Start on boot
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
RemainAfterExit = true; # Consider the service "active" after successful run
|
||||||
|
User = "root";
|
||||||
|
ExecStart = pkgs.writeShellScript "set-nix-channel-script" ''
|
||||||
|
set -e # Exit immediately if a command exits with a non-zero status.
|
||||||
|
CHANNEL_FILE="/var/bento/channel"
|
||||||
|
CHANNEL_NAME="nixos"
|
||||||
|
|
||||||
|
if [ ! -f "$CHANNEL_FILE" ]; then
|
||||||
|
echo "Error: Channel file $CHANNEL_FILE not found." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
CHANNEL_URL=$(cat "$CHANNEL_FILE")
|
||||||
|
|
||||||
|
if [ -z "$CHANNEL_URL" ]; then
|
||||||
|
echo "Error: Channel file $CHANNEL_FILE is empty." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Attempt to remove existing channel to ensure clean state, ignore error if it doesn't exist
|
||||||
|
${pkgs.nix}/bin/nix-channel --remove "$CHANNEL_NAME" || true
|
||||||
|
${pkgs.nix}/bin/nix-channel --add "$CHANNEL_URL" "$CHANNEL_NAME"
|
||||||
|
${pkgs.nix}/bin/nix-channel --update "$CHANNEL_NAME"
|
||||||
|
|
||||||
|
echo "Successfully set and updated channel '$CHANNEL_NAME' from $CHANNEL_FILE."
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user