flake: add helpers

This commit is contained in:
Aly Raffauf 2024-07-07 23:06:17 -04:00
parent 0840f43ffd
commit 97f265bd4d

148
flake.nix
View file

@ -33,44 +33,56 @@
]; ];
}; };
outputs = inputs @ {self, ...}: { outputs = inputs @ {self, ...}: let
formatter = inputs.nixpkgs.lib.genAttrs [ forDefaultSystems = inputs.nixpkgs.lib.genAttrs [
"aarch64-darwin"
"aarch64-linux" "aarch64-linux"
"x86_64-darwin"
"x86_64-linux" "x86_64-linux"
] (system: inputs.nixpkgs.legacyPackages.${system}.alejandra); "aarch64-darwin"
"x86_64-darwin"
];
packages = forLinuxSystems = inputs.nixpkgs.lib.genAttrs [
inputs.nixpkgs.lib.genAttrs [ "aarch64-linux"
"aarch64-linux" "x86_64-linux"
"x86_64-linux" ];
] (system: {
default = inputs.nixpkgs.legacyPackages."${system}".writeShellScriptBin "clean-install" ''
# Check if an argument is provided
if [ $# -eq 0 ]; then
echo "Error: Please provide a valid hostname as an argument."
exit 1
fi
HOST=$1 forAllHosts = inputs.nixpkgs.lib.genAttrs [
FLAKE=github:alyraffauf/nixcfg#$HOST "fallarbor"
"lavaridge"
"mandarin"
"mauville"
"petalburg"
"rustboro"
];
in {
formatter = forDefaultSystems (system: inputs.nixpkgs.legacyPackages.${system}.alejandra);
echo "Warning: Running this script will wipe the currently installed system." packages = forLinuxSystems (system: {
read -p "Do you want to continue? (y/n): " answer default = inputs.nixpkgs.legacyPackages."${system}".writeShellScriptBin "clean-install" ''
# Check if an argument is provided
if [ $# -eq 0 ]; then
echo "Error: Please provide a valid hostname as an argument."
exit 1
fi
if [ "$answer" != "y" ]; then HOST=$1
echo "Aborted." FLAKE=github:alyraffauf/nixcfg#$HOST
exit 0
fi
sudo nix --experimental-features "nix-command flakes" run \ echo "Warning: Running this script will wipe the currently installed system."
github:nix-community/disko -- --mode disko --flake $FLAKE read -p "Do you want to continue? (y/n): " answer
# Install NixOS with the updated flake input and root settings if [ "$answer" != "y" ]; then
sudo nixos-install --no-root-password --root /mnt --flake $FLAKE echo "Aborted."
''; exit 0
}); fi
sudo nix --experimental-features "nix-command flakes" run \
github:nix-community/disko -- --mode disko --flake $FLAKE
# Install NixOS with the updated flake input and root settings
sudo nixos-install --no-root-password --root /mnt --flake $FLAKE
'';
});
homeManagerModules = { homeManagerModules = {
default = import ./homeManagerModules inputs self; default = import ./homeManagerModules inputs self;
@ -85,50 +97,42 @@
users = import ./userModules inputs; users = import ./userModules inputs;
}; };
nixosConfigurations = nixosConfigurations = forAllHosts (
inputs.nixpkgs.lib.genAttrs [ host:
"fallarbor" inputs.nixpkgs.lib.nixosSystem {
"lavaridge" specialArgs = {inherit inputs self;};
"mandarin" modules = [
"mauville" ./hosts/${host}
"petalburg" inputs.agenix.nixosModules.default
"rustboro" inputs.disko.nixosModules.disko
] ( inputs.home-manager.nixosModules.home-manager
host: inputs.hyprland.nixosModules.default
inputs.nixpkgs.lib.nixosSystem { inputs.nixvim.nixosModules.nixvim
specialArgs = {inherit inputs self;}; inputs.nur.nixosModules.nur
modules = [ inputs.raffauflabs.nixosModules.raffauflabs
./hosts/${host} self.nixosModules.base
inputs.agenix.nixosModules.default self.nixosModules.nixos
inputs.disko.nixosModules.disko self.nixosModules.users
inputs.home-manager.nixosModules.home-manager
inputs.hyprland.nixosModules.default
inputs.nixvim.nixosModules.nixvim
inputs.nur.nixosModules.nur
inputs.raffauflabs.nixosModules.raffauflabs
self.nixosModules.base
self.nixosModules.nixos
self.nixosModules.users
{ {
home-manager = { home-manager = {
backupFileExtension = "backup"; backupFileExtension = "backup";
extraSpecialArgs = {inherit inputs self;}; extraSpecialArgs = {inherit inputs self;};
sharedModules = [ sharedModules = [
inputs.agenix.homeManagerModules.default inputs.agenix.homeManagerModules.default
inputs.hyprland.homeManagerModules.default inputs.hyprland.homeManagerModules.default
inputs.nixvim.homeManagerModules.nixvim inputs.nixvim.homeManagerModules.nixvim
inputs.nur.hmModules.nur inputs.nur.hmModules.nur
self.homeManagerModules.default self.homeManagerModules.default
]; ];
useGlobalPkgs = true; useGlobalPkgs = true;
useUserPackages = true; useUserPackages = true;
}; };
} }
]; ];
} }
); );
}; };
} }