From 97f265bd4d72f15b6ed02d4f38feed6d48a1203b Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Sun, 7 Jul 2024 23:06:17 -0400 Subject: [PATCH] flake: add helpers --- flake.nix | 148 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 76 insertions(+), 72 deletions(-) diff --git a/flake.nix b/flake.nix index c5036140..645d5e91 100644 --- a/flake.nix +++ b/flake.nix @@ -33,44 +33,56 @@ ]; }; - outputs = inputs @ {self, ...}: { - formatter = inputs.nixpkgs.lib.genAttrs [ - "aarch64-darwin" + outputs = inputs @ {self, ...}: let + forDefaultSystems = inputs.nixpkgs.lib.genAttrs [ "aarch64-linux" - "x86_64-darwin" "x86_64-linux" - ] (system: inputs.nixpkgs.legacyPackages.${system}.alejandra); + "aarch64-darwin" + "x86_64-darwin" + ]; - packages = - inputs.nixpkgs.lib.genAttrs [ - "aarch64-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 + forLinuxSystems = inputs.nixpkgs.lib.genAttrs [ + "aarch64-linux" + "x86_64-linux" + ]; - HOST=$1 - FLAKE=github:alyraffauf/nixcfg#$HOST + forAllHosts = inputs.nixpkgs.lib.genAttrs [ + "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." - read -p "Do you want to continue? (y/n): " answer + packages = forLinuxSystems (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 - if [ "$answer" != "y" ]; then - echo "Aborted." - exit 0 - fi + HOST=$1 + FLAKE=github:alyraffauf/nixcfg#$HOST - sudo nix --experimental-features "nix-command flakes" run \ - github:nix-community/disko -- --mode disko --flake $FLAKE + echo "Warning: Running this script will wipe the currently installed system." + read -p "Do you want to continue? (y/n): " answer - # Install NixOS with the updated flake input and root settings - sudo nixos-install --no-root-password --root /mnt --flake $FLAKE - ''; - }); + if [ "$answer" != "y" ]; then + 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 = { default = import ./homeManagerModules inputs self; @@ -85,50 +97,42 @@ users = import ./userModules inputs; }; - nixosConfigurations = - inputs.nixpkgs.lib.genAttrs [ - "fallarbor" - "lavaridge" - "mandarin" - "mauville" - "petalburg" - "rustboro" - ] ( - host: - inputs.nixpkgs.lib.nixosSystem { - specialArgs = {inherit inputs self;}; - modules = [ - ./hosts/${host} - inputs.agenix.nixosModules.default - inputs.disko.nixosModules.disko - 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 + nixosConfigurations = forAllHosts ( + host: + inputs.nixpkgs.lib.nixosSystem { + specialArgs = {inherit inputs self;}; + modules = [ + ./hosts/${host} + inputs.agenix.nixosModules.default + inputs.disko.nixosModules.disko + 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 = { - backupFileExtension = "backup"; - extraSpecialArgs = {inherit inputs self;}; + { + home-manager = { + backupFileExtension = "backup"; + extraSpecialArgs = {inherit inputs self;}; - sharedModules = [ - inputs.agenix.homeManagerModules.default - inputs.hyprland.homeManagerModules.default - inputs.nixvim.homeManagerModules.nixvim - inputs.nur.hmModules.nur - self.homeManagerModules.default - ]; + sharedModules = [ + inputs.agenix.homeManagerModules.default + inputs.hyprland.homeManagerModules.default + inputs.nixvim.homeManagerModules.nixvim + inputs.nur.hmModules.nur + self.homeManagerModules.default + ]; - useGlobalPkgs = true; - useUserPackages = true; - }; - } - ]; - } - ); + useGlobalPkgs = true; + useUserPackages = true; + }; + } + ]; + } + ); }; }