feat(ensure): create ensure module
This module serves to ensure specific directories exist, however in the future it could be used for other things that need to be 'ensured'.
This commit is contained in:
parent
6a02e7b9ea
commit
911d8538fa
2 changed files with 24 additions and 0 deletions
21
modules/functionality/ensure.nix
Normal file
21
modules/functionality/ensure.nix
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
with lib;
|
||||||
|
with lib.hlissner;
|
||||||
|
let
|
||||||
|
cfg = config.services.ensure;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.services.ensure = with types; {
|
||||||
|
enable = mkBoolOpt true;
|
||||||
|
directories = mkOpt (listOf string) [ ];
|
||||||
|
};
|
||||||
|
|
||||||
|
config.systemd.services = {
|
||||||
|
"ensure-directories" = mkIf (cfg.enable && (length cfg.directories > 0)) {
|
||||||
|
description = "Ensures certain directories exist (${concatStringsSep "," cfg.directories})";
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
serviceConfig.Type = "oneshot";
|
||||||
|
script = "mkdir -p ${concatStringsSep " " cfg.directories}";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
|
@ -18,4 +18,7 @@ with lib.hlissner;
|
||||||
|
|
||||||
# Allow non-root users to allow other users to access mount point
|
# Allow non-root users to allow other users to access mount point
|
||||||
programs.fuse.userAllowOther = mkDefault true;
|
programs.fuse.userAllowOther = mkDefault true;
|
||||||
|
|
||||||
|
# Ensure certain necessary directories always exist
|
||||||
|
services.ensure.directories = [ "/mnt" ];
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue