# SPDX-License-Identifier: BlueOak-1.0.0
# SPDX-FileCopyrightText: 2025 toastal <toastal@posteo.net>
{
   description = "factor-nix-demo";

   inputs = {
      nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
   };

   outputs =
      { self, nixpkgs, ... }@inputs:
      let
         # covering what what Factor *should* support (this may differ from
         # what Nix actually support, but could/should)
         supportedSystems = builtins.filter (
            system:
            builtins.any (archPrefix: nixpkgs.lib.hasPrefix archPrefix system) [
               "x86_64-"
               "i686-"
            ]
         ) nixpkgs.lib.systems.flakeExposed;

         nixpkgsFor = nixpkgs.lib.genAttrs supportedSystems (
            system:
            import nixpkgs {
               inherit system;
               overlays = [
                  (import ./nix/overlays/default.nix)
                  (import ./nix/overlays/development.nix)
               ];
            }
         );

         forAllSystems =
            fn:
            nixpkgs.lib.genAttrs supportedSystems (
               system:
               fn rec {
                  inherit system;
                  pkgs = nixpkgsFor.${system};
                  inherit (pkgs) lib;
               }
            );
      in
      {
         overlays = {
            default = import ./nix/overlays/default.nix;
            dev-tools = import ./nix/overlays/development.nix;
         };

         packages = forAllSystems (
            { pkgs, ... }:
            {
               default = pkgs.fello;
            }
         );

         devShells = forAllSystems (
            { pkgs, ... }:
            {
               default = pkgs.fello-dev-shell;
            }
         );

         formatter = forAllSystems ({ pkgs, ... }: pkgs.nixfmt-3-space);
      };
}