2023-03-10 19:42:32 +01:00
|
|
|
# This is not part of Liminix per se. This is a "scratchpad"
|
|
|
|
# configuration for a device I'm testing with.
|
|
|
|
#
|
|
|
|
# Parts of it do do things that Liminix eventually needs to do, but
|
|
|
|
# don't look in here for solutions - just for identifying the
|
|
|
|
# problems.
|
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
secrets = import ./extneder-secrets.nix;
|
|
|
|
inherit (pkgs.liminix.services) oneshot longrun bundle target;
|
|
|
|
inherit (pkgs.pseudofile) dir symlink;
|
2023-04-10 18:46:39 +02:00
|
|
|
inherit (pkgs) writeText dropbear ifwait serviceFns;
|
2023-08-28 17:08:46 +02:00
|
|
|
svc = config.system.service;
|
2023-03-10 19:42:32 +01:00
|
|
|
in rec {
|
|
|
|
boot = {
|
|
|
|
tftp = {
|
|
|
|
serverip = "192.168.8.148";
|
|
|
|
ipaddr = "192.168.8.251";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
imports = [
|
2023-05-16 21:13:46 +02:00
|
|
|
../modules/standard.nix
|
2023-03-10 19:42:32 +01:00
|
|
|
../modules/wlan.nix
|
2023-08-28 17:08:46 +02:00
|
|
|
../modules/network
|
2023-08-31 00:26:44 +02:00
|
|
|
../modules/vlan
|
2023-03-10 19:42:32 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
hostname = "arhcive";
|
|
|
|
|
|
|
|
kernel = {
|
|
|
|
config = {
|
|
|
|
USB = "y";
|
|
|
|
USB_EHCI_HCD = "y";
|
|
|
|
USB_EHCI_HCD_PLATFORM = "y";
|
|
|
|
USB_OHCI_HCD = "y";
|
|
|
|
USB_OHCI_HCD_PLATFORM = "y";
|
|
|
|
USB_SUPPORT = "y";
|
|
|
|
USB_COMMON = "y";
|
|
|
|
USB_STORAGE = "y";
|
|
|
|
USB_STORAGE_DEBUG = "n";
|
|
|
|
USB_UAS = "y";
|
|
|
|
USB_ANNOUNCE_NEW_DEVICES = "y";
|
|
|
|
SCSI = "y";
|
|
|
|
BLK_DEV_SD = "y";
|
|
|
|
USB_PRINTER = "y";
|
|
|
|
PARTITION_ADVANCED = "y";
|
|
|
|
MSDOS_PARTITION = "y";
|
|
|
|
EFI_PARTITION = "y";
|
|
|
|
EXT4_FS = "y";
|
|
|
|
EXT4_USE_FOR_EXT2 = "y";
|
|
|
|
FS_ENCRYPTION = "y";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-03-11 00:39:32 +01:00
|
|
|
services.dhcpc =
|
2023-08-28 17:08:46 +02:00
|
|
|
let iface = config.hardware.networkInterfaces.lan;
|
|
|
|
in svc.network.dhcp.client.build {
|
|
|
|
interface = iface;
|
2023-03-11 00:39:32 +01:00
|
|
|
dependencies = [ config.services.hostname ];
|
2023-08-28 17:08:46 +02:00
|
|
|
};
|
2023-03-10 19:42:32 +01:00
|
|
|
|
|
|
|
services.sshd = longrun {
|
|
|
|
name = "sshd";
|
|
|
|
run = ''
|
|
|
|
mkdir -p /run/dropbear
|
|
|
|
${dropbear}/bin/dropbear -E -P /run/dropbear.pid -R -F
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-03-23 13:48:10 +01:00
|
|
|
services.watchdog =
|
|
|
|
let
|
|
|
|
watched = with config.services ; [ sshd dhcpc ];
|
|
|
|
spinupGrace = 60;
|
|
|
|
script = pkgs.writeAshScript "gaspode" {
|
|
|
|
runtimeInputs = [ pkgs.s6 ];
|
|
|
|
} ''
|
|
|
|
deadline=$(expr $(date +%s) + ${toString spinupGrace})
|
|
|
|
services=$@
|
|
|
|
echo started feeding the dog
|
|
|
|
exec 3> ''${WATCHDOG-/dev/watchdog}
|
|
|
|
|
|
|
|
healthy(){
|
|
|
|
test $(date +%s) -le $deadline && return 0
|
|
|
|
|
|
|
|
for i in $services; do
|
|
|
|
if test "$(s6-svstat -o up /run/service/$i)" != "true" ; then
|
|
|
|
echo "service $i is down"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
while healthy ;do
|
|
|
|
sleep 10
|
|
|
|
echo >&3
|
|
|
|
done
|
|
|
|
echo "stopped feeding the dog"
|
|
|
|
sleep 6000 # don't want s6-rc to restart
|
|
|
|
'';
|
|
|
|
in longrun {
|
|
|
|
name = "watchdog";
|
|
|
|
run =
|
|
|
|
"${script} ${lib.concatStringsSep " " (builtins.map (s: s.name) watched)}";
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-03-10 19:42:32 +01:00
|
|
|
services.resolvconf = oneshot rec {
|
|
|
|
dependencies = [ services.dhcpc ];
|
|
|
|
name = "resolvconf";
|
|
|
|
up = ''
|
|
|
|
. ${serviceFns}
|
|
|
|
( in_outputs ${name}
|
|
|
|
for i in $(output ${services.dhcpc} dns); do
|
|
|
|
echo "nameserver $i" > resolv.conf
|
|
|
|
done
|
|
|
|
)
|
|
|
|
'';
|
|
|
|
down = ''
|
|
|
|
rm -rf /run/service-state/${name}/
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
filesystem = dir {
|
|
|
|
etc = dir {
|
|
|
|
"resolv.conf" = symlink "${services.resolvconf}/.outputs/resolv.conf";
|
|
|
|
};
|
|
|
|
srv = dir {};
|
|
|
|
};
|
|
|
|
|
2023-09-01 00:52:59 +02:00
|
|
|
services.defaultroute4 = svc.network.route.build {
|
2023-03-10 19:42:32 +01:00
|
|
|
via = "$(output ${services.dhcpc} router)";
|
|
|
|
target = "default";
|
|
|
|
dependencies = [services.dhcpc];
|
|
|
|
};
|
|
|
|
|
|
|
|
programs.busybox = {
|
2023-03-17 12:53:26 +01:00
|
|
|
applets = ["blkid" "lsusb" "findfs" "tar"];
|
2023-03-10 19:42:32 +01:00
|
|
|
options = {
|
|
|
|
FEATURE_LS_TIMESTAMPS = "y";
|
|
|
|
FEATURE_LS_SORTFILES = "y";
|
|
|
|
FEATURE_BLKID_TYPE = "y";
|
|
|
|
FEATURE_MOUNT_FLAGS = "y";
|
|
|
|
FEATURE_MOUNT_LABEL = "y";
|
|
|
|
FEATURE_VOLUMEID_EXT = "y";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.mount_external_disk = oneshot {
|
|
|
|
name = "mount_external_disk";
|
2023-03-17 12:53:26 +01:00
|
|
|
up = ''
|
|
|
|
while ! findfs LABEL=backup-disk; do
|
|
|
|
echo waiting for backup-disk
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
mount -t ext4 LABEL=backup-disk /srv
|
|
|
|
'';
|
2023-03-10 19:42:32 +01:00
|
|
|
down = "umount /srv";
|
|
|
|
};
|
|
|
|
|
|
|
|
services.rsync =
|
|
|
|
let
|
|
|
|
secrets_file = oneshot rec {
|
|
|
|
name = "rsync-secrets";
|
|
|
|
up = ''
|
|
|
|
. ${serviceFns}
|
|
|
|
(in_outputs ${name}
|
|
|
|
echo "backup:${secrets.rsync_secret}" > secrets)
|
|
|
|
'';
|
|
|
|
down = "true";
|
|
|
|
};
|
|
|
|
configFile = writeText "rsync.conf" ''
|
|
|
|
pid file = /run/rsyncd.pid
|
2023-03-24 18:10:49 +01:00
|
|
|
uid = backup
|
2023-03-10 19:42:32 +01:00
|
|
|
[srv]
|
|
|
|
path = /srv
|
|
|
|
use chroot = yes
|
|
|
|
auth users = backup
|
|
|
|
read only = false
|
2023-03-24 18:10:49 +01:00
|
|
|
gid = backup
|
2023-03-10 19:42:32 +01:00
|
|
|
secrets file = ${secrets_file}/.outputs/secrets
|
|
|
|
'';
|
|
|
|
in longrun {
|
|
|
|
name = "rsync";
|
|
|
|
run = ''
|
2023-04-10 21:04:23 +02:00
|
|
|
${pkgs.rsyncSmall}/bin/rsync --no-detach --daemon --config=${configFile}
|
2023-03-10 19:42:32 +01:00
|
|
|
'';
|
|
|
|
dependencies = [
|
|
|
|
secrets_file
|
|
|
|
services.mount_external_disk
|
|
|
|
config.hardware.networkInterfaces.lan
|
|
|
|
] ;
|
|
|
|
};
|
|
|
|
|
2023-03-23 14:16:58 +01:00
|
|
|
users.root = {
|
|
|
|
passwd = lib.mkForce secrets.root_password;
|
|
|
|
# openssh.authorizedKeys.keys = [
|
|
|
|
# (builtins.readFile "/home/dan/.ssh/id_rsa.pub")
|
|
|
|
# ];
|
|
|
|
};
|
2023-03-10 19:42:32 +01:00
|
|
|
|
2023-03-24 18:10:49 +01:00
|
|
|
users.backup = {
|
2023-03-10 19:42:32 +01:00
|
|
|
uid=500; gid=500; gecos="Storage owner"; dir="/srv";
|
2023-03-24 18:10:49 +01:00
|
|
|
shell="/dev/null";
|
|
|
|
};
|
|
|
|
groups.backup = {
|
|
|
|
gid=500; usernames = ["backup"];
|
2023-03-10 19:42:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
defaultProfile.packages = with pkgs; [e2fsprogs strace tcpdump ];
|
|
|
|
}
|