forked from Mirrors/nixos-infect
more cleanup
This commit is contained in:
parent
c769beaddf
commit
6e910a3c1b
1 changed files with 45 additions and 38 deletions
83
nixos-infect
83
nixos-infect
|
@ -11,21 +11,24 @@
|
||||||
# - Deploy a Debian 8.3 x64 droplet (enable ipv6; add your ssh key)
|
# - Deploy a Debian 8.3 x64 droplet (enable ipv6; add your ssh key)
|
||||||
# - cat customConfig.optional nixos-infect | ssh root@targethost bash
|
# - cat customConfig.optional nixos-infect | ssh root@targethost bash
|
||||||
#
|
#
|
||||||
# This was last tested with the DigitalOcean Debian 8.3 x64 image. Different
|
# This was last tested with the DigitalOcean Debian 8.3 x64 and Ubuntu 15.10
|
||||||
# versions as well as the Ubuntu images should work as well, but then, there's
|
# x64 images. Different versions and archs (namely i386) should work as well,
|
||||||
# not much point in selecting something different if you intend to wipe out the
|
# but then, there's not much point in selecting something different if you
|
||||||
# fs as this does. You may need to make minor modifications to use in other
|
# intend to wipe out the fs, as this script does. You may need to make minor
|
||||||
# templates, but basically all that will ever need tweaking should be:
|
# modifications to use in other templates, but basically all that will ever
|
||||||
# /etc/nixos/{,hardware-}configuration.nix, inline in this file
|
# need tweaking are already inlined in this file:
|
||||||
# /etc/nixso/networking.nix, generated at runtime (no ipv6? different number of adapters?)
|
# /etc/nixos/{,hardware-}configuration.nix : rudimentary mostly static config
|
||||||
|
# /etc/nixos/networking.nix, networking settings determined at runtime
|
||||||
|
# tweak if no ipv6, different number of adapters, etc.
|
||||||
#
|
#
|
||||||
# Motivation: nixos-assimilate should supplant this script entirely, if it's
|
# Motivation for this script: nixos-assimilate should supplant this script
|
||||||
# ever completed. nixos-in-place was quite broken when I tried it, and also
|
# entirely, if it's ever completed. nixos-in-place was quite broken when I
|
||||||
# took a pretty janky approach that was substantially more complex than this
|
# tried it, and also took a pretty janky approach that was substantially more
|
||||||
# (although it supported more platforms): it didn't install to root (/nixos
|
# complex than this (although it supported more platforms): it didn't install
|
||||||
# instead), left dregs of the old filesystem (almost always unnecessary since
|
# to root (/nixos instead), left dregs of the old filesystem (almost always
|
||||||
# starting from a fresh deployment), and most importantly, simply didn't work for
|
# unnecessary since starting from a fresh deployment), and most importantly,
|
||||||
# me! (old system was being because grub wasnt properly reinstalled)
|
# simply didn't work for me! (old system was being because grub wasnt properly
|
||||||
|
# reinstalled)
|
||||||
|
|
||||||
set -ex
|
set -ex
|
||||||
|
|
||||||
|
@ -33,33 +36,31 @@ makeConf() {
|
||||||
# NB remember to escape / $ ` in heredocs!
|
# NB remember to escape / $ ` in heredocs!
|
||||||
# TODO use appended archive or some curl-able tarball?
|
# TODO use appended archive or some curl-able tarball?
|
||||||
mkdir -p /etc/nixos
|
mkdir -p /etc/nixos
|
||||||
|
IFS=$'\n'; keys=($(cat /root/.ssh/authorized_keys))
|
||||||
cat > /etc/nixos/networking.nix << EOF
|
cat > /etc/nixos/networking.nix << EOF
|
||||||
# This file will be populated at runtime with the
|
# This file will be populated at runtime with the
|
||||||
# networking details gathered from the active system.
|
# networking details gathered from the active system.
|
||||||
{...}:{}
|
{...}:{}
|
||||||
EOF
|
EOF
|
||||||
cat > /etc/nixos/configuration.nix << EOF
|
cat > /etc/nixos/configuration.nix << EOF
|
||||||
{ config, pkgs, ... }: {
|
{ ... }: {
|
||||||
imports = [
|
imports = [
|
||||||
./hardware-configuration.nix
|
./hardware-configuration.nix
|
||||||
./networking.nix
|
./networking.nix # generated at runtime by nixos-infect
|
||||||
];
|
];
|
||||||
|
|
||||||
time.timeZone = "America/Los_Angeles";
|
|
||||||
boot.cleanTmpDir = true;
|
boot.cleanTmpDir = true;
|
||||||
|
|
||||||
services.tlsdated.enable = true;
|
|
||||||
services.openssh.enable = true;
|
|
||||||
networking.firewall.allowPing = true;
|
|
||||||
networking.hostName = "$(hostname)";
|
networking.hostName = "$(hostname)";
|
||||||
users.users.root.openssh.authorizedKeys.keys = [ ''
|
networking.firewall.allowPing = true;
|
||||||
$(cat /root/.ssh/authorized_keys | head -n1)
|
services.openssh.enable = true;
|
||||||
'' ];
|
users.users.root.openssh.authorizedKeys.keys = [$(for key in ${keys[@]}; do echo -n "
|
||||||
|
\"$key\""; done)
|
||||||
|
];
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
# (nixos-generate-config will add qemu-user and bind-mounts, so avoid)
|
# (nixos-generate-config will add qemu-user and bind-mounts, so avoid)
|
||||||
cat > /etc/nixos/hardware-configuration.nix << EOF
|
cat > /etc/nixos/hardware-configuration.nix << EOF
|
||||||
{ config, lib, pkgs, ... }: {
|
{ ... }: {
|
||||||
imports = [ <nixpkgs/nixos/modules/profiles/qemu-guest.nix> ];
|
imports = [ <nixpkgs/nixos/modules/profiles/qemu-guest.nix> ];
|
||||||
boot.loader.grub.devices = [ "/dev/vda" ];
|
boot.loader.grub.devices = [ "/dev/vda" ];
|
||||||
fileSystems."/" = { device = "/dev/vda1"; fsType = "ext4"; };
|
fileSystems."/" = { device = "/dev/vda1"; fsType = "ext4"; };
|
||||||
|
@ -134,30 +135,36 @@ source /nix/var/nix/profiles/system/etc/profile
|
||||||
# XXX temporary fix for name resolution
|
# XXX temporary fix for name resolution
|
||||||
echo nameserver 8.8.4.4 > /etc/resolv.conf
|
echo nameserver 8.8.4.4 > /etc/resolv.conf
|
||||||
|
|
||||||
ip4s=$(ip address show dev eth0 | grep 'inet ' | sed -r 's|.*inet ([0-9.]+)/([0-9]+).*|{ address="\1"; prefixLength=\2; }|')
|
IFS=$'\n'
|
||||||
ip6s=$(ip address show dev eth0 | grep 'inet6 .*global' | sed -r 's|.*inet6 ([0-9a-f:]+)/([0-9]+).*|{ address="\1"; prefixLength=\2; }|')
|
ip4s=($(ip address show dev eth0 | grep 'inet ' | sed -r 's|.*inet ([0-9.]+)/([0-9]+).*|{ address="\1"; prefixLength=\2; }|'))
|
||||||
gateway=$(ip route show dev eth0 | grep default | sed -r 's|default via ([0-9.]+).*|\1|')
|
ip6s=($(ip address show dev eth0 | grep 'inet6 .*global' | sed -r 's|.*inet6 ([0-9a-f:]+)/([0-9]+).*|{ address="\1"; prefixLength=\2; }|'))
|
||||||
gateway6=$(ip -6 route show dev eth0 | grep default | sed -r 's|default via ([0-9a-f:]+).*|\1|')
|
gateway=($(ip route show dev eth0 | grep default | sed -r 's|default via ([0-9.]+).*|\1|'))
|
||||||
ether0=$(ip address show dev eth0 | grep link/ether | sed -r 's|.*link/ether ([0-9a-f:]+) .*|\1|')
|
gateway6=($(ip -6 route show dev eth0 | grep default | sed -r 's|default via ([0-9a-f:]+).*|\1|'))
|
||||||
ether1=$(ip address show dev eth1 | grep link/ether | sed -r 's|.*link/ether ([0-9a-f:]+) .*|\1|')
|
ether0=($(ip address show dev eth0 | grep link/ether | sed -r 's|.*link/ether ([0-9a-f:]+) .*|\1|'))
|
||||||
|
ether1=($(ip address show dev eth1 | grep link/ether | sed -r 's|.*link/ether ([0-9a-f:]+) .*|\1|'))
|
||||||
|
|
||||||
cat > /etc/nixos/networking.nix << EOF
|
cat > /etc/nixos/networking.nix << EOF
|
||||||
{ config, pkgs, ... }: {
|
{ ... }: {
|
||||||
networking = {
|
networking = {
|
||||||
nameservers = [ "8.8.4.4" ];
|
nameservers = [ "8.8.4.4" ];
|
||||||
defaultGateway = "$gateway";
|
defaultGateway = "${gateway}";
|
||||||
defaultGateway6 = "$gateway6";
|
defaultGateway6 = "${gateway6}";
|
||||||
interfaces = {
|
interfaces = {
|
||||||
eth0 = {
|
eth0 = {
|
||||||
ip4 = [ $ip4s ];
|
ip4 = [$(for a in ${ip4s[@]}; do echo -n "
|
||||||
ip6 = [ $ip6s ];
|
$a"; done)
|
||||||
|
];
|
||||||
|
ip6 = [$(for a in ${ip6s[@]}; do echo -n "
|
||||||
|
$a"; done)
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
# eth1 is for private networking or something?
|
||||||
eth1.useDHCP = false;
|
eth1.useDHCP = false;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
services.udev.extraRules = ''
|
services.udev.extraRules = ''
|
||||||
KERNEL=="eth*", ATTR{address}=="$ether0", NAME="eth0"
|
KERNEL=="eth*", ATTR{address}=="${ether0}", NAME="eth0"
|
||||||
KERNEL=="eth*", ATTR{address}=="$ether1", NAME="eth1"
|
KERNEL=="eth*", ATTR{address}=="${ether1}", NAME="eth1"
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
Loading…
Reference in a new issue