NixOS and Home Manager config

feat: mount nas folders for each user and the system

nel.pet c4ff07ec 62c298f0

verified
Changed files
+63 -13
modules
systems
nel-desktop
+1
modules/nixos/default.nix
···
_class = "nixos";
imports = [
./nix.nix
];
}
···
_class = "nixos";
imports = [
+
./lannas.nix
./nix.nix
];
}
+56
modules/nixos/lannas.nix
···
···
+
{
+
lib,
+
pkgs,
+
config,
+
...
+
}: let
+
cfg = config.cyclamen.system.lannas;
+
# TODO: secrets stuff
+
credFile = "/etc/nixos/nas_secrets";
+
rootBackupsPath = "main/backup/nel";
+
normalUsers = lib.attrNames (lib.filterAttrs
+
(username: user: if user.isNormalUser == true then true else false)
+
config.users.users
+
);
+
usernameToMountUnit = name: {
+
what = "//truenas.lan.nelind.dk/${rootBackupsPath}/users/${name}";
+
where = "/mnt/nas/users/${name}";
+
type = "cifs";
+
options = "credentials=${credFile},uid=${name},gid=users,forcegid,forceuid,nounix,file_mode=0700,dir_mode=0700,_netdev";
+
mountConfig.TimeoutSec = 5;
+
};
+
usernameToAutomountUnit = name: {
+
requiredBy = [ "remote-fs.target" ];
+
where = "/mnt/nas/users/${name}";
+
automountConfig.TimeoutIdleSec = 60;
+
};
+
hostnameToMountUnit = name: {
+
what = "//truenas.lan.nelind.dk/${rootBackupsPath}/hosts/${name}";
+
where = "/mnt/nas/system";
+
type = "cifs";
+
options = "credentials=${credFile},file_mode=0700,dir_mode=0700,_netdev";
+
mountConfig.TimeoutSec = 5;
+
};
+
hostnameToAutomountUnit = name: {
+
requiredBy = [ "remote-fs.target" ];
+
where = "/mnt/nas/system";
+
automountConfig.TimeoutIdleSec = 60;
+
};
+
in {
+
options.cyclamen.system.lannas.enable = lib.mkEnableOption ''
+
mounting of directories from the LAN NAS. mainly intended for backups.
+
'';
+
+
config = lib.mkIf cfg.enable {
+
boot.supportedFilesystems = [ "cifs" ];
+
# For mount.cifs, required unless domain name resolution is not needed.
+
environment.systemPackages = [ pkgs.cifs-utils ];
+
+
# We use systemd mount units directly instead of fileSystems.* to avoid infinite recursion.
+
# See https://github.com/NixOS/nixpkgs/issues/24570 for details
+
systemd = {
+
mounts = (lib.lists.map usernameToMountUnit normalUsers) ++ [ (hostnameToMountUnit config.networking.hostName) ];
+
automounts = (lib.lists.map usernameToAutomountUnit normalUsers) ++ [ (hostnameToAutomountUnit config.networking.hostName) ];
+
};
+
};
+
}
+6 -13
systems/nel-desktop/configuration.nix
···
./hardware-configuration.nix
];
# Bootloader.
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
···
[General]
background=${./transcoded-wallpaper.jpeg}
'')
-
-
# For mount.cifs, required unless domain name resolution is not needed.
-
cifs-utils
];
-
-
# TODO: secrets stuff
-
fileSystems."/mnt/nas" = {
-
device = "//truenas.lan.nelind.dk/main";
-
fsType = "cifs";
-
options = let
-
# this prevents hanging on network split
-
automount_opts = "x-systemd.automount,noauto,x-systemd.idle-timeout=60,x-systemd.device-timeout=5s,x-systemd.mount-timeout=5s";
-
in [ "${automount_opts},credentials=/etc/nixos/nas_secrets" ];
-
};
services.pulseaudio.enable = false;
security.rtkit.enable = true;
···
./hardware-configuration.nix
];
+
cyclamen = {
+
system = {
+
lannas.enable = true;
+
};
+
};
+
# Bootloader.
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
···
[General]
background=${./transcoded-wallpaper.jpeg}
'')
];
services.pulseaudio.enable = false;
security.rtkit.enable = true;