From 958247b22ca7270387d78f26e0e2580b66a66a21 Mon Sep 17 00:00:00 2001 From: oqyude Date: Fri, 2 Oct 2026 23:05:00 +0300 Subject: [PATCH] soft coding --- configurations/mobile.nix | 4 ++-- home/secondary.nix | 2 +- home/termux.nix | 16 ++++++++-------- lib/xlib/default.nix | 14 +++++++++++++- lib/xlib/device.nix | 8 ++++++++ lib/xlib/helpers.nix | 13 +++++++++---- modules/essentials/packages.nix | 3 ++- modules/essentials/shell.nix | 7 ++++--- modules/essentials/systemd-routines.nix | 4 ++-- modules/server/nextcloud.nix | 2 +- modules/users.nix | 6 ++++++ modules/vds/systemd.nix | 2 +- modules/wsl/containers/default.nix | 2 +- 13 files changed, 58 insertions(+), 25 deletions(-) diff --git a/configurations/mobile.nix b/configurations/mobile.nix index a271b18..c4f99f0 100644 --- a/configurations/mobile.nix +++ b/configurations/mobile.nix @@ -27,10 +27,10 @@ let # (default is bashInteractive) user.shell = "${pkgs.zsh}/bin/zsh"; - # SSH user (matches `User oqyude` in the client's ~/.ssh/config). + # SSH user (matches the `User` entries in the client's ~/.ssh/config). # Default is "nix-on-droid"; home stays at the read-only # /data/data/com.termux.nix/files/home either way. - user.userName = "oqyude"; + user.userName = xlib.device.username; # Minimal termux settings (nix-on-droid options only: # environment.*, nix.*, time.*, user.*, system.*, android-integration.*) diff --git a/home/secondary.nix b/home/secondary.nix index c40292e..6516262 100644 --- a/home/secondary.nix +++ b/home/secondary.nix @@ -14,7 +14,7 @@ let "${config.home.homeDirectory}/Games/PrismLaunchers/${config.home.username}" = ".local/share/PrismLauncher"; - "${xlib.dirs.lamet-drive}/Users/oqyude/Music" = "Music"; + "${xlib.dirs.lamet-drive}/Users/${xlib.device.username}/Music" = "Music"; }; mkLinks = lib.mapAttrs' (sourcePath: targetPath: { name = targetPath; diff --git a/home/termux.nix b/home/termux.nix index c0da3bb..25ce6f3 100644 --- a/home/termux.nix +++ b/home/termux.nix @@ -218,7 +218,7 @@ enable = true; settings = { user = { - name = "oqyude"; + name = xlib.device.username; email = "oqyude@gmail.com"; }; pull = { @@ -250,31 +250,31 @@ }; sapphira = { HostName = "192.168.1.20"; - User = "oqyude"; + User = xlib.device.username; }; sapphira-tailscale = { HostName = "100.64.0.0"; - User = "oqyude"; + User = xlib.device.username; }; otreca-old = { HostName = "217.60.3.12"; - User = "oqyude"; + User = xlib.device.username; }; otreca = { HostName = "109.248.161.5"; - User = "oqyude"; + User = xlib.device.username; }; otreca-tailscale = { HostName = "100.64.1.0"; - User = "oqyude"; + User = xlib.device.username; }; rydiwo = { HostName = "192.168.1.102"; - User = "oqyude"; + User = xlib.device.username; }; epral = { HostName = "192.168.1.101"; - User = "oqyude"; + User = xlib.device.username; Port = 8022; }; }; diff --git a/lib/xlib/default.nix b/lib/xlib/default.nix index e7bf951..2ffce36 100644 --- a/lib/xlib/default.nix +++ b/lib/xlib/default.nix @@ -40,6 +40,8 @@ in hostname, type, username ? "oqyude", + uid ? 1000, + gid ? 1000, }: let device = mkDevice { @@ -47,6 +49,8 @@ in hostname type username + uid + gid ; }; in @@ -56,11 +60,19 @@ in hostname type username + uid + gid ; }; isDesktop = device.isDesktop; isHeadless = device.isHeadless; dirs = mkDirs username; - inherit helpers; + # Bind the host's ids into the mount helpers, so ntfs3/exfat options + # carry the same uid/gid the primary user actually has. + helpers = import ./helpers.nix { + inherit lib; + uid = device.uid; + gid = device.gid; + }; }; } \ No newline at end of file diff --git a/lib/xlib/device.nix b/lib/xlib/device.nix index a49b465..0a1ef02 100644 --- a/lib/xlib/device.nix +++ b/lib/xlib/device.nix @@ -49,6 +49,12 @@ in hostname, type, username ? "oqyude", + # The primary user is pinned to 1000 rather than left to NixOS' + # nextfree logic: the mount helpers below write uid=/gid= into + # ntfs3/exfat options, and an NTFS/exFAT volume mounted with a + # different id shows every file as owned by `nobody`. + uid ? 1000, + gid ? 1000, }: let capabilities = devices.${type} or (throw "xlib: unknown device type '${type}', expected one of ${lib.concatStringsSep ", " (builtins.attrNames devices)}"); @@ -58,6 +64,8 @@ in hostname type username + uid + gid ; isDesktop = capabilities.desktop; isHeadless = capabilities.headless; diff --git a/lib/xlib/helpers.nix b/lib/xlib/helpers.nix index ee126a3..14859f6 100644 --- a/lib/xlib/helpers.nix +++ b/lib/xlib/helpers.nix @@ -1,5 +1,10 @@ { lib, + # The primary user's ids, bound from xlib.device by mkXlib. ntfs3/exfat + # volumes carry POSIX ids, so a mount using anything other than the real + # uid/gid shows every file as owned by `nobody`. + uid, + gid, ... }: # Pure helper functions for module definitions. @@ -105,8 +110,8 @@ let fsType = "ntfs3"; options = [ "defaults" - "uid=1000" - "gid=1000" + "uid=${toString uid}" + "gid=${toString gid}" "fmask=${mask}" "dmask=${mask}" "nofail" @@ -128,8 +133,8 @@ let fsType = "exfat"; options = [ "nofail" - "uid=1000" - "gid=1000" + "uid=${toString uid}" + "gid=${toString gid}" ]; }; }; diff --git a/modules/essentials/packages.nix b/modules/essentials/packages.nix index 3862902..cbaa698 100644 --- a/modules/essentials/packages.nix +++ b/modules/essentials/packages.nix @@ -2,6 +2,7 @@ config, pkgs, inputs, + xlib, ... }: { @@ -185,7 +186,7 @@ enable = true; config = { user = { - name = "oqyude"; + name = xlib.device.username; email = "oqyude@gmail.com"; }; pull = { diff --git a/modules/essentials/shell.nix b/modules/essentials/shell.nix index 56ec25b..b2ed6ab 100644 --- a/modules/essentials/shell.nix +++ b/modules/essentials/shell.nix @@ -1,6 +1,7 @@ { config, pkgs, + xlib, ... }: { @@ -20,7 +21,7 @@ }; shellInit = '' beet-p() { - local base="/home/oqyude/.config/beets/My" + local base="${xlib.dirs.user-home}/.config/beets/My" local rel rel=$(realpath --relative-to="$base" "$PWD") beet mod "path:$rel" playlist="$*" @@ -29,7 +30,7 @@ beet im ./ -S $* } beet-path() { - realpath --relative-to="/home/oqyude/.config/beets/My" "$1" + realpath --relative-to="${xlib.dirs.user-home}/.config/beets/My" "$1" } ''; shellAliases = { @@ -45,7 +46,7 @@ gc = "git add . && git commit -m 'dev: автокоммит $(date +'%Y-%m-%d %H:%M:%S')'"; y = "yazi"; nix-shellp = "nix-shell --run $SHELL -p"; - beet-path-library = "realpath --relative-to='/home/oqyude/.config/beets/My' ."; + beet-path-library = "realpath --relative-to='${xlib.dirs.user-home}/.config/beets/My' ."; z-proxy = "export ALL_PROXY=socks5://localhost:10808"; zh-proxy = "export HTTPS_PROXY=http://localhost:10808 && export HTTP_PROXY=http://localhost:10808"; diff --git a/modules/essentials/systemd-routines.nix b/modules/essentials/systemd-routines.nix index ad29bf2..255bdad 100644 --- a/modules/essentials/systemd-routines.nix +++ b/modules/essentials/systemd-routines.nix @@ -11,13 +11,13 @@ description = "Prebuild NixOS closure"; serviceConfig = { CPUQuota = "20%"; - User = "oqyude"; + User = xlib.device.username; Group = "users"; Nice = 10; Type = "oneshot"; WorkingDirectory = "/tmp"; Environment = [ - "HOME=/home/oqyude" + "HOME=${xlib.dirs.user-home}" ]; ExecStart = '' ${pkgs.nix}/bin/nix build --no-link /etc/nixos#nixosConfigurations.${config.networking.hostName}.config.system.build.toplevel diff --git a/modules/server/nextcloud.nix b/modules/server/nextcloud.nix index 79481f5..a0501f4 100644 --- a/modules/server/nextcloud.nix +++ b/modules/server/nextcloud.nix @@ -64,7 +64,7 @@ dbtype = "pgsql"; dbuser = "nextcloud"; dbname = "nextcloud"; - adminuser = "oqyude"; + adminuser = xlib.device.username; adminpassFile = config.sops.secrets.nextcloud-adminpass.path; }; settings = { diff --git a/modules/users.nix b/modules/users.nix index d2697ca..92e9a26 100644 --- a/modules/users.nix +++ b/modules/users.nix @@ -44,6 +44,12 @@ in name = "${user}"; isNormalUser = true; group = "users"; + # Pinned, not left to NixOS' nextfree logic: the ntfs3/exfat mount + # helpers (lib/xlib/helpers.nix) write the same uid into their mount + # options, so both sides have to agree or NTFS files show up as owned + # by `nobody`. NixOS has no per-user `gid` option — the primary group + # id comes from `group` above. + uid = xlib.device.uid; description = "Jor Oqyude"; hashedPasswordFile = config.sops.secrets.hashed_password.path; # hashed_password homeMode = "700"; diff --git a/modules/vds/systemd.nix b/modules/vds/systemd.nix index bce0089..829d45b 100644 --- a/modules/vds/systemd.nix +++ b/modules/vds/systemd.nix @@ -7,7 +7,7 @@ }: let serviceName = "rsync-services-sync"; - serverAddress = "oqyude@100.64.0.0"; + serverAddress = "${xlib.device.username}@100.64.0.0"; serverDir = "${xlib.dirs.services-nodes-folder}/${xlib.device.hostname}"; nodeDir = "${xlib.dirs.services-mnt-folder}"; in diff --git a/modules/wsl/containers/default.nix b/modules/wsl/containers/default.nix index dea844e..7d6119b 100644 --- a/modules/wsl/containers/default.nix +++ b/modules/wsl/containers/default.nix @@ -7,7 +7,7 @@ { imports = [ # shared container modules live in ../../containers - # ../../containers/3x-ui.nix + ../../containers/silero-tts.nix ]; environment.systemPackages = with pkgs; [