1
1
Fork 0

Compare commits

..

No commits in common. "d3f2fcb28e92fd190e5c7288abfd4a37bb11b0d6" and "62adee6a8963df5cc1b4dbab056f2ec895970cf3" have entirely different histories.

2 changed files with 121 additions and 7 deletions

View file

@ -1,7 +1,3 @@
# WARNING
## This configuration is not meant for public usage
# Install
## Remote (with NixOS Anywhere)
@ -18,10 +14,12 @@
4. Create machine-specific modules in `machines/MACHINE/`
b. Machine configuration and hostname in `default.nix`
a. If [Home Manager](https://github.com/nix-community/home-manager), home configuration in `home.nix`
b. System configuration and hostname in `system.nix`
```nix
{ custom.hostname = "MACHINE"; }
{ networking.hostName = "MACHINE"; }
```
c. [Disko](https://github.com/nix-community/disko) layout in `disko.nix`
@ -40,10 +38,12 @@
nixos-generate-config --show-hardware-config --no-filesystems --root /mnt
```
e. Import modules in `default.nix`
5. Choose profile and add machine-specific modules to `flake.in.nix`
```nix
MACHINE = BRANCH [ ./profiles/PROFILE ./machines/MACHINE ];
MACHINE = linux [ ./profiles/PROFILE ./machines/MACHINE ];
```
6. Generate `flake.nix` with [flakegen](https://github.com/jorsn/flakegen)
@ -74,3 +74,41 @@
```
9. Shutdown, detach ISO, and reboot
## Local (with script)
1. Clone repository using personal access token
```sh
git clone https://TOKEN@github.com/Myned/nixos /tmp/nixos
```
2. Go to repository directory
```sh
cd /tmp/nixos
```
3. Check disk layout
```sh
lsblk
```
4. Modify disko layout to match hardware
```sh
nano machine/MACHINE/disko.nix
```
5. Execute install script
```sh
sudo nix --experimental-features 'nix-command flakes' run nixpkgs#fish -- install.fish
```
6. Optionally shred personal access token
```sh
shred -zu github.token
```

76
install.fish Normal file
View file

@ -0,0 +1,76 @@
#!/usr/bin/env fish
# sudo nix --experimental-features 'nix-command flakes' run nixpkgs#fish -- install.fish
# Wrap command execution in log output with error handling
function execute
if $argv &>>install.log
echo " done."
else
echo " error."
exit 1
end
end
# Alias nix to enable flakes
alias nix "nix --experimental-features 'nix-command flakes'"
# Gather variables
set -l machine (read -P "Enter machine hostname: ")
set -l secret (read -P "Enter encryption secret: ")
# Clear logfile
echo "Logging to install.log..."
rm install.log &>/dev/null
# Create keyfile
echo -n "Creating secret.key..."
execute nix run nixpkgs#fish -- -c "echo -n $secret > /tmp/secret.key"
# Format disks
echo -n "Formatting disks..."
execute nix run disko -- -m disko machines/$machine/disko.nix
# Shred keyfile
echo -n "Shredding secret.key..."
execute shred -zu /tmp/secret.key
# Generate hardware configuration
echo -n "Generating hardware-configuration.nix..."
execute nixos-generate-config --no-filesystems --root /mnt --dir .
# Move hardware configuration
echo -n "Moving hardware-configuration.nix to machines/$machine/..."
execute mv hardware-configuration.nix machines/$machine/
# Stage files in git tree for flake to access
git add .
# Update flake
echo -n "Updating flake.lock..."
execute nix flake update
# Confirm installation of NixOS
while true
switch (read -P "Install NixOS? [Y/N] ")
case Y y
break
case N n
exit
end
end
# Install NixOS
echo -n "Installing..."
execute nixos-install --no-root-password --flake .#$machine
# Update git remote to remove personal access token
echo -n "Updating git remotes..."
git remote rm origin
execute git remote add git@github.com/Myned/nixos.git
# Copy NixOS configuration to system
echo -n "Copying NixOS configuration to /mnt/etc/nixos/..."
execute cp -r . /mnt/etc/nixos/
# Finish
echo "Installation finished. Reboot when ready."