:PROPERTIES:
:ID:       94135d47-652e-476c-9c28-5e38c6e070de
:END:
#+title: Lib.nix

* colmena

- https://github.com/zhaofengli/colmena

#+begin_src nix :exports both :results output :tangle "../../lib/colmena.nix"
{
  inputs,
  system ? "x86_64-linux",
}: let
  l = inputs.nixpkgs.lib // builtins;
  colmena = let
    inherit (l.attrsets) foldAttrs recursiveUpdate mapAttrsToList mapAttrs';
    inherit (l.lists) optionals flatten map;

    collect = x:
      foldAttrs recursiveUpdate {
      } (flatten (mapAttrsToList (
          cell: cells:
            optionals (cells ? colmenaConfigurations)
            (map (mapAttrs' (name: value: {
              name =
                if name != "meta"
                then "${cell}-o-${name}"
                else name;
              value =
                if name == "meta" && (value ? nodeNixpkgs)
                then
                  (
                    value
                    // {
                      nixpkgs = import inputs.nixpkgs {
                        inherit system;
                      };
                      nodeNixpkgs =
                        mapAttrs' (
                          name: value: {
                            name = "${cell}-o-${name}";
                            inherit value;
                          }
                        )
                        value.nodeNixpkgs;
                    }
                  )
                else value;
            })) (l.attrValues cells.colmenaConfigurations))
        )
        x));
  in
    # exports have no system, pick one
    collect inputs.self.${system};
in
  colmena
#+end_src

** update lock

#+begin_src sh :async :exports both :results output
nix flake lock --update-input colmena ../../lock/default | date '+%F-%T'
#+end_src

#+RESULTS:
: 2022-10-11-00:52:42


* Deploy Build

#+begin_src sh :async :exports both :results output
just home
#+end_src

