# borrows from: # https://xeiaso.net/blog/paranoid-nixos-2021-07-18 # https://elis.nu/blog/2020/05/nixos-tmpfs-as-root/ # https://github.com/nix-community/impermanence { config, lib, pkgs, utils, sane-lib, ... }: with lib; let path = sane-lib.path; sane-types = sane-lib.types; cfg = config.sane.persist; storeType = types.submodule { options = { storeDescription = mkOption { type = types.nullOr types.str; default = null; description = '' an optional description of the store, which is rendered like {store.name}: {store.storeDescription} for example, a store named "private" could have description "ecnrypted to the user's password and decrypted on login". ''; }; origin = mkOption { type = types.str; }; prefix = mkOption { type = types.str; default = "/"; description = '' optional prefix to strip from children when stored here. for example, prefix="/var/private" and mountpoint="/mnt/crypt/private" would cause /var/private/www/root to be stored at /mnt/crypt/private/www/root instead of /mnt/crypt/private/var/private/www/root. ''; }; defaultOrdering.wantedBeforeBy = mkOption { type = types.listOf types.str; default = [ "local-fs.target" ]; description = '' list of units or targets which would prefer that everything in this store be initialized before they run, but failing to do so should not error the items in this list. ''; }; defaultOrdering.wantedBy = mkOption { type = types.listOf types.str; default = [ ]; description = '' list of units or targets which, upon activation, should activate all units in this store. ''; }; }; }; # options for a single mountpoint / persistence dirEntryOptions = { options = { directory = mkOption { type = types.str; }; inherit (sane-types.aclOverrideMod.options) user group mode; }; }; contextualizedDir = types.submodule dirEntryOptions; # allow "bar/baz" as shorthand for { directory = "bar/baz"; } contextualizedDirOrShorthand = types.coercedTo types.str (d: { directory = d; }) contextualizedDir; # entry whose `directory` is always an absolute fs path # and has an associated `store` contextFreeDir = types.submodule [ dirEntryOptions { options = { store = mkOption { type = storeType; }; }; } ]; contextFreeDirSpec = types.submodule { options = { inherit (sane-types.aclOverrideMod.options) user group mode; store = mkOption { type = storeType; }; }; }; # attrset from { "${storeName}" = [ dirEntry ] } # the user can specify something like: #