2023-04-30 04:30:15 +02:00
|
|
|
# My own module with nicer syntax for impernanence
|
|
|
|
{ lib, config, ... }:
|
|
|
|
let cfg = config.satellite.persistence;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.satellite.persistence = {
|
2023-05-24 03:17:09 +02:00
|
|
|
enable = lib.mkEnableOption "satellite persitence";
|
2023-04-30 04:30:15 +02:00
|
|
|
|
|
|
|
at = lib.mkOption {
|
|
|
|
default = { };
|
|
|
|
description = "Record of persistent locations (eg: /persist)";
|
|
|
|
type = lib.types.attrsOf (lib.types.submodule (_: {
|
|
|
|
options = {
|
|
|
|
path = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
example = "/persist";
|
|
|
|
default = null;
|
|
|
|
description = "The location to store the files described in this record";
|
|
|
|
};
|
|
|
|
|
2023-06-09 13:17:34 +02:00
|
|
|
prefixDirectories = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = true;
|
|
|
|
example = false;
|
|
|
|
description = "Whether to enable gnu/stow type prefix directories";
|
|
|
|
};
|
|
|
|
|
2023-04-30 04:30:15 +02:00
|
|
|
apps = lib.mkOption {
|
|
|
|
default = { };
|
|
|
|
description = "The apps to be stores in this persistent location";
|
|
|
|
type = lib.types.attrsOf (lib.types.submodule (_: {
|
|
|
|
options = {
|
2023-06-09 13:17:34 +02:00
|
|
|
files = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
|
|
|
default = [ ];
|
|
|
|
example = [ ".screenrc" ];
|
|
|
|
description = ''
|
|
|
|
A list of files in your home directory you want to
|
|
|
|
link to persistent storage. Allows both absolute paths
|
|
|
|
and paths relative to the home directory. .
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-04-30 04:30:15 +02:00
|
|
|
directories = lib.mkOption {
|
|
|
|
default = [ ];
|
|
|
|
description = "Modified version of home.persistence.*.directories which takes in absolute paths";
|
|
|
|
type = lib.types.listOf (lib.types.either lib.types.str (lib.types.submodule {
|
|
|
|
options = {
|
|
|
|
directory = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = null;
|
|
|
|
description = "The directory path to be linked.";
|
|
|
|
};
|
|
|
|
|
|
|
|
method = lib.mkOption {
|
|
|
|
type = lib.types.enum [ "bindfs" "symlink" ];
|
2023-06-09 13:17:34 +02:00
|
|
|
default = "symlink";
|
2023-04-30 04:30:15 +02:00
|
|
|
description = ''
|
|
|
|
The linking method that should be used for this
|
|
|
|
directory. bindfs is the default and works for most use
|
|
|
|
cases, however some programs may behave better with
|
|
|
|
symlinks.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config =
|
|
|
|
let
|
|
|
|
makeLocation = location:
|
|
|
|
let
|
|
|
|
processPath = appName: value:
|
2023-06-09 13:17:34 +02:00
|
|
|
let
|
|
|
|
suffix = "${lib.strings.removePrefix "${config.home.homeDirectory}/" (builtins.toString value)}";
|
|
|
|
prefix = if location.prefixDirectories then "${appName}/" else "";
|
|
|
|
in
|
|
|
|
# lib.debug.traceSeq "\nProcessing path at location ${location.path} and app ${appName} from original path ${value} to ${prefix + suffix}"
|
|
|
|
(prefix + suffix);
|
2023-04-30 04:30:15 +02:00
|
|
|
|
|
|
|
mkDirectory = appName: directory:
|
|
|
|
if builtins.isAttrs directory then {
|
|
|
|
method = directory.method;
|
|
|
|
directory = processPath appName directory.directory;
|
|
|
|
}
|
|
|
|
else processPath appName directory;
|
|
|
|
|
|
|
|
mkAppDirectory = appName: app: builtins.map (mkDirectory appName) app.directories;
|
2023-06-09 13:17:34 +02:00
|
|
|
mkAppFiles = appName: app: builtins.map (processPath appName) app.files;
|
2023-04-30 04:30:15 +02:00
|
|
|
in
|
|
|
|
lib.attrsets.nameValuePair (location.path + config.home.homeDirectory) {
|
2023-06-09 13:17:34 +02:00
|
|
|
removePrefixDirectory = location.prefixDirectories;
|
2023-04-30 04:30:15 +02:00
|
|
|
allowOther = true;
|
|
|
|
directories = lib.lists.flatten
|
|
|
|
(lib.attrsets.mapAttrsToList mkAppDirectory location.apps);
|
2023-06-09 13:17:34 +02:00
|
|
|
|
|
|
|
files = lib.lists.flatten
|
|
|
|
(lib.attrsets.mapAttrsToList mkAppFiles location.apps);
|
2023-04-30 04:30:15 +02:00
|
|
|
};
|
|
|
|
in
|
|
|
|
lib.mkIf cfg.enable {
|
|
|
|
home.persistence = lib.attrsets.mapAttrs' (_: makeLocation) cfg.at;
|
|
|
|
};
|
|
|
|
}
|