Reorganize for zfs

This commit is contained in:
Charlotte Van Petegem 2020-05-23 09:59:32 +02:00
parent 2933964680
commit cfb48de40c
57 changed files with 817 additions and 492 deletions

56
modules/zfs.nix Normal file
View file

@ -0,0 +1,56 @@
{ config, lib, ... }:
{
options.custom.zfs = {
enable = lib.mkOption {
default = false;
example = true;
};
encrypted = lib.mkOption {
default = false;
example = true;
};
systemLinks = lib.mkOption {
default = [ ];
example = [
{ path = "/var/lib/docker"; type = "cache"; }
{ path = "/var/lib/docker/volumes"; type = "data"; }
];
};
homeLinks = lib.mkOption {
default = [ ];
example = [
{ path = ".config/syncthing"; type = "data"; }
{ path = ".cache/nix-index"; type = "cache"; }
];
};
};
config.boot = lib.mkIf config.custom.zfs.enable {
supportedFilesystems = [ "zfs" ];
zfs.requestEncryptionCredentials = config.custom.zfs.encrypted;
initrd.postDeviceCommands = lib.mkAfter ''
zfs rollback -r rpool/local/root@blank
'';
};
config.services.zfs.autoScrub.enable = config.custom.zfs.enable;
config.services.zfs.trim.enable = config.custom.zfs.enable;
config.environment.etc = lib.mkIf config.custom.zfs.enable {
nixos = { source = "/data/etc/nixos/"; };
};
config.systemd.tmpfiles.rules = lib.mkIf config.custom.zfs.enable (
[ "d /home/charlotte 0700 charlotte users - -" ] ++
(map (location: "L ${location.path} - - - - /${location.type}${location.path}") config.custom.zfs.systemLinks)
);
config.home-manager.users.charlotte = { ... }: {
systemd.user.tmpfiles.rules = lib.mkIf config.custom.zfs.enable (
map
(location: "L /home/charlotte/${location.path} - - - - /${location.type}/home/charlotte/${location.path}")
config.custom.zfs.homeLinks
);
};
}