updates to incorporate cascade installer
This commit is contained in:
parent
baf04cc75d
commit
858aa43c40
9
common/cascade-packages.nix
Normal file
9
common/cascade-packages.nix
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
with import (toString ../functions);
|
||||||
|
with builtins;
|
||||||
|
|
||||||
|
{pkgs, ...}:
|
||||||
|
{
|
||||||
|
|
||||||
|
config.nixpkgs.overlays = attrValues (import-folder {path = (toString ../overlays);});
|
||||||
|
|
||||||
|
}
|
|
@ -1,36 +1,53 @@
|
||||||
with builtins;
|
with builtins;
|
||||||
with import (toString ../functions);
|
with import (toString ../functions);
|
||||||
|
|
||||||
{config, lib, ...}: {
|
{pkgs, config, lib, ...}: {
|
||||||
|
|
||||||
options = with lib; with types; {
|
options = with lib; with types; {
|
||||||
environment.cascade-source.enable = mkOption {
|
cascade.source.enable = mkOption {
|
||||||
default = true;
|
default = true;
|
||||||
type = bool;
|
type = bool;
|
||||||
description = ''
|
description = ''
|
||||||
Include cascade source code configured for nixos-rebuild.
|
Include cascade source code configured for nixos-rebuild.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
cascade.source.git-url = mkOption {
|
||||||
|
default = "https://gitlab.com/jamesandariese/cascade";
|
||||||
|
type = str;
|
||||||
|
description = ''
|
||||||
|
git URL where cascade sources can be found
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
cascade.source.set-nix-path = mkOption {
|
||||||
|
default = true;
|
||||||
|
type = bool;
|
||||||
|
description = ''
|
||||||
|
set cascade=/usr/src/cascade in NIX_PATH if cascade.source.enable is also true.
|
||||||
|
|
||||||
|
if this option or cascade.source.enable are false, this will not be done.
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = with lib; {
|
config = with lib; {
|
||||||
system.activationScripts.cascade-source = mkMerge [
|
system.activationScripts.cascade-source = mkMerge [
|
||||||
(mkIf config.environment.cascade-source.enable ''
|
(mkIf config.cascade.source.enable ''
|
||||||
mkdir -m 0755 -p /usr/src /etc/nixos
|
if [ ! -f /usr/src/cascade/.created-by-nixos ];then
|
||||||
[ -h /usr/src/cascade ] && rm /usr/src/cascade # do this first so the dir test that comes next won't read the symlink as a dir
|
mkdir -m 0755 -p /usr/src /etc/nixos
|
||||||
[ -d /usr/src/cascade ] && mv /usr/src/cascade /usr/src/cascade.before-nixos
|
[ -e /usr/src/cascade ] && mv /usr/src/cascade /usr/src/cascade.before-nixos
|
||||||
ln -sfn ${./..} /usr/src/cascade # but why isn't this atomic?
|
${pkgs.git}/bin/git clone ${config.cascade.source.git-url} /usr/src/cascade
|
||||||
ln -sf /usr/src/cascade/hosts/${config.networking.hostName}.nix /etc/nixos/configuration.nix
|
touch /usr/src/cascade/.created-by-nixos
|
||||||
|
fi
|
||||||
'')
|
'')
|
||||||
(mkIf (!config.environment.cascade-source.enable) ''
|
(mkIf (!config.cascade.source.enable) ''
|
||||||
# if we delete the symlink version of cascade, we delete a symlink in /etc/nixos as well
|
# only cleanup if we actually created /usr/src/cascade
|
||||||
[ -h /usr/src/cascade ] && rm /usr/src/cascade && \
|
if [ -f /usr/src/cascade/.created-by-nixos ];then
|
||||||
[ -h /etc/nixos/configuration.nix ] && rm /etc/nixos/configuration.nix
|
rm -rf /usr/src/cascade && \
|
||||||
|
[ -e /usr/src/cascade.before-nixos ] && mv /usr/src/cascade.before-nixos /usr/src/cascade
|
||||||
|
fi
|
||||||
'')
|
'')
|
||||||
];
|
];
|
||||||
nix.nixPath = [
|
nix.nixPath = mkIf (config.cascade.source.set-nix-path && config.cascade.source.enable) [ "cascade=/usr/src/cascade" ];
|
||||||
"nixos-config=/etc/nixos/configuration.nix"
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
63
overlays/cascade-installer.nix
Normal file
63
overlays/cascade-installer.nix
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
final: prev: {
|
||||||
|
cascade-installer = prev.writeShellApplication {
|
||||||
|
name="cascade-installer";
|
||||||
|
runtimeInputs = with final; [ bash git parted util-linux jq ];
|
||||||
|
text=''
|
||||||
|
usage() {
|
||||||
|
1>&2 echo "usage: cascade-installer HOSTNAME BLOCKDEVTONUKE PROFILE"
|
||||||
|
}
|
||||||
|
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ];then
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
HOSTNAME="$1"
|
||||||
|
BLOCKDEVTONUKE="$2"
|
||||||
|
PROFILE="$3"
|
||||||
|
|
||||||
|
if ! [ -d /usr/src/cascade/profiles/"$PROFILE" ];then
|
||||||
|
1>&2 echo "profile $PROFILE does not exist. possible options:"
|
||||||
|
(cd /usr/src/cascade/profiles/ && 1>&2 printf " %s\n" [a-zA-Z0-9]*)
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p /mnt
|
||||||
|
|
||||||
|
# if the block device has children...
|
||||||
|
if lsblk -J "$BLOCKDEVTONUKE" | jq -e '.blockdevices[]|.children' > /dev/null ; then
|
||||||
|
1>&2 echo "$BLOCKDEVTONUKE still has partitions. please clear the block device before installing"
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
|
|
||||||
|
parted "$BLOCKDEVTONUKE" -- mklabel gpt
|
||||||
|
parted "$BLOCKDEVTONUKE" -- mkpart primary 512MiB -2GiB
|
||||||
|
parted "$BLOCKDEVTONUKE" -- mkpart primary linux-swap -2GiB 100%
|
||||||
|
parted "$BLOCKDEVTONUKE" -- mkpart ESP fat32 1MiB 512MiB
|
||||||
|
parted "$BLOCKDEVTONUKE" -- set 3 esp on
|
||||||
|
parted "$BLOCKDEVTONUKE" -- name 1 nixos
|
||||||
|
parted "$BLOCKDEVTONUKE" -- name 2 nixos-swap
|
||||||
|
parted "$BLOCKDEVTONUKE" -- name 3 ESP
|
||||||
|
|
||||||
|
sync
|
||||||
|
sleep 3
|
||||||
|
|
||||||
|
BLK_NIXOS="$(lsblk -OJ "$BLOCKDEVTONUKE" | jq -r '.blockdevices[].children[]|select(.partlabel == "nixos")|.name')"
|
||||||
|
BLK_SWAP="$(lsblk -OJ "$BLOCKDEVTONUKE" | jq -r '.blockdevices[].children[]|select(.partlabel == "nixos-swap")|.name')"
|
||||||
|
BLK_ESP="$(lsblk -OJ "$BLOCKDEVTONUKE" | jq -r '.blockdevices[].children[]|select(.partlabel == "ESP")|.name')"
|
||||||
|
mkfs.xfs -L nixos "$BLK_NIXOS"
|
||||||
|
mkswap -L nixos-swap "$BLK_SWAP"
|
||||||
|
mkfs.fat -F 32 -n BOOT "$BLK_ESP"
|
||||||
|
|
||||||
|
mount "$BLK_NIXOS" /mnt
|
||||||
|
mkdir -p /mnt/boot /mnt/etc/nixos
|
||||||
|
sed -e '
|
||||||
|
s#[(] *toString ../profiles/.*[)]#(toString /usr/src/cascade/profiles/'"$PROFILE"')#
|
||||||
|
s#networking.hostName = "nixos";#networking.hostName = "'"$HOSTNAME"'";#
|
||||||
|
' < /usr/src/cascade/hosts/_basic.nix > /etc/nixos/configuration.nix
|
||||||
|
|
||||||
|
swapon "$BLK_SWAP"
|
||||||
|
nixos-install
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
{pkgs ? (import "${import ../../nixpkgs-path.nix}" {}), ...}:
|
#{pkgs ? (import "${import ../../nixpkgs-path.nix}" {}), ...}:
|
||||||
|
{pkgs, ...}:
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
(toString ../../common)
|
(toString ../../common)
|
||||||
|
@ -7,7 +8,7 @@
|
||||||
# used for deployment. This is done automatically with shell.nix.
|
# used for deployment. This is done automatically with shell.nix.
|
||||||
];
|
];
|
||||||
config = {
|
config = {
|
||||||
environment.systemPackages = with pkgs; [ bridge-utils git ];
|
environment.systemPackages = with pkgs; [ bridge-utils git cascade-installer ];
|
||||||
programs.neovim.enable = true;
|
programs.neovim.enable = true;
|
||||||
programs.neovim.vimAlias = true;
|
programs.neovim.vimAlias = true;
|
||||||
programs.neovim.viAlias = true;
|
programs.neovim.viAlias = true;
|
||||||
|
@ -28,6 +29,7 @@
|
||||||
|
|
||||||
|
|
||||||
nix.nixPath = with pkgs; [
|
nix.nixPath = with pkgs; [
|
||||||
|
"nixos-config=/etc/nixos/configuration.nix"
|
||||||
"nixpkgs=${ import ../../nixpkgs-path.nix }"
|
"nixpkgs=${ import ../../nixpkgs-path.nix }"
|
||||||
"home-manager=/usr/src/home-manager"
|
"home-manager=/usr/src/home-manager"
|
||||||
"morph-options=${morph.lib}/options.nix"
|
"morph-options=${morph.lib}/options.nix"
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
{
|
{
|
||||||
imports = [ (toString ../qemu-vm) ];
|
imports = [
|
||||||
|
(toString ../qemu-vm)
|
||||||
|
];
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
cascade.bridge-interface = mkForce null; # let it come up with its default interface with dhcp first
|
cascade.bridge-interface = mkForce null; # let it come up with its default interface with dhcp first
|
||||||
|
|
|
@ -34,11 +34,6 @@ mkvirt() {
|
||||||
1>&2 echo "there is already a file at ./hosts/$name"".nix. move it or remove it."
|
1>&2 echo "there is already a file at ./hosts/$name"".nix. move it or remove it."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# free-ips.txt contains fre IPs, one per line
|
|
||||||
# this is currently not being used in favor of DHCP towards the end
|
|
||||||
#IPALLOC="$(head -1 free-ips.txt)"
|
|
||||||
#sed -i -e '1d' free-ips.txt
|
|
||||||
|
|
||||||
[ -f "result/nixos.img" ] || (
|
[ -f "result/nixos.img" ] || (
|
||||||
1>&2 echo "you do not seem to have a result/nixos.img file. building one now."
|
1>&2 echo "you do not seem to have a result/nixos.img file. building one now."
|
||||||
|
|
Loading…
Reference in New Issue
Block a user