arhcive.nix (5502B)
1 # This is not part of Liminix per se. This is a "scratchpad" 2 # configuration for a device I'm testing with. 3 # 4 # Parts of it do do things that Liminix eventually needs to do, but 5 # don't look in here for solutions - just for identifying the 6 # problems. 7 { 8 config, 9 pkgs, 10 lib, 11 ... 12 }: let 13 secrets = import ./extneder-secrets.nix; 14 inherit 15 (pkgs.liminix.networking) 16 address 17 udhcpc 18 interface 19 route 20 ; 21 inherit (pkgs.liminix.services) oneshot longrun bundle target; 22 inherit (pkgs.pseudofile) dir symlink; 23 inherit (pkgs) writeText dropbear ifwait serviceFns; 24 in rec { 25 boot = { 26 tftp = { 27 serverip = "192.168.8.148"; 28 ipaddr = "192.168.8.251"; 29 }; 30 }; 31 32 imports = [ 33 ../modules/standard.nix 34 ../modules/wlan.nix 35 ]; 36 37 hostname = "arhcive"; 38 39 kernel = { 40 config = { 41 USB = "y"; 42 USB_EHCI_HCD = "y"; 43 USB_EHCI_HCD_PLATFORM = "y"; 44 USB_OHCI_HCD = "y"; 45 USB_OHCI_HCD_PLATFORM = "y"; 46 USB_SUPPORT = "y"; 47 USB_COMMON = "y"; 48 USB_STORAGE = "y"; 49 USB_STORAGE_DEBUG = "n"; 50 USB_UAS = "y"; 51 USB_ANNOUNCE_NEW_DEVICES = "y"; 52 SCSI = "y"; 53 BLK_DEV_SD = "y"; 54 USB_PRINTER = "y"; 55 PARTITION_ADVANCED = "y"; 56 MSDOS_PARTITION = "y"; 57 EFI_PARTITION = "y"; 58 EXT4_FS = "y"; 59 EXT4_USE_FOR_EXT2 = "y"; 60 FS_ENCRYPTION = "y"; 61 }; 62 }; 63 64 services.dhcpc = 65 let iface = config.hardware.networkInterfaces.lan; 66 in (udhcpc iface { 67 dependencies = [ config.services.hostname ]; 68 }) // { inherit (iface) device; }; 69 70 services.sshd = longrun { 71 name = "sshd"; 72 run = '' 73 mkdir -p /run/dropbear 74 ${dropbear}/bin/dropbear -E -P /run/dropbear.pid -R -F 75 ''; 76 }; 77 78 services.watchdog = 79 let 80 watched = with config.services ; [ sshd dhcpc ]; 81 spinupGrace = 60; 82 script = pkgs.writeAshScript "gaspode" { 83 runtimeInputs = [ pkgs.s6 ]; 84 } '' 85 deadline=$(expr $(date +%s) + ${toString spinupGrace}) 86 services=$@ 87 echo started feeding the dog 88 exec 3> ''${WATCHDOG-/dev/watchdog} 89 90 healthy(){ 91 test $(date +%s) -le $deadline && return 0 92 93 for i in $services; do 94 if test "$(s6-svstat -o up /run/service/$i)" != "true" ; then 95 echo "service $i is down" 96 return 1 97 fi 98 done 99 } 100 101 while healthy ;do 102 sleep 10 103 echo >&3 104 done 105 echo "stopped feeding the dog" 106 sleep 6000 # don't want s6-rc to restart 107 ''; 108 in longrun { 109 name = "watchdog"; 110 run = 111 "${script} ${lib.concatStringsSep " " (builtins.map (s: s.name) watched)}"; 112 }; 113 114 115 services.resolvconf = oneshot rec { 116 dependencies = [ services.dhcpc ]; 117 name = "resolvconf"; 118 up = '' 119 . ${serviceFns} 120 ( in_outputs ${name} 121 for i in $(output ${services.dhcpc} dns); do 122 echo "nameserver $i" > resolv.conf 123 done 124 ) 125 ''; 126 down = '' 127 rm -rf /run/service-state/${name}/ 128 ''; 129 }; 130 filesystem = dir { 131 etc = dir { 132 "resolv.conf" = symlink "${services.resolvconf}/.outputs/resolv.conf"; 133 }; 134 srv = dir {}; 135 }; 136 137 services.defaultroute4 = route { 138 name = "defaultroute"; 139 via = "$(output ${services.dhcpc} router)"; 140 target = "default"; 141 dependencies = [services.dhcpc]; 142 }; 143 144 programs.busybox = { 145 applets = ["blkid" "lsusb" "findfs" "tar"]; 146 options = { 147 FEATURE_LS_TIMESTAMPS = "y"; 148 FEATURE_LS_SORTFILES = "y"; 149 FEATURE_BLKID_TYPE = "y"; 150 FEATURE_MOUNT_FLAGS = "y"; 151 FEATURE_MOUNT_LABEL = "y"; 152 FEATURE_VOLUMEID_EXT = "y"; 153 }; 154 }; 155 156 services.mount_external_disk = oneshot { 157 name = "mount_external_disk"; 158 up = '' 159 while ! findfs LABEL=backup-disk; do 160 echo waiting for backup-disk 161 sleep 1 162 done 163 mount -t ext4 LABEL=backup-disk /srv 164 ''; 165 down = "umount /srv"; 166 }; 167 168 services.rsync = 169 let 170 secrets_file = oneshot rec { 171 name = "rsync-secrets"; 172 up = '' 173 . ${serviceFns} 174 (in_outputs ${name} 175 echo "backup:${secrets.rsync_secret}" > secrets) 176 ''; 177 down = "true"; 178 }; 179 configFile = writeText "rsync.conf" '' 180 pid file = /run/rsyncd.pid 181 uid = backup 182 [srv] 183 path = /srv 184 use chroot = yes 185 auth users = backup 186 read only = false 187 gid = backup 188 secrets file = ${secrets_file}/.outputs/secrets 189 ''; 190 in longrun { 191 name = "rsync"; 192 run = '' 193 ${pkgs.rsyncSmall}/bin/rsync --no-detach --daemon --config=${configFile} 194 ''; 195 dependencies = [ 196 secrets_file 197 services.mount_external_disk 198 config.hardware.networkInterfaces.lan 199 ] ; 200 }; 201 202 services.default = target { 203 name = "default"; 204 contents = 205 let links = config.hardware.networkInterfaces; 206 in with config.services; [ 207 links.lo 208 defaultroute4 209 resolvconf 210 sshd 211 rsync 212 watchdog 213 ]; 214 }; 215 216 users.root = { 217 passwd = lib.mkForce secrets.root_password; 218 # openssh.authorizedKeys.keys = [ 219 # (builtins.readFile "/home/dan/.ssh/id_rsa.pub") 220 # ]; 221 }; 222 223 users.backup = { 224 uid=500; gid=500; gecos="Storage owner"; dir="/srv"; 225 shell="/dev/null"; 226 }; 227 groups.backup = { 228 gid=500; usernames = ["backup"]; 229 }; 230 231 defaultProfile.packages = with pkgs; [e2fsprogs strace tcpdump ]; 232 }