Added SMB share to Desktop

This commit is contained in:
2026-04-16 16:12:32 +02:00
parent 43ab264adc
commit 36c407cb55
2 changed files with 51 additions and 7 deletions

View File

@@ -1,5 +1,4 @@
{ {
config,
pkgs, pkgs,
primaryUser, primaryUser,
... ...
@@ -66,16 +65,24 @@
description = "Set Samba password for ${primaryUser}"; description = "Set Samba password for ${primaryUser}";
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
after = [ after = [
"smbd.service" "samba-smbd.service"
"sops-nix.service" "sops-install-secrets.service"
]; ];
requires = [ "smbd.service" ]; requires = [ "samba-smbd.service" ];
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";
RemainAfterExit = true; RemainAfterExit = true;
ExecStart = pkgs.writeShellScript "samba-set-password" '' ExecStart = pkgs.writeShellScript "samba-set-password" ''
PASSWORD=$(cat /run/secrets/smb-password-phil) # Wait for smbd to initialize its passdb
echo -e "$PASSWORD\n$PASSWORD" | ${pkgs.samba}/bin/smbpasswd -a -s ${primaryUser} for i in $(seq 1 10); do
[ -f /var/lib/samba/private/passdb.tdb ] && break
echo "Waiting for passdb.tdb... attempt $i"
sleep 1
done
PASSWORD=$(cat /run/secrets/smb_passwd)
(echo "$PASSWORD"; echo "$PASSWORD") | ${pkgs.samba}/bin/smbpasswd -a -s ${primaryUser} || \
(echo "$PASSWORD"; echo "$PASSWORD") | ${pkgs.samba}/bin/smbpasswd -s ${primaryUser}
''; '';
}; };
}; };

View File

@@ -2,6 +2,7 @@
config, config,
lib, lib,
modulesPath, modulesPath,
primaryUser,
... ...
}: }:
@@ -32,6 +33,17 @@
''; '';
}; };
sops = {
secrets.smb_passwd = { };
templates.smb_credentials = {
content = ''
username=${primaryUser}
password=${config.sops.placeholder.smb_passwd}
'';
};
};
fileSystems = { fileSystems = {
"/" = { "/" = {
device = "/dev/disk/by-label/NIXROOT"; device = "/dev/disk/by-label/NIXROOT";
@@ -51,7 +63,32 @@
device = "/dev/disk/by-label/STORAGE"; device = "/dev/disk/by-label/STORAGE";
fsType = "ext4"; fsType = "ext4";
}; };
}
// builtins.listToAttrs (
map
(share: {
name = "/shares/${share}";
value = {
device = "//127.0.0.1/${share}";
fsType = "cifs";
options = [
"credentials=${config.sops.templates.smb_credentials.path}"
"iocharset=utf8"
"_netdev"
"auto"
"x-systemd.requires=samba-smbd.service"
"x-systemd.after=samba-smbd.service"
"x-systemd.requires=sops-install-secrets.service"
"x-systemd.after=sops-install-secrets.service"
];
}; };
})
[
"internal"
"fast"
"backup"
]
);
swapDevices = [ ]; swapDevices = [ ];