forked from DGNum/liminix
extract "mount filesystem" to module
This commit is contained in:
parent
83092b7b73
commit
3bdc986dd7
4 changed files with 75 additions and 16 deletions
|
@ -2141,8 +2141,8 @@ Thu Aug 31 23:53:54 BST 2023
|
||||||
- packet forwarding
|
- packet forwarding
|
||||||
- and arhcive
|
- and arhcive
|
||||||
- rsync
|
- rsync
|
||||||
- watchdog
|
- [done] watchdog
|
||||||
- mount
|
- [done] mount
|
||||||
- nftables syntax error
|
- nftables syntax error
|
||||||
- tidy up the dependency handling in serviceDefn build
|
- tidy up the dependency handling in serviceDefn build
|
||||||
(interface is fine, implementation is a bit brutal)
|
(interface is fine, implementation is a bit brutal)
|
||||||
|
|
|
@ -30,6 +30,7 @@ in rec {
|
||||||
../modules/vlan
|
../modules/vlan
|
||||||
../modules/ssh
|
../modules/ssh
|
||||||
../modules/watchdog
|
../modules/watchdog
|
||||||
|
../modules/mount
|
||||||
];
|
];
|
||||||
|
|
||||||
hostname = "arhcive";
|
hostname = "arhcive";
|
||||||
|
@ -101,27 +102,18 @@ in rec {
|
||||||
};
|
};
|
||||||
|
|
||||||
programs.busybox = {
|
programs.busybox = {
|
||||||
applets = ["blkid" "lsusb" "findfs" "tar"];
|
applets = ["lsusb" "tar"];
|
||||||
options = {
|
options = {
|
||||||
FEATURE_LS_TIMESTAMPS = "y";
|
FEATURE_LS_TIMESTAMPS = "y";
|
||||||
FEATURE_LS_SORTFILES = "y";
|
FEATURE_LS_SORTFILES = "y";
|
||||||
FEATURE_BLKID_TYPE = "y";
|
|
||||||
FEATURE_MOUNT_FLAGS = "y";
|
|
||||||
FEATURE_MOUNT_LABEL = "y";
|
|
||||||
FEATURE_VOLUMEID_EXT = "y";
|
FEATURE_VOLUMEID_EXT = "y";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
services.mount_external_disk = oneshot {
|
services.mount_external_disk = svc.mount.build {
|
||||||
name = "mount_external_disk";
|
device = "LABEL=backup-disk";
|
||||||
up = ''
|
mountpoint = "/srv";
|
||||||
while ! findfs LABEL=backup-disk; do
|
fstype = "ext4";
|
||||||
echo waiting for backup-disk
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
mount -t ext4 LABEL=backup-disk /srv
|
|
||||||
'';
|
|
||||||
down = "umount /srv";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
services.rsync =
|
services.rsync =
|
||||||
|
|
49
modules/mount/default.nix
Normal file
49
modules/mount/default.nix
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
|
||||||
|
{ lib, pkgs, config, ...}:
|
||||||
|
let
|
||||||
|
inherit (lib) mkOption types;
|
||||||
|
inherit (pkgs) liminix;
|
||||||
|
mkBoolOption = description : mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
inherit description;
|
||||||
|
default = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
in {
|
||||||
|
options = {
|
||||||
|
system.service.mount = mkOption {
|
||||||
|
type = liminix.lib.types.serviceDefn;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
config.system.service = {
|
||||||
|
mount = liminix.callService ./service.nix {
|
||||||
|
device = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
example = "/dev/sda1";
|
||||||
|
};
|
||||||
|
mountpoint = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
example = "/mnt/media";
|
||||||
|
};
|
||||||
|
options = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
default = [];
|
||||||
|
example = ["noatime" "ro" "sync"];
|
||||||
|
};
|
||||||
|
fstype = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "auto";
|
||||||
|
example = "vfat";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
config.programs.busybox = {
|
||||||
|
applets = ["blkid" "findfs"];
|
||||||
|
options = {
|
||||||
|
FEATURE_BLKID_TYPE = "y";
|
||||||
|
FEATURE_MOUNT_FLAGS = "y";
|
||||||
|
FEATURE_MOUNT_LABEL = "y";
|
||||||
|
FEATURE_VOLUMEID_EXT = "y";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
18
modules/mount/service.nix
Normal file
18
modules/mount/service.nix
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
liminix
|
||||||
|
, lib
|
||||||
|
}:
|
||||||
|
{ device, mountpoint, options, fstype }:
|
||||||
|
let
|
||||||
|
inherit (liminix.services) oneshot;
|
||||||
|
in oneshot {
|
||||||
|
name = "mount.${lib.escapeURL mountpoint}";
|
||||||
|
up = ''
|
||||||
|
while ! findfs ${device}; do
|
||||||
|
echo waiting for device ${device}
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
mount -t ${fstype} -o ${lib.concatStringsSep "," options} ${device} ${mountpoint}
|
||||||
|
'';
|
||||||
|
down = "umount ${mountpoint}";
|
||||||
|
}
|
Loading…
Reference in a new issue