liminix/examples/arhcive.nix

152 lines
3.5 KiB
Nix
Raw Permalink Normal View History

# 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;
in rec {
boot = {
tftp = {
2024-05-07 18:50:34 +02:00
serverip = "10.0.0.1";
ipaddr = "10.0.0.8";
};
};
imports = [
../modules/wlan.nix
2023-08-28 17:08:46 +02:00
../modules/network
../modules/vlan
2023-09-01 18:32:53 +02:00
../modules/ssh
../modules/usb.nix
2023-09-02 18:28:40 +02:00
../modules/watchdog
2023-09-04 22:17:52 +02:00
../modules/mount
];
hostname = "arhcive";
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
};
services.sshd = svc.ssh.build { };
2023-09-02 18:28:40 +02:00
services.watchdog = svc.watchdog.build {
watched = with config.services ; [ sshd dhcpc ];
};
2023-03-23 13:48:10 +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
)
'';
};
filesystem = dir {
etc = dir {
"resolv.conf" = symlink "${services.resolvconf}/.outputs/resolv.conf";
};
srv = dir {};
};
services.defaultroute4 = svc.network.route.build {
via = "$(output ${services.dhcpc} router)";
target = "default";
dependencies = [services.dhcpc];
};
programs.busybox = {
2023-09-04 22:17:52 +02:00
applets = ["lsusb" "tar"];
options = {
FEATURE_LS_TIMESTAMPS = "y";
FEATURE_LS_SORTFILES = "y";
FEATURE_VOLUMEID_EXT = "y";
};
};
2023-09-04 22:17:52 +02:00
services.mount_external_disk = svc.mount.build {
2024-04-17 13:59:13 +02:00
partlabel = "backup-disk";
2023-09-04 22:17:52 +02:00
mountpoint = "/srv";
fstype = "ext4";
};
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
[srv]
path = /srv
use chroot = yes
auth users = backup
read only = false
2023-03-24 18:10:49 +01:00
gid = backup
secrets file = ${secrets_file}/.outputs/secrets
'';
in longrun {
name = "rsync";
run = ''
${pkgs.rsyncSmall}/bin/rsync --no-detach --daemon --config=${configFile}
'';
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.passwd;
2024-05-07 18:50:34 +02:00
openssh.authorizedKeys.keys = secrets.root.keys;
2023-03-23 14:16:58 +01:00
};
2023-03-24 18:10:49 +01:00
users.backup = {
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"];
};
defaultProfile.packages = with pkgs; [
e2fsprogs
mtdutils
(levitate.override {
config = {
services = {
inherit (config.services) dhcpc sshd watchdog;
};
defaultProfile.packages = [ mtdutils ];
users.root.openssh.authorizedKeys.keys = secrets.root.keys;
};
})
];
}