File tree Expand file tree Collapse file tree 1 file changed +39
-1
lines changed Expand file tree Collapse file tree 1 file changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ flake: {
6060 ...
6161 } : let
6262 inherit ( builtins ) head ;
63- inherit ( lib ) any getExe hasInfix hasPrefix mkForce mkIf mkOption splitString ;
63+ inherit ( lib ) any getExe hasInfix hasPrefix mkForce mkIf mkOption removePrefix splitString ;
6464 inherit ( lib . types ) bool enum listOf str ;
6565 inherit ( config . aws . instance ) instance_type ;
6666
@@ -76,6 +76,15 @@ flake: {
7676 key = ./profile-aws-ec2-ephemeral.nix ;
7777
7878 options . services . aws . ec2 . ephemeral = {
79+ enableMountOnCreation = mkOption {
80+ type = bool ;
81+ default = true ;
82+ description = ''
83+ Whether to ensure the ephemeral volume is mounted automatically after
84+ it becomes available.
85+ '' ;
86+ } ;
87+
7988 enablePostMountService = mkOption {
8089 type = bool ;
8190 default = true ;
@@ -345,6 +354,35 @@ flake: {
345354 } ) ;
346355 } ;
347356 } ;
357+
358+ "${ cfg . serviceName } -mount-on-creation" = mkIf cfg . enableMountOnCreation {
359+ wantedBy = [ "multi-user.target" ] ;
360+ serviceConfig = {
361+ Type = "oneshot" ;
362+ ExecStart = getExe ( pkgs . writeShellApplication {
363+ name = "${ cfg . serviceName } -mount-on-creation" ;
364+ text = ''
365+ set -euo pipefail
366+
367+ while true; do
368+ echo "Sleeping 10 seconds until mount on created attempt..."
369+ sleep 10
370+ # shellcheck disable=SC2010
371+ if ls -1 / | grep -q ${ removePrefix "/" cfg . mountPoint } ; then
372+ echo "Found: ${ cfg . mountPoint } "
373+
374+ # Trigger the systemd auto-mount service
375+ ls ${ cfg . mountPoint }
376+
377+ touch ${ cfg . mountPoint } /.mounted
378+
379+ break
380+ fi
381+ done
382+ '' ;
383+ } ) ;
384+ } ;
385+ } ;
348386 } ;
349387 } ;
350388 } ;
You can’t perform that action at this time.
0 commit comments