{ inputs = { disko.inputs.nixpkgs.follows = "nixpkgs"; disko.url = "github:nix-community/disko"; flake-utils.url = "github:numtide/flake-utils"; gomod2nix.inputs.flake-utils.follows = "flake-utils"; gomod2nix.inputs.nixpkgs.follows = "nixpkgs"; gomod2nix.url = "github:nix-community/gomod2nix"; home-manager.inputs.nixpkgs.follows = "nixpkgs"; home-manager.url = "github:nix-community/home-manager/release-24.05"; krops.inputs.flake-utils.follows = "flake-utils"; krops.inputs.nixpkgs.follows = "nixpkgs"; krops.url = "github:Mic92/krops"; nix-pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs"; nix-pre-commit-hooks.url = "github:cachix/git-hooks.nix/master"; nixos-hardware.url = "github:nixos/nixos-hardware/master"; nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; nixpkgsMaster.url = "github:NixOS/nixpkgs/master"; nur.url = "github:nix-community/NUR"; poetry2nix.inputs.flake-utils.follows = "flake-utils"; poetry2nix.inputs.nixpkgs.follows = "nixpkgs"; poetry2nix.url = "github:nix-community/poetry2nix"; sops-nix.inputs.nixpkgs.follows = "nixpkgs"; sops-nix.url = "github:Mic92/sops-nix"; }; outputs = { self , flake-utils , gomod2nix , home-manager , krops , nix-pre-commit-hooks , nixpkgs , nur , poetry2nix , ... }@inputs: flake-utils.lib.eachSystem [ "x86_64-linux" ] (system: let pkgs = import nixpkgs { inherit system; }; inherit (pkgs) lib; in { checks = { pre-commit-check = nix-pre-commit-hooks.lib.${system}.run { src = self; hooks = { black.enable = true; nixpkgs-fmt.enable = true; shellcheck.enable = true; }; }; }; devShells.default = pkgs.mkShell { buildInputs = (with pkgs; [ black just nixpkgs-fmt shellcheck sops ssh-to-age ]); shellHook = '' ${self.checks.${system}.pre-commit-check.shellHook} ''; }; apps = lib.mapAttrs (name: program: { type = "app"; program = toString program; }) (flake-utils.lib.flattenTree { deploy = lib.recurseIntoAttrs (lib.mapAttrs (hostname: machine: let inherit (krops.packages.${system}) writeCommand; inherit (krops) lib; in writeCommand "deploy-${hostname}" { target = lib.mkTarget "root@${machine.config.deployment.targetHost}" // { extraOptions = [ # force allocation of tty to allow aborting with ^C and to show build progress "-t" ]; }; source = lib.evalSource (lib.singleton { config.file = { path = toString ./.; useChecksum = true; }; }); command = targetPath: '' nixos-rebuild switch --flake ${targetPath}/config -L --keep-going ''; } ) self.nixosConfigurations); argon2id = let python = pkgs.python3.withPackages (pp: with pp; [ argon2-cffi ]); in pkgs.writeTextFile { name = "argon2id"; text = '' #!${python}/bin/python import getpass from argon2 import PasswordHasher pw = getpass.getpass() ph = PasswordHasher( time_cost=5, memory_cost=2*1024*1024, # in kibibytes parallelism=4, ) print(ph.hash(pw)) ''; executable = true; }; }); }) // { overlays.default = import ./pkgs inputs; nixosConfigurations = nixpkgs.lib.mapAttrs (hostname: { system , extraModules ? [ ] , targetHost ? hostname , nixpkgs ? inputs.nixpkgs }: nixpkgs.lib.nixosSystem rec { inherit system; specialArgs = { inherit self system; }; modules = [ (./hosts + "/${hostname}/configuration.nix") ./modules { _module.args = { inputs = inputs; custom-utils = import ./custom-utils { lib = nixpkgs.lib; }; }; } # deployment settings ({ lib, ... }: { options.deployment = { targetHost = lib.mkOption { type = lib.types.str; readOnly = true; internal = true; }; }; config.deployment = { inherit targetHost; }; }) ] ++ [ { nixpkgs.overlays = [ nur.overlay ]; } home-manager.nixosModules.home-manager inputs.sops-nix.nixosModules.sops inputs.disko.nixosModules.disko ] ++ extraModules; }) (import ./hosts inputs); }; }