Enhance Nix configuration: update backup file extension, add SSHFS and bind mounts for user directories, and introduce rebuild script for improved management

This commit is contained in:
Chris Toph 2025-03-04 14:22:02 -05:00
parent f86f184345
commit 41ba46324e
4 changed files with 131 additions and 6 deletions

View file

@ -41,7 +41,7 @@ in
# Force home-manager to use global packages
home-manager.useGlobalPkgs = true;
# If there is a conflict file that is backed up, use this extension
home-manager.backupFileExtension = "bk";
home-manager.backupFileExtension = "homeManagerBackupFileExtension";
# home-manager.useUserPackages = true;
## Overlays ##

View file

@ -8,7 +8,9 @@
modulesPath,
...
}:
let
username = config.hostSpec.username;
in
{
imports = [
(modulesPath + "/profiles/qemu-guest.nix")
@ -41,11 +43,33 @@
extraModulePackages = [ ];
};
fileSystems."/" = {
fileSystems = {
"/" = {
device = "/dev/disk/by-uuid/a0b82536-3087-410a-b283-60ea10811ef5";
fsType = "ext4";
};
"/pool" = {
device = "${username}@104.40.4.24:/pool";
fsType = "sshfs";
options = [
"defaults"
"reconnect"
"_netdev"
"allow_other"
"identityfile=/home/${username}/.ssh/pve"
];
};
"/home/${username}/git" = {
fsType = "none";
device = "/pool/git";
options = [
"bind"
"nofail"
];
};
};
swapDevices = [ ];
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking

73
scripts/rebuild.fish Normal file
View file

@ -0,0 +1,73 @@
#!/usr/bin/env fish
function red
# Usage: red <message> [<command-string>]
printf "\033[31m[!] %s \033[0m\n" $argv[1]
if test (count $argv) -ge 2
# If there's a second argument, we eval it and print in red as well
printf "\033[31m[!] %s \033[0m\n" (eval "$argv[2]")
end
end
function green
# Usage: green <message> [<command-string>]
printf "\033[32m[+] %s \033[0m\n" $argv[1]
if test (count $argv) -ge 2
printf "\033[32m[+] %s \033[0m\n" (eval "$argv[2]")
end
end
function yellow
# Usage: yellow <message> [<command-string>]
printf "\033[33m[*] %s \033[0m\n" $argv[1]
if test (count $argv) -ge 2
printf "\033[33m[*] %s \033[0m\n" (eval "$argv[2]")
end
end
# Build switch arguments
set switch_args "--show-trace" "--impure" "--flake"
# Check first argument
if test (count $argv) -gt 0 -a "$argv[1]" = "trace"
set switch_args $switch_args "--show-trace"
else if test (count $argv) -gt 0
set HOST $argv[1]
else
set HOST (hostname)
end
# Append flake and host switch
set switch_args $switch_args ".#$HOST" "switch"
green "====== REBUILD ======"
# Check if `nh` exists
if type -q nh
find ~ -type f -name "*.homeManagerBackupFileExtension" -delete
set -x REPO_PATH (pwd)
nh os switch . -- --impure --show-trace
else
find ~ -type f -name "*.homeManagerBackupFileExtension" -delete
sudo nixos-rebuild $switch_args
end
# If successful
if test $status -eq 0
green "====== POST-REBUILD ======"
green "Rebuilt successfully"
# Check for a clean git working directory
if git diff --exit-code >/dev/null
and git diff --staged --exit-code >/dev/null
# Check if the current HEAD commit is already tagged as buildable
if git tag --points-at HEAD | grep -q buildable
yellow "Current commit is already tagged as buildable"
else
git tag buildable-(date +%Y%m%d%H%M%S) -m ''
green "Tagged current commit as buildable"
end
else
yellow "WARN: There are pending changes that would affect the build succeeding. Commit them before tagging"
end
end

28
shell.nix Normal file
View file

@ -0,0 +1,28 @@
# Shell for bootstrapping flake-enabled nix and other tooling
{
pkgs ?
# If pkgs is not defined, instantiate nixpkgs from locked commit
let
lock = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.nixpkgs.locked;
nixpkgs = fetchTarball {
url = "https://github.com/nixos/nixpkgs/archive/${lock.rev}.tar.gz";
sha256 = lock.narHash;
};
in
import nixpkgs { overlays = [ ]; },
...
}:
{
default = pkgs.mkShell {
nativeBuildInputs = builtins.attrValues {
inherit (pkgs)
nix
home-manager
nh
git
bats # for bash testing
;
};
};
}