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]",
|
||||
"check from-nixos-with-sudo [x86_64-linux]",
|
||||
"package nixos-remote [x86_64-linux]",
|
||||
"check treefmt [x86_64-linux]",
|
||||
"package treefmt [x86_64-linux]",
|
||||
# github actions
|
||||
"deploy"
|
||||
]
|
||||
|
18
flake.lock
18
flake.lock
@ -113,7 +113,23 @@
|
||||
"disko": "disko",
|
||||
"flake-parts": "flake-parts",
|
||||
"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"; };
|
||||
# used for testing
|
||||
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
|
||||
./tests/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;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -98,7 +98,6 @@ while [[ $# -gt 0 ]]; do
|
||||
shift
|
||||
done
|
||||
|
||||
|
||||
# ssh wrapper
|
||||
timeout_ssh_() {
|
||||
timeout 10 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$ssh_connection" "$@"
|
||||
@ -134,20 +133,20 @@ if [[ -z ${ssh_connection:-} ]]; then
|
||||
fi
|
||||
|
||||
# parse flake nixos-install style syntax, get the system attr
|
||||
if [[ -n "${flake:-}" ]]; then
|
||||
if [[ -n ${flake:-} ]]; then
|
||||
if [[ $flake =~ ^(.*)\#([^\#\"]*)$ ]]; then
|
||||
flake="${BASH_REMATCH[1]}"
|
||||
flakeAttr="${BASH_REMATCH[2]}"
|
||||
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 "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
|
||||
fi
|
||||
disko_script=$(nix_build "${flake}#nixosConfigurations.${flakeAttr}.config.system.build.disko")
|
||||
nixos_system=$(nix_build "${flake}#nixosConfigurations.${flakeAttr}.config.system.build.toplevel")
|
||||
elif [[ -n "${disko_script:-}" ]] && [[ -n "${nixos_system:-}" ]]; then
|
||||
if [[ ! -e "${disko_script}" ]] || [[ ! -e "${nixos_system}" ]]; then
|
||||
elif [[ -n ${disko_script:-} ]] && [[ -n ${nixos_system:-} ]]; then
|
||||
if [[ ! -e ${disko_script} ]] || [[ ! -e ${nixos_system} ]]; then
|
||||
echo "${disko_script} and ${nixos_system} must be existing store-paths"
|
||||
exit 1
|
||||
fi
|
||||
@ -160,7 +159,8 @@ fi
|
||||
# TODO we probably need an architecture detection here
|
||||
# TODO if we have specified a user here but we are already booted into the
|
||||
# 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}
|
||||
has(){
|
||||
command -v tar >/dev/null && echo "y" || echo "n"
|
||||
@ -204,7 +204,7 @@ set -efu ${enable_debug}
|
||||
"${maybesudo}" mkdir -p /root/kexec
|
||||
SSH
|
||||
|
||||
if [[ -f "$kexec_url" ]]; then
|
||||
if [[ -f $kexec_url ]]; then
|
||||
ssh_ "${maybesudo} tar -C /root/kexec -xvzf-" <"$kexec_url"
|
||||
elif [[ ${has_curl-n} == "y" ]]; then
|
||||
ssh_ "curl --fail -Ss -L '${kexec_url}' | ${maybesudo} tar -C /root/kexec -xvzf-"
|
||||
@ -227,8 +227,7 @@ SSH
|
||||
# watiting for machine to become available again
|
||||
until ssh_ -o ConnectTimeout=10 -- exit 0; do sleep 5; done
|
||||
fi
|
||||
for path in "${!disk_encryption_keys[@]}"
|
||||
do
|
||||
for path in "${!disk_encryption_keys[@]}"; do
|
||||
echo "Uploading ${disk_encryption_keys[$path]} to $path"
|
||||
ssh_ "umask 077; cat > $path" <"${disk_encryption_keys[$path]}"
|
||||
done
|
||||
@ -242,7 +241,7 @@ fi
|
||||
|
||||
nix_copy --to "ssh://$ssh_connection?remote-store=local?root=/mnt" "$nixos_system"
|
||||
if [[ -n ${extra_files:-} ]]; then
|
||||
if [[ -d "$extra_files" ]]; then
|
||||
if [[ -d $extra_files ]]; then
|
||||
extra_files="$extra_files/"
|
||||
fi
|
||||
rsync -vrlF -e "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" "$extra_files" "${ssh_connection}:/mnt/"
|
||||
|
Loading…
Reference in New Issue
Block a user