Harden NixOS config defaults and setup guidance #4
Reference in New Issue
Block a user
Delete Branch "copilot/review-nixos-setup-issues"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The current NixOS setup had fragile defaults and placeholder-driven paths that could break evaluation or confuse users. This PR tightens configuration validation and clarifies setup steps to avoid common misconfigurations.
hostname/usernameinflake.nixand pass viaspecialArgsExample:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
Pull request overview
This PR hardens the NixOS configuration by centralizing hostname and username settings, adding validation, and improving password handling. The changes move away from inline placeholder values to a centralized configuration approach in
flake.nix.Changes:
hostnameandusernameinflake.nixwith validation and propagate viaspecialArgshashedPasswordtohashedPasswordFilefor improved securityReviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
hashedPasswordFile, reorganizes environment variables💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The setup instructions don't mention creating the password hash file before the first build, but this is required because
hashedPasswordFileis used in the user configuration. Add a new step between "Review Configuration Defaults" and "Stage Files in Git" that instructs users to create the password hash file. This is a prerequisite for the first successful build.The README instructions for password setup in the "Post-Installation" section should be moved to the setup instructions before the first build. The current flow requires users to successfully build the system first, but the build will fail if the password hash file doesn't exist. Users need to create this file before running
nixos-rebuildfor the first time.@@ -41,1 +43,3 @@specialArgs = { inherit inputs system; };usernameValid =builtins.match "^[a-z_][a-z0-9_]*$" username != null&& builtins.match "^_+$" username == nullThe username validation regex allows usernames that consist only of underscores followed by other characters (e.g., "___abc"), but the second check
builtins.match "^_+$" username == nullonly rejects usernames that are entirely underscores. According to standard Unix username conventions, usernames starting with underscore are typically reserved for system accounts. Consider strengthening the validation to reject any username starting with underscore unless that's intentionally allowed for system accounts.@@ -42,0 +47,4 @@&& username != "root";hostConfig = assert builtins.pathExists (./hosts + "/${hostname}/hardware-configuration.nix");./hosts + "/${hostname}/hardware-configuration.nix";passwordHashPath = "/etc/nixos/secrets/${username}/password.hash";The assertion for
hostConfigwill fail at evaluation time with a cryptic error if the path doesn't exist. The assert statement should provide a helpful error message to guide users. Consider using a let-binding with an abort statement that provides a clear message like: "Hardware configuration not found at ./hosts/${hostname}/hardware-configuration.nix. Please ensure the directory exists and contains the hardware configuration file."@@ -42,0 +48,4 @@hostConfig = assert builtins.pathExists (./hosts + "/${hostname}/hardware-configuration.nix");./hosts + "/${hostname}/hardware-configuration.nix";passwordHashPath = "/etc/nixos/secrets/${username}/password.hash";specialArgs = { inherit inputs system hostname username usernameValid passwordHashPath; };The
passwordHashPathis hardcoded to a system location that may not exist on first installation, but there's no validation or assertion to check if this file exists. This will cause the system build to fail with an unclear error. Consider adding an assertion incommon.nixto check if the password hash file exists, with a helpful error message directing users to the password setup instructions in the README. Alternatively, document that users must create this file before their first build.