mirror of
https://github.com/nix-community/nixos-anywhere.git
synced 2024-08-17 04:10:36 +03:00
treewide: add formatting via treefmt
This commit is contained in:
parent
75c182ae90
commit
e2d1a946b1
@ -7,6 +7,8 @@ status = [
|
|||||||
"package default [x86_64-linux]",
|
"package default [x86_64-linux]",
|
||||||
"check from-nixos-with-sudo [x86_64-linux]",
|
"check from-nixos-with-sudo [x86_64-linux]",
|
||||||
"package nixos-remote [x86_64-linux]",
|
"package nixos-remote [x86_64-linux]",
|
||||||
|
"check treefmt [x86_64-linux]",
|
||||||
|
"package treefmt [x86_64-linux]",
|
||||||
# github actions
|
# github actions
|
||||||
"deploy"
|
"deploy"
|
||||||
]
|
]
|
||||||
|
18
flake.lock
18
flake.lock
@ -113,7 +113,23 @@
|
|||||||
"disko": "disko",
|
"disko": "disko",
|
||||||
"flake-parts": "flake-parts",
|
"flake-parts": "flake-parts",
|
||||||
"nixos-images": "nixos-images",
|
"nixos-images": "nixos-images",
|
||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs",
|
||||||
|
"treefmt-nix": "treefmt-nix"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"treefmt-nix": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1672931382,
|
||||||
|
"narHash": "sha256-lgtc2Sct/xtvqkdzlJ4AL3Vesw0Wz/fxqNGOBFS7YXU=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "treefmt-nix",
|
||||||
|
"rev": "6717065d6a432bc3f5b827007ad959e6032d5856",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "treefmt-nix",
|
||||||
|
"type": "github"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
14
flake.nix
14
flake.nix
@ -7,6 +7,8 @@
|
|||||||
disko = { url = "github:nix-community/disko/master"; inputs.nixpkgs.follows = "nixpkgs"; };
|
disko = { url = "github:nix-community/disko/master"; inputs.nixpkgs.follows = "nixpkgs"; };
|
||||||
# used for testing
|
# used for testing
|
||||||
nixos-images.url = "github:nix-community/nixos-images";
|
nixos-images.url = "github:nix-community/nixos-images";
|
||||||
|
# used for development
|
||||||
|
treefmt-nix.url = "github:numtide/treefmt-nix";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -17,6 +19,18 @@
|
|||||||
./src/flake-module.nix
|
./src/flake-module.nix
|
||||||
./tests/flake-module.nix
|
./tests/flake-module.nix
|
||||||
./docs/flake-module.nix
|
./docs/flake-module.nix
|
||||||
|
inputs.treefmt-nix.flakeModule
|
||||||
];
|
];
|
||||||
|
|
||||||
|
perSystem = { config, ... }: {
|
||||||
|
treefmt = {
|
||||||
|
projectRootFile = "flake.nix";
|
||||||
|
programs.nixpkgs-fmt.enable = true;
|
||||||
|
programs.shellcheck.enable = true;
|
||||||
|
programs.shfmt.enable = true;
|
||||||
|
settings.formatter.shellcheck.options = [ "-s" "bash" ];
|
||||||
|
};
|
||||||
|
formatter = config.treefmt.build.wrapper;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -42,63 +42,62 @@ declare -A disk_encryption_keys
|
|||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-f | --flake)
|
-f | --flake)
|
||||||
flake=$2
|
flake=$2
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-L | --print-build-logs)
|
-L | --print-build-logs)
|
||||||
print_build_logs=y
|
print_build_logs=y
|
||||||
;;
|
;;
|
||||||
-s | --store-paths)
|
-s | --store-paths)
|
||||||
disko_script=$(readlink -f "$2")
|
disko_script=$(readlink -f "$2")
|
||||||
nixos_system=$(readlink -f "$3")
|
nixos_system=$(readlink -f "$3")
|
||||||
shift
|
shift
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--help)
|
--help)
|
||||||
|
showUsage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
--kexec)
|
||||||
|
kexec_url=$2
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--no-ssh-copy-id)
|
||||||
|
no_ssh_copy=y
|
||||||
|
;;
|
||||||
|
--debug)
|
||||||
|
enable_debug="-x"
|
||||||
|
print_build_logs=y
|
||||||
|
set -x
|
||||||
|
;;
|
||||||
|
--extra-files)
|
||||||
|
extra_files=$2
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--disk-encryption-keys)
|
||||||
|
disk_encryption_keys["$2"]="$3"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--stop-after-disko)
|
||||||
|
stop_after_disko=y
|
||||||
|
;;
|
||||||
|
--no-reboot)
|
||||||
|
maybereboot=""
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
if [[ -z ${ssh_connection:-} ]]; then
|
||||||
|
ssh_connection="$1"
|
||||||
|
else
|
||||||
showUsage
|
showUsage
|
||||||
exit 0
|
exit 1
|
||||||
;;
|
fi
|
||||||
--kexec)
|
;;
|
||||||
kexec_url=$2
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--no-ssh-copy-id)
|
|
||||||
no_ssh_copy=y
|
|
||||||
;;
|
|
||||||
--debug)
|
|
||||||
enable_debug="-x"
|
|
||||||
print_build_logs=y
|
|
||||||
set -x
|
|
||||||
;;
|
|
||||||
--extra-files)
|
|
||||||
extra_files=$2
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--disk-encryption-keys)
|
|
||||||
disk_encryption_keys["$2"]="$3"
|
|
||||||
shift
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--stop-after-disko)
|
|
||||||
stop_after_disko=y
|
|
||||||
;;
|
|
||||||
--no-reboot)
|
|
||||||
maybereboot=""
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
if [[ -z ${ssh_connection:-} ]]; then
|
|
||||||
ssh_connection="$1"
|
|
||||||
else
|
|
||||||
showUsage
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
# ssh wrapper
|
# ssh wrapper
|
||||||
timeout_ssh_() {
|
timeout_ssh_() {
|
||||||
timeout 10 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$ssh_connection" "$@"
|
timeout 10 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$ssh_connection" "$@"
|
||||||
@ -134,20 +133,20 @@ if [[ -z ${ssh_connection:-} ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# parse flake nixos-install style syntax, get the system attr
|
# parse flake nixos-install style syntax, get the system attr
|
||||||
if [[ -n "${flake:-}" ]]; then
|
if [[ -n ${flake:-} ]]; then
|
||||||
if [[ $flake =~ ^(.*)\#([^\#\"]*)$ ]]; then
|
if [[ $flake =~ ^(.*)\#([^\#\"]*)$ ]]; then
|
||||||
flake="${BASH_REMATCH[1]}"
|
flake="${BASH_REMATCH[1]}"
|
||||||
flakeAttr="${BASH_REMATCH[2]}"
|
flakeAttr="${BASH_REMATCH[2]}"
|
||||||
fi
|
fi
|
||||||
if [[ -z "${flakeAttr:-}" ]]; then
|
if [[ -z ${flakeAttr:-} ]]; then
|
||||||
echo "Please specify the name of the NixOS configuration to be installed, as a URI fragment in the flake-uri."
|
echo "Please specify the name of the NixOS configuration to be installed, as a URI fragment in the flake-uri."
|
||||||
echo "For example, to use the output nixosConfigurations.foo from the flake.nix, append \"#foo\" to the flake-uri."
|
echo 'For example, to use the output nixosConfigurations.foo from the flake.nix, append "#foo" to the flake-uri.'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
disko_script=$(nix_build "${flake}#nixosConfigurations.${flakeAttr}.config.system.build.disko")
|
disko_script=$(nix_build "${flake}#nixosConfigurations.${flakeAttr}.config.system.build.disko")
|
||||||
nixos_system=$(nix_build "${flake}#nixosConfigurations.${flakeAttr}.config.system.build.toplevel")
|
nixos_system=$(nix_build "${flake}#nixosConfigurations.${flakeAttr}.config.system.build.toplevel")
|
||||||
elif [[ -n "${disko_script:-}" ]] && [[ -n "${nixos_system:-}" ]]; then
|
elif [[ -n ${disko_script:-} ]] && [[ -n ${nixos_system:-} ]]; then
|
||||||
if [[ ! -e "${disko_script}" ]] || [[ ! -e "${nixos_system}" ]]; then
|
if [[ ! -e ${disko_script} ]] || [[ ! -e ${nixos_system} ]]; then
|
||||||
echo "${disko_script} and ${nixos_system} must be existing store-paths"
|
echo "${disko_script} and ${nixos_system} must be existing store-paths"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -160,7 +159,8 @@ fi
|
|||||||
# TODO we probably need an architecture detection here
|
# TODO we probably need an architecture detection here
|
||||||
# TODO if we have specified a user here but we are already booted into the
|
# TODO if we have specified a user here but we are already booted into the
|
||||||
# installer, than the user might not work anymore
|
# installer, than the user might not work anymore
|
||||||
until facts=$(ssh_ -o ConnectTimeout=10 -- <<SSH
|
until facts=$(
|
||||||
|
ssh_ -o ConnectTimeout=10 -- <<SSH
|
||||||
set -efu ${enable_debug}
|
set -efu ${enable_debug}
|
||||||
has(){
|
has(){
|
||||||
command -v tar >/dev/null && echo "y" || echo "n"
|
command -v tar >/dev/null && echo "y" || echo "n"
|
||||||
@ -198,14 +198,14 @@ if [[ ${is_kexec-n} != "y" ]] && [[ ${no_ssh_copy-n} != "y" ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ${is_kexec-n} == "n" ]]; then
|
if [[ ${is_kexec-n} == "n" ]]; then
|
||||||
ssh_ << SSH
|
ssh_ <<SSH
|
||||||
set -efu ${enable_debug}
|
set -efu ${enable_debug}
|
||||||
"${maybesudo}" rm -rf /root/kexec
|
"${maybesudo}" rm -rf /root/kexec
|
||||||
"${maybesudo}" mkdir -p /root/kexec
|
"${maybesudo}" mkdir -p /root/kexec
|
||||||
SSH
|
SSH
|
||||||
|
|
||||||
if [[ -f "$kexec_url" ]]; then
|
if [[ -f $kexec_url ]]; then
|
||||||
ssh_ "${maybesudo} tar -C /root/kexec -xvzf-" < "$kexec_url"
|
ssh_ "${maybesudo} tar -C /root/kexec -xvzf-" <"$kexec_url"
|
||||||
elif [[ ${has_curl-n} == "y" ]]; then
|
elif [[ ${has_curl-n} == "y" ]]; then
|
||||||
ssh_ "curl --fail -Ss -L '${kexec_url}' | ${maybesudo} tar -C /root/kexec -xvzf-"
|
ssh_ "curl --fail -Ss -L '${kexec_url}' | ${maybesudo} tar -C /root/kexec -xvzf-"
|
||||||
elif [[ ${has_wget-n} == "y" ]]; then
|
elif [[ ${has_wget-n} == "y" ]]; then
|
||||||
@ -214,7 +214,7 @@ SSH
|
|||||||
curl --fail -Ss -L "${kexec_url}" | ssh_ "${maybesudo} tar -C /root/kexec -xvzf-"
|
curl --fail -Ss -L "${kexec_url}" | ssh_ "${maybesudo} tar -C /root/kexec -xvzf-"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ssh_ << SSH
|
ssh_ <<SSH
|
||||||
TMPDIR=/root/kexec setsid ${maybesudo} /root/kexec/kexec/run
|
TMPDIR=/root/kexec setsid ${maybesudo} /root/kexec/kexec/run
|
||||||
SSH
|
SSH
|
||||||
|
|
||||||
@ -227,10 +227,9 @@ SSH
|
|||||||
# watiting for machine to become available again
|
# watiting for machine to become available again
|
||||||
until ssh_ -o ConnectTimeout=10 -- exit 0; do sleep 5; done
|
until ssh_ -o ConnectTimeout=10 -- exit 0; do sleep 5; done
|
||||||
fi
|
fi
|
||||||
for path in "${!disk_encryption_keys[@]}"
|
for path in "${!disk_encryption_keys[@]}"; do
|
||||||
do
|
|
||||||
echo "Uploading ${disk_encryption_keys[$path]} to $path"
|
echo "Uploading ${disk_encryption_keys[$path]} to $path"
|
||||||
ssh_ "umask 077; cat > $path" < "${disk_encryption_keys[$path]}"
|
ssh_ "umask 077; cat > $path" <"${disk_encryption_keys[$path]}"
|
||||||
done
|
done
|
||||||
|
|
||||||
nix_copy --to "ssh://$ssh_connection" "$disko_script"
|
nix_copy --to "ssh://$ssh_connection" "$disko_script"
|
||||||
@ -242,7 +241,7 @@ fi
|
|||||||
|
|
||||||
nix_copy --to "ssh://$ssh_connection?remote-store=local?root=/mnt" "$nixos_system"
|
nix_copy --to "ssh://$ssh_connection?remote-store=local?root=/mnt" "$nixos_system"
|
||||||
if [[ -n ${extra_files:-} ]]; then
|
if [[ -n ${extra_files:-} ]]; then
|
||||||
if [[ -d "$extra_files" ]]; then
|
if [[ -d $extra_files ]]; then
|
||||||
extra_files="$extra_files/"
|
extra_files="$extra_files/"
|
||||||
fi
|
fi
|
||||||
rsync -vrlF -e "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" "$extra_files" "${ssh_connection}:/mnt/"
|
rsync -vrlF -e "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" "$extra_files" "${ssh_connection}:/mnt/"
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
test:
|
test:
|
||||||
{ pkgs ? import <nixpkgs> {}, ... } @ args:
|
{ pkgs ? import <nixpkgs> { }, ... } @ args:
|
||||||
let
|
let
|
||||||
inherit (pkgs) lib;
|
inherit (pkgs) lib;
|
||||||
nixos-lib = import (pkgs.path + "/nixos/lib") {};
|
nixos-lib = import (pkgs.path + "/nixos/lib") { };
|
||||||
in
|
in
|
||||||
(nixos-lib.runTest {
|
(nixos-lib.runTest {
|
||||||
hostPkgs = pkgs;
|
hostPkgs = pkgs;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{modulesPath, self, ...}: {
|
{ modulesPath, self, ... }: {
|
||||||
imports = [
|
imports = [
|
||||||
(modulesPath + "/testing/test-instrumentation.nix")
|
(modulesPath + "/testing/test-instrumentation.nix")
|
||||||
(modulesPath + "/profiles/qemu-guest.nix")
|
(modulesPath + "/profiles/qemu-guest.nix")
|
||||||
@ -9,7 +9,7 @@
|
|||||||
hardware.enableAllFirmware = false;
|
hardware.enableAllFirmware = false;
|
||||||
networking.hostId = "8425e349"; # from profiles/base.nix, needed for zfs
|
networking.hostId = "8425e349"; # from profiles/base.nix, needed for zfs
|
||||||
boot.zfs.devNodes = "/dev/disk/by-uuid"; # needed because /dev/disk/by-id is empty in qemu-vms
|
boot.zfs.devNodes = "/dev/disk/by-uuid"; # needed because /dev/disk/by-id is empty in qemu-vms
|
||||||
boot.loader.grub.devices = ["/dev/vda"];
|
boot.loader.grub.devices = [ "/dev/vda" ];
|
||||||
disko.devices = {
|
disko.devices = {
|
||||||
disk = {
|
disk = {
|
||||||
vda = {
|
vda = {
|
||||||
@ -25,7 +25,7 @@
|
|||||||
start = "0";
|
start = "0";
|
||||||
end = "1M";
|
end = "1M";
|
||||||
part-type = "primary";
|
part-type = "primary";
|
||||||
flags = ["bios_grub"];
|
flags = [ "bios_grub" ];
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
type = "partition";
|
type = "partition";
|
||||||
|
Loading…
Reference in New Issue
Block a user