From 200063fcb196f2875bf05fe43aadb12caa1133a8 Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Thu, 29 Aug 2024 08:25:41 +0700 Subject: [PATCH] introduce treefmt-nix --- flake.lock | 23 +- flake.nix | 563 +++++++++++++++++++++++++--------------------- nix/formatter.nix | 16 ++ treefmt.toml | 48 ---- 4 files changed, 340 insertions(+), 310 deletions(-) create mode 100644 nix/formatter.nix delete mode 100644 treefmt.toml diff --git a/flake.lock b/flake.lock index 273b75f..7088402 100644 --- a/flake.lock +++ b/flake.lock @@ -843,7 +843,8 @@ "retiolum": "retiolum", "srvos": "srvos", "stylix": "stylix", - "taskshell": "taskshell" + "taskshell": "taskshell", + "treefmt-nix": "treefmt-nix_3" } }, "sops-nix": { @@ -1029,6 +1030,26 @@ "repo": "treefmt-nix", "type": "github" } + }, + "treefmt-nix_3": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1724833132, + "narHash": "sha256-F4djBvyNRAXGusJiNYInqR6zIMI3rvlp6WiKwsRISos=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "3ffd842a5f50f435d3e603312eefa4790db46af5", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index ced671b..2df11be 100644 --- a/flake.nix +++ b/flake.nix @@ -58,6 +58,11 @@ srvos.url = "github:nix-community/srvos"; + treefmt-nix = { + url = "github:numtide/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + landingpage = { #url = "git+file:///home/palo/dev/landingpage"; url = "github:mrVanDalo/landingpage"; @@ -91,28 +96,30 @@ }; outputs = - inputs@{ self - , clan-core - , clan-fact-generators - , flake-parts - , home-manager - , home-manager-utils - , kmonad - , landingpage - , nixos-anywhere - , nixos-hardware - , nixpkgs - , nixpkgs-legacy_2211 - , nixpkgs-legacy_2311 - , nixpkgs-legacy_2405 - , nixpkgs-unstable-small - , permown - , polygon-art - , private_assets - , retiolum - , srvos - , stylix - , taskshell + inputs@{ + self, + clan-core, + clan-fact-generators, + flake-parts, + home-manager, + home-manager-utils, + kmonad, + landingpage, + nixos-anywhere, + nixos-hardware, + nixpkgs, + nixpkgs-legacy_2211, + nixpkgs-legacy_2311, + nixpkgs-legacy_2405, + nixpkgs-unstable-small, + permown, + polygon-art, + private_assets, + retiolum, + srvos, + stylix, + taskshell, + treefmt-nix, }: let @@ -165,7 +172,10 @@ inherit inputs; assets = ./assets; factsGenerator = clan-fact-generators.lib { inherit pkgs; }; - clanLib = import ./lib/clanlib.nix { inherit (pkgs) lib; machineDir = ./machines; }; + clanLib = import ./lib/clanlib.nix { + inherit (pkgs) lib; + machineDir = ./machines; + }; zerotierDeviceName = "ztbn67ogn2"; components = ./components; features = ./features; @@ -173,57 +183,63 @@ }; clanSetup = - { name - , host - , modules - }: { + { + name, + host, + modules, + }: + { clan.core.networking.targetHost = lib.mkDefault "root@${host}"; nixpkgs.pkgs = meta.pkgs; nixpkgs.hostPlatform = meta.system; clan.core.facts.secretStore = "password-store"; - imports = modules ++ defaultModules ++ [ - ./machines/${name}/configuration.nix + imports = + modules + ++ defaultModules + ++ [ + ./machines/${name}/configuration.nix + ]; + }; + + zerotierControllerModule = { + clan.core.networking.zerotier.controller = { + enable = true; + public = false; + }; + }; + + zerotierModules = + { pkgs, ... }: + { + imports = [ + + # this magically adds all my machines in the zero tier network + # and makes the controller accept them. + # will automatic look into `/machines//facts/zerotier-ip + inputs.clan-core.clanModules.zerotier-static-peers + + # Statically configure the host names of machines based on their respective zerotier-ip. + inputs.clan-core.clanModules.static-hosts + + # generate ssh host keys with facts + inputs.clan-core.clanModules.sshd + + # manual configs + { + clan.static-hosts.topLevelDomain = "bear"; + components.network.zerotier.enable = true; + environment.systemPackages = [ + clan-core.packages.${pkgs.system}.clan-cli + (pkgs.writers.writeBashBin "zerotier-script-nodeid" '' + sudo ${pkgs.zerotierone}/bin/zerotier-cli info | cut -d " " -f 3 + '') + ]; + } ]; }; - zerotierControllerModule = - { - clan.core.networking.zerotier.controller = { - enable = true; - public = false; - }; - }; - - zerotierModules = { pkgs, ... }: { - imports = [ - - # this magically adds all my machines in the zero tier network - # and makes the controller accept them. - # will automatic look into `/machines//facts/zerotier-ip - inputs.clan-core.clanModules.zerotier-static-peers - - # Statically configure the host names of machines based on their respective zerotier-ip. - inputs.clan-core.clanModules.static-hosts - - # generate ssh host keys with facts - inputs.clan-core.clanModules.sshd - - # manual configs - { - clan.static-hosts.topLevelDomain = "bear"; - components.network.zerotier.enable = true; - environment.systemPackages = [ - clan-core.packages.${pkgs.system}.clan-cli - (pkgs.writers.writeBashBin "zerotier-script-nodeid" '' - sudo ${pkgs.zerotierone}/bin/zerotier-cli info | cut -d " " -f 3 - '') - ]; - } - ]; - }; - defaultModules = [ # make flake inputs accessiable in NixOS { @@ -231,15 +247,18 @@ _module.args.inputs = self.inputs; } # ssh keys - ({ config, ... }: { - users.users.root.openssh.authorizedKeys.keyFiles = [ - # master key - ./assets/mrvandalo_rsa.pub - # backup key - "${config.clan.core.clanDir}/machines/chungus/facts/ssh.syncoid.id_ed25519.pub" - "${config.clan.core.clanDir}/machines/chungus/facts/ssh.rbackup.id_ed25519.pub" - ]; - }) + ( + { config, ... }: + { + users.users.root.openssh.authorizedKeys.keyFiles = [ + # master key + ./assets/mrvandalo_rsa.pub + # backup key + "${config.clan.core.clanDir}/machines/chungus/facts/ssh.syncoid.id_ed25519.pub" + "${config.clan.core.clanDir}/machines/chungus/facts/ssh.rbackup.id_ed25519.pub" + ]; + } + ) { # disable emergency mode everywhere, although it might be needed on laptops boot.initrd.systemd.emergencyAccess = false; @@ -250,11 +269,20 @@ systemd.enableEmergencyMode = false; } # configure nix - ({ pkgs, lib, clanLib, ... }: + ( + { + pkgs, + lib, + clanLib, + ... + }: { nix.settings.substituters = [ "http://cache.orbi.wg0" ]; nix.settings.trusted-public-keys = [ (clanLib.readFact "nix-serve.pub" "orbi") ]; - nix.settings.experimental-features = [ "nix-command" "flakes" ]; + nix.settings.experimental-features = [ + "nix-command" + "flakes" + ]; nix.settings.max-jobs = 1; # no channesl needed this way nix.nixPath = [ "nixpkgs=${pkgs.path}" ]; @@ -282,7 +310,8 @@ boot.loader.systemd-boot.configurationLimit = lib.mkDefault 10; boot.loader.generic-extlinux-compatible.configurationLimit = lib.mkDefault 10; boot.loader.grub.configurationLimit = lib.mkDefault 10; - }) + } + ) # My Structure ./components ./features @@ -293,210 +322,222 @@ permown.nixosModules.permown kmonad.nixosModules.default # some default things I always want - ({ pkgs, ... }: { - boot.tmp.useTmpfs = lib.mkDefault true; - environment.systemPackages = [ - pkgs.nixpkgs-fmt - ]; - }) + ( + { pkgs, ... }: + { + boot.tmp.useTmpfs = lib.mkDefault true; + environment.systemPackages = [ + pkgs.nixpkgs-fmt + ]; + } + ) ]; - stylixModules = { pkgs, config, ... }: { - imports = [ stylix.nixosModules.stylix ]; - stylix.enable = true; - stylix.base16Scheme = "${pkgs.base16-schemes}/share/themes/gruvbox-light-medium.yaml"; - stylix.image = ./assets/wallpaper.png; - stylix.fonts = { - serif = { - package = pkgs.nerdfonts.override { fonts = [ "Ubuntu" ]; }; - name = "Ubuntu"; + stylixModules = + { pkgs, config, ... }: + { + imports = [ stylix.nixosModules.stylix ]; + stylix.enable = true; + stylix.base16Scheme = "${pkgs.base16-schemes}/share/themes/gruvbox-light-medium.yaml"; + stylix.image = ./assets/wallpaper.png; + stylix.fonts = { + serif = { + package = pkgs.nerdfonts.override { fonts = [ "Ubuntu" ]; }; + name = "Ubuntu"; + }; + sansSerif = { + package = pkgs.nerdfonts.override { fonts = [ "Ubuntu" ]; }; + name = "Ubuntu"; + }; + monospace = { + package = pkgs.nerdfonts.override { fonts = [ "JetBrainsMono" ]; }; + name = "JetBrains Mono"; + }; + emoji = { + package = pkgs.noto-fonts-emoji; + name = "Noto Color Emoji"; + }; + sizes.popups = 15; }; - sansSerif = { - package = pkgs.nerdfonts.override { fonts = [ "Ubuntu" ]; }; - name = "Ubuntu"; - }; - monospace = { - package = pkgs.nerdfonts.override { fonts = [ "JetBrainsMono" ]; }; - name = "JetBrains Mono"; - }; - emoji = { - package = pkgs.noto-fonts-emoji; - name = "Noto Color Emoji"; - }; - sizes.popups = 15; }; - }; - homeManagerModules = { pkgs, config, ... }: { - imports = [ - home-manager.nixosModules.home-manager - ]; - home-manager.extraSpecialArgs = { - #inherit private_assets; - assets = ./assets; + homeManagerModules = + { pkgs, config, ... }: + { + imports = [ + home-manager.nixosModules.home-manager + ]; + home-manager.extraSpecialArgs = { + #inherit private_assets; + assets = ./assets; + }; + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.backupFileExtension = "backup"; + home-manager.sharedModules = [ + home-manager-utils.hmModule + ]; }; - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - home-manager.backupFileExtension = "backup"; - home-manager.sharedModules = [ - home-manager-utils.hmModule - ]; - }; in - flake-parts.lib.mkFlake { inherit inputs; } ({ self, pkgs, ... }: { - # We define our own systems below. you can still use this to add system specific outputs to your flake. - # See: https://flake.parts/getting-started - systems = [ "x86_64-linux" ]; + flake-parts.lib.mkFlake { inherit inputs; } ( + { self, pkgs, ... }: + { + # We define our own systems below. you can still use this to add system specific outputs to your flake. + # See: https://flake.parts/getting-started + systems = [ "x86_64-linux" ]; - # import clan-core modules - imports = [ - clan-core.flakeModules.default - ]; + # import clan-core modules + imports = [ + clan-core.flakeModules.default + ./nix/formatter.nix + ]; - perSystem = { pkgs, ... }: { - packages.pkl = pkgs.callPackage ./pkgs/pkl { }; - }; - - # Define your clan - clan = { - # Clan wide settings. - meta.name = "gummybears"; # Ensure to choose a unique name. - specialArgs = meta.specialArgs; - - machines = { - - cream = clanSetup { - name = "cream"; - host = "cream.bear"; - modules = [ - zerotierModules - nixos-hardware.nixosModules.framework-12th-gen-intel - retiolum.nixosModules.retiolum - private_assets.nixosModules.cream - private_assets.nixosModules.yubikey - homeManagerModules - stylixModules - { home-manager.users.mainUser.gui.enable = true; } - { - home-manager.users.mainUser = import ./homes/palo; - home-manager.users.root = import ./homes/root; - } - { - clan.core.machineDescription = "Laptop"; - } - ]; + perSystem = + { pkgs, ... }: + { + packages.pkl = pkgs.callPackage ./pkgs/pkl { }; }; - cherry = clanSetup { - name = "cherry"; - host = "cherry.bear"; - modules = [ - zerotierModules - nixos-hardware.nixosModules.framework-13th-gen-intel - retiolum.nixosModules.retiolum - private_assets.nixosModules.yubikey - private_assets.nixosModules.cherry - homeManagerModules - stylixModules - { home-manager.users.mainUser.gui.enable = true; } - { - home-manager.users.mainUser = import ./homes/palo; - home-manager.users.root = import ./homes/root; - } - { - clan.core.machineDescription = "Laptop"; - } - ]; - }; + # Define your clan + clan = { + # Clan wide settings. + meta.name = "gummybears"; # Ensure to choose a unique name. + specialArgs = meta.specialArgs; - chungus = clanSetup { - name = "chungus"; - host = "chungus.bear"; - modules = [ - zerotierModules - zerotierControllerModule - homeManagerModules - stylixModules - retiolum.nixosModules.retiolum - private_assets.nixosModules.chungus - { - home-manager.users.mainUser = import ./homes/palo; - home-manager.users.root = import ./homes/root; - } - { - clan.core.machineDescription = "Home Server"; - } - ]; - }; + machines = { - orbi = clanSetup { - name = "orbi"; - host = "orbi.bear"; - #host = "95.216.66.212"; - modules = [ - homeManagerModules - stylixModules - zerotierModules - srvos.nixosModules.hardware-hetzner-online-intel - #srvos.nixosModules.server - #srvos.nixosModules.mixins-terminfo - { - home-manager.users.mainUser = import ./homes/palo; - home-manager.users.root = import ./homes/root; - } - { - clan.core.machineDescription = "Internet Server"; - } - ]; - }; + cream = clanSetup { + name = "cream"; + host = "cream.bear"; + modules = [ + zerotierModules + nixos-hardware.nixosModules.framework-12th-gen-intel + retiolum.nixosModules.retiolum + private_assets.nixosModules.cream + private_assets.nixosModules.yubikey + homeManagerModules + stylixModules + { home-manager.users.mainUser.gui.enable = true; } + { + home-manager.users.mainUser = import ./homes/palo; + home-manager.users.root = import ./homes/root; + } + { + clan.core.machineDescription = "Laptop"; + } + ]; + }; - probe = clanSetup { - name = "probe"; - #host = "167.235.205.150"; - host = "95.217.18.54"; - modules = [ - homeManagerModules - stylixModules - srvos.nixosModules.hardware-hetzner-cloud - srvos.nixosModules.server - srvos.nixosModules.mixins-terminfo - #inputs.clan-core.clanModules.sshd - { - home-manager.users.mainUser = import ./homes/palo; - home-manager.users.root = import ./homes/root; - } - { - clan.core.machineDescription = "Dummy Internet Server"; - } - ]; - }; + cherry = clanSetup { + name = "cherry"; + host = "cherry.bear"; + modules = [ + zerotierModules + nixos-hardware.nixosModules.framework-13th-gen-intel + retiolum.nixosModules.retiolum + private_assets.nixosModules.yubikey + private_assets.nixosModules.cherry + homeManagerModules + stylixModules + { home-manager.users.mainUser.gui.enable = true; } + { + home-manager.users.mainUser = import ./homes/palo; + home-manager.users.root = import ./homes/root; + } + { + clan.core.machineDescription = "Laptop"; + } + ]; + }; + + chungus = clanSetup { + name = "chungus"; + host = "chungus.bear"; + modules = [ + zerotierModules + zerotierControllerModule + homeManagerModules + stylixModules + retiolum.nixosModules.retiolum + private_assets.nixosModules.chungus + { + home-manager.users.mainUser = import ./homes/palo; + home-manager.users.root = import ./homes/root; + } + { + clan.core.machineDescription = "Home Server"; + } + ]; + }; + + orbi = clanSetup { + name = "orbi"; + host = "orbi.bear"; + #host = "95.216.66.212"; + modules = [ + homeManagerModules + stylixModules + zerotierModules + srvos.nixosModules.hardware-hetzner-online-intel + #srvos.nixosModules.server + #srvos.nixosModules.mixins-terminfo + { + home-manager.users.mainUser = import ./homes/palo; + home-manager.users.root = import ./homes/root; + } + { + clan.core.machineDescription = "Internet Server"; + } + ]; + }; + + probe = clanSetup { + name = "probe"; + #host = "167.235.205.150"; + host = "95.217.18.54"; + modules = [ + homeManagerModules + stylixModules + srvos.nixosModules.hardware-hetzner-cloud + srvos.nixosModules.server + srvos.nixosModules.mixins-terminfo + #inputs.clan-core.clanModules.sshd + { + home-manager.users.mainUser = import ./homes/palo; + home-manager.users.root = import ./homes/root; + } + { + clan.core.machineDescription = "Dummy Internet Server"; + } + ]; + }; + + usbstick = clanSetup { + name = "usbstick"; + #host = "usbstick.bear"; + host = "10.100.0.100"; + modules = [ + homeManagerModules + stylixModules + zerotierModules + { home-manager.users.mainUser.gui.enable = true; } + { + home-manager.users.mainUser = import ./homes/palo; + home-manager.users.root = import ./homes/root; + } + { + clan.core.machineDescription = "USB-Stick for Backup"; + } + ]; + }; - usbstick = clanSetup { - name = "usbstick"; - #host = "usbstick.bear"; - host = "10.100.0.100"; - modules = [ - homeManagerModules - stylixModules - zerotierModules - { home-manager.users.mainUser.gui.enable = true; } - { - home-manager.users.mainUser = import ./homes/palo; - home-manager.users.root = import ./homes/root; - } - { - clan.core.machineDescription = "USB-Stick for Backup"; - } - ]; }; }; - }; - - }); + } + ); } - diff --git a/nix/formatter.nix b/nix/formatter.nix new file mode 100644 index 0000000..17b291d --- /dev/null +++ b/nix/formatter.nix @@ -0,0 +1,16 @@ +{ inputs, ... }: +{ + imports = [ inputs.treefmt-nix.flakeModule ]; + + perSystem = _: { + treefmt = { + projectRootFile = ".git/config"; + programs.nixfmt.enable = true; + programs.terraform.enable = true; + programs.hclfmt.enable = true; + programs.jsonfmt.enable = true; + programs.yamlfmt.enable = true; + programs.black.enable = true; + }; + }; +} diff --git a/treefmt.toml b/treefmt.toml deleted file mode 100644 index 250f237..0000000 --- a/treefmt.toml +++ /dev/null @@ -1,48 +0,0 @@ -# One CLI to format the code tree - https://github.com/numtide/treefmt - -[formatter.nix] -command = "nixpkgs-fmt" -includes = [ "*.nix"] - -[formatter.shell] -command = "shfmt" -options = [ - "-i", - "2", # indent 2 - "-s", # simplify the code - "-w", # write back to the file -] -includes = ["*.sh"] -excludes = ["scripts/hetzner-dedicated-wipe-and-install-nixos.sh"] - -#[formatter.shellcheck] -#command = "shellcheck" -#includes = ["*.sh"] -#excludes = ["./scripts/hetzner-dedicated-wipe-and-install-nixos.sh"] - -[formatter.python] -command = "black" -includes = ["*.py"] - -[formatter.media] -command = "prettier" -options = ["--write"] -includes = [ - "*.json", - "*.md", - "*.yaml", - "*.yml", -] - -[formatter.terragrunt] -command = "terragrunt" -options = [ "hclfmt" ] -includes = [ "*.hcl" ] -excludes = [ "*/.terraform" ] - -[formatter.terraform] -command = "terraform" -options = [ "fmt" ] -includes = [ "*.tf" ] -excludes = [ "*/.terraform" ] -