fixup! nix/os/devices/CFB4ED74: add static ipv6 static address
This commit is contained in:
parent
e6c4a19832
commit
9fae53fac7
2 changed files with 18 additions and 5 deletions
135
nix/os/devices/disk.nix
Normal file
135
nix/os/devices/disk.nix
Normal file
|
@ -0,0 +1,135 @@
|
|||
{ pkgs ? import <nixpkgs> {}
|
||||
, ownLib ? import ../lib/default.nix { }
|
||||
, dir
|
||||
, rebuildarg
|
||||
, moreargs ? ""
|
||||
, diskId ? (import ((builtins.getEnv "PWD")+"/${dir}/hw.nix") {}).hardware.encryptedDisk.diskId
|
||||
, gitRoot ? "$(git rev-parse --show-toplevel)"
|
||||
}:
|
||||
|
||||
let
|
||||
mntRootVol="/mnt/${diskId}-root";
|
||||
|
||||
in rec {
|
||||
rebuild = pkgs.writeScript "script" ''
|
||||
#!/usr/bin/env bash
|
||||
set -xe
|
||||
|
||||
pushd ${gitRoot}/${dir}
|
||||
export NIXOS_CONFIG="$PWD"/configuration.nix
|
||||
|
||||
[[ -e "''${NIXOS_CONFIG}" ]]
|
||||
|
||||
nixos-rebuild -I nixos-config=''${NIXOS_CONFIG} ${rebuildarg} ${moreargs}
|
||||
if test -L result; then
|
||||
rm result
|
||||
fi
|
||||
'';
|
||||
|
||||
diskMount = pkgs.writeScript "script" ''
|
||||
#!/usr/bin/env bash
|
||||
set -xe
|
||||
echo Mounting ${diskId}
|
||||
cryptsetup luksOpen ${ownLib.disk.bootLuksDevice diskId} ${ownLib.disk.luksName diskId}
|
||||
sleep 1
|
||||
vgchange -ay ${ownLib.disk.volumeGroup diskId}
|
||||
mkdir -p /mnt
|
||||
mkdir ${mntRootVol}
|
||||
mount ${ownLib.disk.rootFsDevice diskId} ${mntRootVol}
|
||||
mount ${ownLib.disk.rootFsDevice diskId} ${mntRootVol}/nixos/home -o subvol=home
|
||||
mount ${ownLib.disk.bootFsDevice diskId} ${mntRootVol}/nixos/boot
|
||||
'';
|
||||
|
||||
diskUmount = pkgs.writeScript "script" ''
|
||||
#!/usr/bin/env bash
|
||||
set -xe
|
||||
umount -R ${mntRootVol}
|
||||
rmdir ${mntRootVol}
|
||||
vgchange -an ${ownLib.disk.volumeGroup diskId}
|
||||
cryptsetup luksClose ${ownLib.disk.luksName diskId}
|
||||
sync
|
||||
'';
|
||||
|
||||
diskInstall = pkgs.writeScript "script" ''
|
||||
#!/usr/bin/env bash
|
||||
set -xe
|
||||
pushd ${gitRoot}/${dir}
|
||||
export NIXOS_CONFIG="$PWD"/configuration.nix
|
||||
|
||||
[[ -e "''${NIXOS_CONFIG}" ]]
|
||||
[[ -e "${mntRootVol}/nixos" ]]
|
||||
|
||||
nixos-install --max-jobs 5 --cores 4 --no-root-passwd --root ${mntRootVol}/nixos
|
||||
'';
|
||||
|
||||
diskPrepare = pkgs.writeScript "script" ''
|
||||
#!/usr/bin/env bash
|
||||
set -xe
|
||||
|
||||
read -p "Continue to format ${ownLib.disk.bootGrubDevice diskId} (YES/n)?" choice
|
||||
case "$choice" in
|
||||
YES ) echo "Continuing in 3 seconds..."; sleep 3;;
|
||||
n|N ) echo "Exiting..."; exit 0;;
|
||||
* ) echo "Exiting..."; exit 1;;
|
||||
esac
|
||||
|
||||
# Partition
|
||||
sync
|
||||
{
|
||||
fdisk -w always -W always ${ownLib.disk.bootGrubDevice diskId} <<EOF
|
||||
g
|
||||
n
|
||||
1
|
||||
|
||||
+1M
|
||||
n
|
||||
2
|
||||
|
||||
+512M
|
||||
n
|
||||
3
|
||||
|
||||
|
||||
t
|
||||
1
|
||||
4
|
||||
x
|
||||
n
|
||||
2
|
||||
2-${diskId}
|
||||
n
|
||||
3
|
||||
3-${diskId}
|
||||
r
|
||||
w
|
||||
EOF
|
||||
} || {
|
||||
sync
|
||||
partprobe ${ownLib.disk.bootGrubDevice diskId}
|
||||
}
|
||||
|
||||
# Encrypt
|
||||
cryptsetup luksFormat ${ownLib.disk.bootLuksDevice diskId} -
|
||||
cryptsetup luksOpen ${ownLib.disk.bootLuksDevice diskId} ${ownLib.disk.luksName diskId}
|
||||
|
||||
# LVM
|
||||
vgcreate ${ownLib.disk.volumeGroup diskId} ${ownLib.disk.luksPhysicalVolume diskId}
|
||||
lvcreate ${ownLib.disk.volumeGroup diskId} -L 2G -n swap
|
||||
lvcreate ${ownLib.disk.volumeGroup diskId} -l 100%FREE -n root
|
||||
|
||||
# Filesystem
|
||||
mkfs.vfat -F32 ${ownLib.disk.bootFsDevice diskId}
|
||||
mkfs.btrfs ${ownLib.disk.rootFsDevice diskId}
|
||||
mkswap ${ownLib.disk.swapFsDevice diskId}
|
||||
|
||||
# Subvolume and FS hierharchy
|
||||
mkdir -p /mnt
|
||||
mkdir ${mntRootVol}
|
||||
mount ${ownLib.disk.rootFsDevice diskId} ${mntRootVol}
|
||||
btrfs subvolume create ${mntRootVol}/nixos
|
||||
btrfs subvolume create ${mntRootVol}/home
|
||||
mkdir ${mntRootVol}/nixos/{boot,home}
|
||||
|
||||
${diskUmount}
|
||||
'';
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue