{ inputs = { flake-utils.url = "github:numtide/flake-utils"; nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05"; nixpkgsMaster.url = "github:NixOS/nixpkgs/master"; nur.url = "github:nix-community/NUR"; home-manager = { url = "github:nix-community/home-manager/release-23.05"; inputs.nixpkgs.follows = "nixpkgs"; }; nix-pre-commit-hooks = { url = "github:cachix/pre-commit-hooks.nix/master"; inputs.flake-utils.follows = "flake-utils"; }; sops-nix = { url = "github:Mic92/sops-nix"; inputs.nixpkgs.follows = "nixpkgs"; }; krops = { url = "github:Mic92/krops"; inputs = { flake-utils.follows = "flake-utils"; nixpkgs.follows = "nixpkgs"; }; }; gomod2nix = { url = "github:nix-community/gomod2nix"; inputs = { flake-utils.follows = "flake-utils"; nixpkgs.follows = "nixpkgs"; }; }; }; outputs = { self , nixpkgs , flake-utils , krops , gomod2nix , home-manager , nur , nix-pre-commit-hooks , ... }@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 ] ++ (with inputs; [ sops-nix.nixosModules.sops ]) ++ extraModules; }) (import ./hosts inputs); }; }