{
  description = "A highly structured configuration database.";

  inputs =
    {
      # Nix
      nixos.url = "github:nixos/nixpkgs/release-21.11";
      latest.url = "github:nixos/nixpkgs/nixos-unstable";
      # Community
      home.url = "github:nix-community/home-manager/release-21.11";
      home.inputs.nixpkgs.follows = "nixos";
      nixos-hardware.url = "github:nixos/nixos-hardware";
      # Lib
      digga.url = "github:divnix/digga";
      digga.inputs.nixpkgs.follows = "nixos";
      digga.inputs.nixlib.follows = "nixos";
      digga.inputs.home-manager.follows = "home";
      digga.inputs.deploy.follows = "deploy";
      nvfetcher.url = "github:berberman/nvfetcher";
      nvfetcher.inputs.nixpkgs.follows = "nixos";
      naersk.url = "github:nmattia/naersk";
      naersk.inputs.nixpkgs.follows = "nixos";
      # Tools
      agenix.url = "github:ryantm/agenix";
      agenix.inputs.nixpkgs.follows = "nixos";
      deploy.url = "github:serokell/deploy-rs";
      deploy.inputs.nixpkgs.follows = "nixos";
      # Packages
      poonam.url = "git+ssh://gitea@git.sealight.xyz/aynish/kitaab?ref=main";
      basant.url = "git+ssh://gitea@git.sealight.xyz/aynish/basant?ref=main";
      basant.inputs.nixpkgs.follows = "nixos";
      basant.inputs.poonam.follows = "poonam";
      rust-overlay = {
        url = "github:oxalica/rust-overlay";
        inputs.nixpkgs.follows = "nixos";
      };
      eww = {
        url = "github:elkowar/eww";
        inputs.nixpkgs.follows = "nixos";
        inputs.rust-overlay.follows = "rust-overlay";
      };
      # eww follows rust nightly
      # eww.inputs.nixpkgs.follows = "latest";
      grasp.url = "git+ssh://gitea@git.sealight.xyz/aynish/grasp.git?ref=main";
      grasp.inputs.nixpkgs.follows = "nixos";
      tidalcycles.url = "github:mitchmindtree/tidalcycles.nix";
      tidalcycles.inputs.nixpkgs.follows = "latest";
      neovim-nightly.url = "github:nix-community/neovim-nightly-overlay";
      neovim-nightly.inputs.nixpkgs.follows = "nixos";
      # TODO hundred rabbits software
      # TODO not quite useful yet, since it needs secrets
      # dhyan.url = "git+ssh://gitea@git.sealight.xyz/aynish/dhyan?ref=main";
      # dhyan.inputs.nixpkgs.follows = "nixos";
    };

  outputs =
    { self
    , digga
    , nixos
    , home
    , nixos-hardware
    , nur
    , agenix
    , nvfetcher
    , deploy
    , basant
    , grasp
    , tidalcycles
    , neovim-nightly
    , eww
    , ...
    } @ inputs:
    digga.lib.mkFlake
      {
        inherit self inputs;
        supportedSystems = [
          "x86_64-linux"
        ];

        channelsConfig = { allowUnfree = true; };

        channels = {
          nixos = {
            imports = [ (digga.lib.importOverlays ./overlays) ];
            overlays = [
              nur.overlay
              agenix.overlay
              nvfetcher.overlay
              deploy.overlay
              ./pkgs/default.nix
              tidalcycles.overlays.default
              neovim-nightly.overlay
              eww.overlays.default
            ];
          };
          latest = { };
        };

        lib = import ./lib { lib = digga.lib // nixos.lib; };

        sharedOverlays = [
          (final: prev: {
            __dontExport = true;
            lib = prev.lib.extend (lfinal: lprev: {
              our = self.lib;
            });
          })
        ];

        nixos = {
          hostDefaults = {
            system = "x86_64-linux";
            channelName = "nixos";
            imports = [ (digga.lib.importExportableModules ./modules) ];
            modules = [
              { lib.our = self.lib; }
              digga.nixosModules.nixConfig
              home.nixosModules.home-manager
              agenix.nixosModules.age
            ];
          };

          imports = [ (digga.lib.importHosts ./hosts) ];
          hosts = {
            /* set host specific properties here */
            curve = {
              channelName = "nixos";
              #modules = [ ]; # nixos-hardware.nixosModules.lenovo-thinkpad
              # Yubikey
            };
            cube = {
              modules = [ basant.nixosModule ];
            };
            box = {
              modules = [ grasp.nixosModule ];
            };
            # helix = { };
            # work = { };
          };
          importables = rec {
            profiles = digga.lib.rakeLeaves ./profiles // {
              users = digga.lib.rakeLeaves ./users;
            };
            suites = with profiles; rec {
              base = [ core users.root users.anish ];
              sealight = [ base server wireguard-server metrics gitea sealight-website backup ]; # rss-bridge gitea sealight-website matrix backup
              mossnet = [ base server taskd shaarli wallabag dns monitoring nfs rss-bridge gonic headphones radicale seafile syncthing dhyan calibre ]; # hpi sync.music
              cube = [ base site server ];
              graphical = [ base bluetooth music sync.kitaab sync.website sync.cal wifi desktop mimetypes ];
              curve = [ graphical secrets syncthing ];
              work = [ base ];
            };
          };
        };

        home = {
          imports = [ (digga.lib.importExportableModules ./users/modules) ];
          # exportedModules = [ ];
          # modules = [ ];
          importables = rec {
            profiles = digga.lib.rakeLeaves ./users/profiles;
            suites = with profiles; rec {
              hmBase = [ direnv git nvim cli task ];
              gui = [ hmBase firefox desktop email cal ];
              work = [ hmBase firefox ];
            };
          };
          users = {
            nixos = { suites, ... }: { imports = suites.hmBase; };
            anish = { suites, ... }: { imports = suites.gui; };
            anishlakhwara = { suites, ... }: { imports = suites.work; };
          }; # digga.lib.importers.rakeLeaves ./users/hm;
        };

        devshell = ./shell;

        homeConfigurations = digga.lib.mkHomeConfigurations self.nixosConfigurations;

        deploy.nodes = digga.lib.mkDeployNodes self.nixosConfigurations { };
      };
}
