mirror of
https://github.com/elitak/nixos-infect.git
synced 2024-12-22 16:18:29 +03:00
Improve flexibility, enable pre-setting NIXOS_CONFIG, & NIXOS_LUSTRATE (#100)
* Improve flexibility, enable pre-setting of NIXOS_CONFIG, and NIXOS_LUSTRATE * Added success/failure to table * Use existing swap * Use existing swap * Check for exisitng Swap device * typo fix * typo fix
This commit is contained in:
parent
d9012e22d3
commit
90dbc4b073
2 changed files with 33 additions and 10 deletions
15
README.md
15
README.md
|
@ -182,10 +182,17 @@ Before executing the install script, you may need to check your mounts with `df
|
||||||
### Oracle Cloud Infrastructure
|
### Oracle Cloud Infrastructure
|
||||||
Tested for both VM.Standard.E2.1.Micro (x86) and VM.Standard.A1.Flex (AArch64) instances.
|
Tested for both VM.Standard.E2.1.Micro (x86) and VM.Standard.A1.Flex (AArch64) instances.
|
||||||
#### Tested on
|
#### Tested on
|
||||||
|Distribution| Name | Status | test date|
|
|Distribution| Name | Status | test date| Shape |
|
||||||
|------------|-----------------|-----------|----------|
|
|------------|-----------------|-----------|----------|----------|
|
||||||
|Oracle Linux| 7.9 |**success**|2021-05-31|
|
|Oracle Linux| 7.9 |**success**|2021-05-31| |
|
||||||
|Ubuntu | 20.04 |**success**|2022-03-23|
|
|Ubuntu | 20.04 |**success**|2022-03-23| |
|
||||||
|
|Ubuntu | 20.04 |**success**|2022-04-19| free arm |
|
||||||
|
|Oracle Linux| 8.0 | -failure- |2022-04-19| free amd |
|
||||||
|
|CentOS | 8.0 | -failure- |2022-04-19| free amd |
|
||||||
|
|Oracle Linux| 7.9[1] |**success**|2022-04-19| free amd |
|
||||||
|
|
||||||
|
[1] The Oracle 7.9 layout has 200Mb for /boot 8G for swap
|
||||||
|
PR#100 Adopted 8G Swap device
|
||||||
|
|
||||||
### Aliyun ECS
|
### Aliyun ECS
|
||||||
|
|
||||||
|
|
28
nixos-infect
28
nixos-infect
|
@ -28,7 +28,7 @@ makeConf() {
|
||||||
];
|
];
|
||||||
|
|
||||||
boot.cleanTmpDir = true;
|
boot.cleanTmpDir = true;
|
||||||
zramSwap.enable = true;
|
zramSwap.enable = ${zramswap};
|
||||||
networking.hostName = "$(hostname)";
|
networking.hostName = "$(hostname)";
|
||||||
services.openssh.enable = true;
|
services.openssh.enable = true;
|
||||||
users.users.root.openssh.authorizedKeys.keys = [$(while read -r line; do echo -n "
|
users.users.root.openssh.authorizedKeys.keys = [$(while read -r line; do echo -n "
|
||||||
|
@ -62,6 +62,7 @@ EOF
|
||||||
$bootcfg
|
$bootcfg
|
||||||
boot.initrd.kernelModules = [ "nvme" ];
|
boot.initrd.kernelModules = [ "nvme" ];
|
||||||
fileSystems."/" = { device = "$rootfsdev"; fsType = "$rootfstype"; };
|
fileSystems."/" = { device = "$rootfsdev"; fsType = "$rootfstype"; };
|
||||||
|
$swapcfg
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
@ -140,8 +141,21 @@ EOF
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkExistingSwap() {
|
||||||
|
SWAPSHOW=$(swapon --show --noheadings --raw)
|
||||||
|
zramswap=true
|
||||||
|
swapcfg=""
|
||||||
|
if [[ -n "$SWAPSHOW" ]]; then
|
||||||
|
SWAP_DEVICE="${SWAPSHOW%% *}"
|
||||||
|
if [[ "$SWAP_DEVICE" == "/dev/"* ]]; then
|
||||||
|
zramswap=false
|
||||||
|
swapcfg="swapDevices = [ { device = \"${SWAP_DEVICE}\"; } ];"
|
||||||
|
NO_SWAP=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
makeSwap() {
|
makeSwap() {
|
||||||
# TODO check currently available swapspace first
|
|
||||||
swapFile=$(mktemp /tmp/nixos-infect.XXXXX.swp)
|
swapFile=$(mktemp /tmp/nixos-infect.XXXXX.swp)
|
||||||
dd if=/dev/zero "of=$swapFile" bs=1M count=$((1*1024))
|
dd if=/dev/zero "of=$swapFile" bs=1M count=$((1*1024))
|
||||||
chmod 0600 "$swapFile"
|
chmod 0600 "$swapFile"
|
||||||
|
@ -274,7 +288,7 @@ infect() {
|
||||||
nix-channel --add "https://nixos.org/channels/$NIX_CHANNEL" nixos
|
nix-channel --add "https://nixos.org/channels/$NIX_CHANNEL" nixos
|
||||||
nix-channel --update
|
nix-channel --update
|
||||||
|
|
||||||
export NIXOS_CONFIG=/etc/nixos/configuration.nix
|
export NIXOS_CONFIG="${NIXOS_CONFIG:-/etc/nixos/configuration.nix}"
|
||||||
|
|
||||||
nix-env --set \
|
nix-env --set \
|
||||||
-I nixpkgs=$HOME/.nix-defexpr/channels/nixos \
|
-I nixpkgs=$HOME/.nix-defexpr/channels/nixos \
|
||||||
|
@ -291,15 +305,16 @@ infect() {
|
||||||
|
|
||||||
# Stage the Nix coup d'état
|
# Stage the Nix coup d'état
|
||||||
touch /etc/NIXOS
|
touch /etc/NIXOS
|
||||||
echo etc/nixos > /etc/NIXOS_LUSTRATE
|
echo etc/nixos >> /etc/NIXOS_LUSTRATE
|
||||||
echo etc/resolv.conf >> /etc/NIXOS_LUSTRATE
|
echo etc/resolv.conf >> /etc/NIXOS_LUSTRATE
|
||||||
echo root/.nix-defexpr/channels >> /etc/NIXOS_LUSTRATE
|
echo root/.nix-defexpr/channels >> /etc/NIXOS_LUSTRATE
|
||||||
|
|
||||||
rm -rf /boot.bak
|
rm -rf /boot.bak
|
||||||
isEFI && umount "$esp"
|
isEFI && umount "$esp"
|
||||||
mv -v /boot /boot.bak
|
|
||||||
|
mv -v /boot /boot.bak || { cp -a /boot /book.bak ; rm -rf /boot/* ; umount /boot ; }
|
||||||
if isEFI; then
|
if isEFI; then
|
||||||
mkdir /boot
|
mkdir -p /boot
|
||||||
mount "$esp" /boot
|
mount "$esp" /boot
|
||||||
find /boot -depth ! -path /boot -exec rm -rf {} +
|
find /boot -depth ! -path /boot -exec rm -rf {} +
|
||||||
fi
|
fi
|
||||||
|
@ -310,6 +325,7 @@ infect() {
|
||||||
|
|
||||||
checkEnv
|
checkEnv
|
||||||
prepareEnv
|
prepareEnv
|
||||||
|
checkExistingSwap
|
||||||
if [[ -z "$NO_SWAP" ]]; then
|
if [[ -z "$NO_SWAP" ]]; then
|
||||||
makeSwap # smallest (512MB) droplet needs extra memory!
|
makeSwap # smallest (512MB) droplet needs extra memory!
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue