From d8a533984bf2d9faa06c9eb85cc81c57a0d7c551 Mon Sep 17 00:00:00 2001 From: guangtao Date: Sun, 8 Oct 2023 03:50:56 -0700 Subject: [PATCH] refactor: update haumea --- .envrc | 10 + .github/dependabot.yml | 6 + .github/settings.yml | 15 + .github/workflows/checks.yaml | 25 + .gitignore | 6 + README.org | 68 ++ de-systemize.nix | 22 - examples/__nixpkgsFlake/flake.lock | 630 +++++++++++ examples/__nixpkgsFlake/flake.nix | 12 + examples/__nixpkgsFlake/overlays.nix | 19 + examples/_fmt-style.nix | 260 +++++ examples/_loader.nix | 12 + examples/base.nix | 18 + examples/callFlake.nix | 34 + examples/checks.nix | 11 + examples/haumea.nix | 141 +++ examples/idea.org | 118 +++ examples/learn.nix | 44 + examples/nixpkgs.nix | 13 + flake.lock | 118 ++- flake.nix | 251 +---- local/.github/settings.yml | 15 + local/.gitignore | 22 + local/cells/repo/configs.nix | 14 + local/cells/repo/devshells.nix | 25 + local/flake.lock | 990 ++++++++++++++++++ local/flake.nix | 40 + namaka.toml | 20 + src/__lib/__lock/flake.lock | 60 ++ src/__lib/__lock/flake.nix | 11 + src/__lib/call-flake-override.nix | 10 + src/__lib/concatMapAttrsWith.nix | 23 + src/__lib/deSystemize.nix | 26 + src/__lib/mergeToDepth.nix | 17 + src/__lib/recursiveMerge.nix | 21 + src/__lib/removeAttrsFromDepth.nix | 18 + src/__loader.nix | 17 + src/configs/pops.nix | 111 ++ src/configs/structAttrs.nix | 19 + src/configs/types.nix | 4 + src/flake/pops.nix | 254 +++++ src/flake/structAttrs.nix | 52 + src/flake/types.nix | 7 + src/haumea/nixosModules.nix | 177 ++++ src/haumea/pops.nix | 226 ++++ src/haumea/structAttrs.nix | 79 ++ src/haumea/types.nix | 24 + templates/default/flake.lock | 255 +++++ templates/default/flake.nix | 37 + .../nixosModules/programs/git/default.nix | 10 + tests/_snapshots/configs | 15 + tests/_snapshots/evalModules | 53 + tests/_snapshots/flake | 28 + tests/_snapshots/haumeaData | 100 ++ tests/_snapshots/haumeaNixOSModules | 19 + tests/configs/expr.nix | 29 + tests/configs/format.nix | 1 + .../__fixture/programs/emacs/default.nix | 44 + .../__fixture/programs/git/default.nix | 4 + .../__fixture/programs/git/opt.nix | 15 + .../__fixture/services/openssh.nix | 50 + tests/evalModules/expr.nix | 85 ++ tests/evalModules/format.nix | 1 + tests/flake/__lock/flake.lock | 28 + tests/flake/__lock/flake.nix | 9 + tests/flake/expr.nix | 58 + tests/flake/format.nix | 1 + tests/haumeaData/__data/data.nix | 1 + tests/haumeaData/__data/treefmt.nix | 9 + tests/haumeaData/expr.nix | 62 ++ tests/haumeaData/format.nix | 1 + tests/haumeaNixOSModules/expr.nix | 50 + tests/haumeaNixOSModules/format.nix | 1 + 73 files changed, 4778 insertions(+), 303 deletions(-) create mode 100755 .envrc create mode 100644 .github/dependabot.yml create mode 100644 .github/settings.yml create mode 100644 .github/workflows/checks.yaml create mode 100644 .gitignore create mode 100644 README.org delete mode 100644 de-systemize.nix create mode 100644 examples/__nixpkgsFlake/flake.lock create mode 100644 examples/__nixpkgsFlake/flake.nix create mode 100644 examples/__nixpkgsFlake/overlays.nix create mode 100644 examples/_fmt-style.nix create mode 100644 examples/_loader.nix create mode 100644 examples/base.nix create mode 100644 examples/callFlake.nix create mode 100644 examples/checks.nix create mode 100755 examples/haumea.nix create mode 100644 examples/idea.org create mode 100755 examples/learn.nix create mode 100644 examples/nixpkgs.nix create mode 100755 local/.github/settings.yml create mode 100755 local/.gitignore create mode 100755 local/cells/repo/configs.nix create mode 100755 local/cells/repo/devshells.nix create mode 100755 local/flake.lock create mode 100755 local/flake.nix create mode 100644 namaka.toml create mode 100644 src/__lib/__lock/flake.lock create mode 100644 src/__lib/__lock/flake.nix create mode 100644 src/__lib/call-flake-override.nix create mode 100644 src/__lib/concatMapAttrsWith.nix create mode 100644 src/__lib/deSystemize.nix create mode 100644 src/__lib/mergeToDepth.nix create mode 100644 src/__lib/recursiveMerge.nix create mode 100644 src/__lib/removeAttrsFromDepth.nix create mode 100644 src/__loader.nix create mode 100644 src/configs/pops.nix create mode 100644 src/configs/structAttrs.nix create mode 100644 src/configs/types.nix create mode 100644 src/flake/pops.nix create mode 100644 src/flake/structAttrs.nix create mode 100644 src/flake/types.nix create mode 100644 src/haumea/nixosModules.nix create mode 100644 src/haumea/pops.nix create mode 100644 src/haumea/structAttrs.nix create mode 100644 src/haumea/types.nix create mode 100644 templates/default/flake.lock create mode 100644 templates/default/flake.nix create mode 100644 templates/default/nixosModules/programs/git/default.nix create mode 100644 tests/_snapshots/configs create mode 100644 tests/_snapshots/evalModules create mode 100644 tests/_snapshots/flake create mode 100644 tests/_snapshots/haumeaData create mode 100644 tests/_snapshots/haumeaNixOSModules create mode 100644 tests/configs/expr.nix create mode 100644 tests/configs/format.nix create mode 100644 tests/evalModules/__fixture/programs/emacs/default.nix create mode 100644 tests/evalModules/__fixture/programs/git/default.nix create mode 100644 tests/evalModules/__fixture/programs/git/opt.nix create mode 100644 tests/evalModules/__fixture/services/openssh.nix create mode 100644 tests/evalModules/expr.nix create mode 100644 tests/evalModules/format.nix create mode 100644 tests/flake/__lock/flake.lock create mode 100644 tests/flake/__lock/flake.nix create mode 100644 tests/flake/expr.nix create mode 100644 tests/flake/format.nix create mode 100644 tests/haumeaData/__data/data.nix create mode 100644 tests/haumeaData/__data/treefmt.nix create mode 100644 tests/haumeaData/expr.nix create mode 100644 tests/haumeaData/format.nix create mode 100644 tests/haumeaNixOSModules/expr.nix create mode 100644 tests/haumeaNixOSModules/format.nix diff --git a/.envrc b/.envrc new file mode 100755 index 0000000..aaa5920 --- /dev/null +++ b/.envrc @@ -0,0 +1,10 @@ +# Disable the automatic menu displaying on every environment reload. +# export DEVSHELL_NO_MOTD=1 +watch_file flakes.nix flake.lock +watch_file local/flake.nix local/flake.lock +# shellcheck disable=SC1090 +source "$(fetchurl "https://raw.githubusercontent.com/gtrunsec/direnv/main/lib" "sha256-tuMA8WGkwcYq9V3MtlN6xdVvKd2YkdEpdK4ZyAN6VDM=")" + +registry="$PRJ_ROOT/local#__std" + +use envreload //repo/devshells/default diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..5ace460 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/settings.yml b/.github/settings.yml new file mode 100644 index 0000000..c01b5ee --- /dev/null +++ b/.github/settings.yml @@ -0,0 +1,15 @@ +repository: + allow_merge_commit: false + allow_rebase_merge: true + allow_squash_merge: false + default_branch: main + delete_branch_on_merge: true + description: 'A nix language configuration framework based on POP: Pure Object' + has_downloads: false + has_issues: false + has_projects: false + has_wiki: false + homepage: '' + name: CONFIGURE-ME + private: true + topics: Flops diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml new file mode 100644 index 0000000..70bb4db --- /dev/null +++ b/.github/workflows/checks.yaml @@ -0,0 +1,25 @@ +name: "CI" +on: + pull_request: + push: + branches: + - master +jobs: + nix: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: nixbuild/nix-quick-install-action@v25 + - uses: DeterminateSystems/magic-nix-cache-action@main + + - name: Run Flake Show + run: nix -Lv flake show --override-input namaka github:nix-community/namaka + + - name: Run Eval check + run: nix -Lv eval ./local#checks --override-input namaka github:nix-community/namaka + + - name: Run Format Check + run: nix develop ./local --command treefmt -- . --fail-on-change --no-cache diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..96df412 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/.data +# nixago: ignore-linked-files +/lefthook.yml +/.editorconfig +/.conform.yaml +/treefmt.toml diff --git a/README.org b/README.org new file mode 100644 index 0000000..ee7230e --- /dev/null +++ b/README.org @@ -0,0 +1,68 @@ +#+TITLE: README +#+AUTHOR: GuangTao Zhang +#+EMAIL: gtrunsec@hardenedlinux.org +#+DATE: 2023-05-03 Wed 05:53 + +powered by [[https://github.com/divnix/POP/blob/main/POP.md][POP: Pure Object Prototypes]] && [[https://github.com/nix-community/haumea][haumea]] + + ~A nix language configuration framework based on POP: Pure Object~ + +if you want to understand this repo how works and use cases easily, just read the tests and expressions directly. For having a human-readable test set, the problem of complexity wouldn't exist anymore. + +- snapshots : https://github.com/GTrunSec/flops/blob/master/tests/_snapshots/haumea +- expr: https://github.com/GTrunSec/flops/blob/master/tests/haumea/expr.nix + +* bye bye, a bloated flake inputs + +We could avoid putting all the inputs in the main flake.nix + +- use the ~flake.pops.default~ to load a subflake. + +#+begin_src nix +callInputs = + (flops.lib.flake.pops.default.setInitInputs ./lib/__lock) + .setSystem + "x86_64-linux"; +#+end_src + +* Merge + +** dmerge + +you can't use the dmerge for the nixosModules + +- David Arnold (blaggacao) said +#+begin_quote +dmerge can only work with json-serializable data on both sides. That's by design. +#+end_quote + +#+begin_src nix :async :exports both :results output + test = with dmerge; + merge { + a.b.c = []; + a.c = lib.mkOption { + type = lib.types.submodule { + freeformType = lib.types.attrs; + options = { + enable = lib.mkEnableOption (lib.mdDoc "Whether to enable git profile"); + }; + }; + }; + } {a.b.c = append ["a" "b" "c"];}; + + testNonMerge = + { + a.b.c = []; + a.c = lib.mkOption { + type = lib.types.submodule { + freeformType = lib.types.attrs; + options = { + enable = lib.mkEnableOption (lib.mdDoc "Whether to enable git profile"); + }; + }; + }; + } + // {d = "d";}; +#+end_src + + So, we use *withoutMergedOptions* to keep the native options after the action of merged. diff --git a/de-systemize.nix b/de-systemize.nix deleted file mode 100644 index d6cb53f..0000000 --- a/de-systemize.nix +++ /dev/null @@ -1,22 +0,0 @@ -let - l = builtins; - /* - A helper function which hides the complexities of dealing - with 'system' properly from you, while still providing - escape hatches when dealing with cross-compilation. - - You can use this function independently of the rest of std. - */ - deSystemize = let - iteration = cutoff: system: fragment: - if ! (l.isAttrs fragment) || cutoff == 0 - then fragment - else if l.hasAttr "${system}" fragment && ! l.isFunction fragment.${system} - then fragment // fragment.${system} - else if l.hasAttr "${system}" fragment && l.isFunction fragment.${system} - then fragment // {__functor = _: fragment.${system};} - else l.mapAttrs (_: iteration (cutoff - 1) system) fragment; - in - iteration 3; -in - deSystemize diff --git a/examples/__nixpkgsFlake/flake.lock b/examples/__nixpkgsFlake/flake.lock new file mode 100644 index 0000000..eb98275 --- /dev/null +++ b/examples/__nixpkgsFlake/flake.lock @@ -0,0 +1,630 @@ +{ + "nodes": { + "blank": { + "locked": { + "lastModified": 1625557891, + "narHash": "sha256-O8/MWsPBGhhyPoPLHZAuoZiiHo9q6FLlEeIDEXuj6T4=", + "owner": "divnix", + "repo": "blank", + "rev": "5a5d2684073d9f563072ed07c871d577a6c614a8", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "blank", + "type": "github" + } + }, + "crane": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "std", + "paisano-mdbook-preprocessor", + "nixpkgs" + ], + "rust-overlay": "rust-overlay" + }, + "locked": { + "lastModified": 1676162383, + "narHash": "sha256-krUCKdz7ebHlFYm/A7IbKDnj2ZmMMm3yIEQcooqm7+E=", + "owner": "ipetkov", + "repo": "crane", + "rev": "6fb400ec631b22ccdbc7090b38207f7fb5cfb5f2", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "devshell": { + "inputs": { + "flake-utils": [ + "std", + "flake-utils" + ], + "nixpkgs": [ + "std", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1682700442, + "narHash": "sha256-qjaAAcCYgp1pBBG7mY9z95ODUBZMtUpf0Qp3Gt/Wha0=", + "owner": "numtide", + "repo": "devshell", + "rev": "fb6673fe9fe4409e3f43ca86968261e970918a83", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "dmerge": { + "inputs": { + "haumea": "haumea", + "namaka": "namaka", + "nixlib": [ + "std", + "nixpkgs" + ], + "yants": [ + "std", + "yants" + ] + }, + "locked": { + "lastModified": 1684178600, + "narHash": "sha256-EtSQcCHRQUBBEj4vbYU0vgPUYiKP261ero5k1QfQ3Bc=", + "owner": "divnix", + "repo": "dmerge", + "rev": "ac9932f26325afac5baa59cf6478432d17762a4e", + "type": "github" + }, + "original": { + "owner": "divnix", + "ref": "0.2.0", + "repo": "dmerge", + "type": "github" + } + }, + "fenix": { + "inputs": { + "nixpkgs": "nixpkgs_4", + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1677306201, + "narHash": "sha256-VZ9x7qdTosFvVsrpgFHrtYfT6PU3yMIs7NRYn9ELapI=", + "owner": "nix-community", + "repo": "fenix", + "rev": "0923f0c162f65ae40261ec940406049726cfeab4", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "haumea": { + "inputs": { + "nixpkgs": [ + "std", + "dmerge", + "nixlib" + ] + }, + "locked": { + "lastModified": 1681176209, + "narHash": "sha256-bJLDun6esIyWtwRVXcsgzGbh4UKu8wJDrPgykqPyzmg=", + "owner": "nix-community", + "repo": "haumea", + "rev": "b915b66b27da3a595d77b139e945bb0a2fcac926", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "haumea", + "type": "github" + } + }, + "haumea_2": { + "inputs": { + "nixpkgs": [ + "std", + "paisano", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1681176209, + "narHash": "sha256-bJLDun6esIyWtwRVXcsgzGbh4UKu8wJDrPgykqPyzmg=", + "owner": "nix-community", + "repo": "haumea", + "rev": "b915b66b27da3a595d77b139e945bb0a2fcac926", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "haumea", + "type": "github" + } + }, + "incl": { + "inputs": { + "nixlib": [ + "std", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1669263024, + "narHash": "sha256-E/+23NKtxAqYG/0ydYgxlgarKnxmDbg6rCMWnOBqn9Q=", + "owner": "divnix", + "repo": "incl", + "rev": "ce7bebaee048e4cd7ebdb4cee7885e00c4e2abca", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "incl", + "type": "github" + } + }, + "n2c": { + "inputs": { + "flake-utils": [ + "std", + "flake-utils" + ], + "nixpkgs": [ + "std", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1677330646, + "narHash": "sha256-hUYCwJneMjnxTvj30Fjow6UMJUITqHlpUGpXMPXUJsU=", + "owner": "nlewo", + "repo": "nix2container", + "rev": "ebca8f58d450cae1a19c07701a5a8ae40afc9efc", + "type": "github" + }, + "original": { + "owner": "nlewo", + "repo": "nix2container", + "type": "github" + } + }, + "namaka": { + "inputs": { + "haumea": [ + "std", + "dmerge", + "haumea" + ], + "nixpkgs": [ + "std", + "dmerge", + "nixlib" + ] + }, + "locked": { + "lastModified": 1683059428, + "narHash": "sha256-ZTMqleCWmuNWhZE375gtF1j1JRkaKEUFN1AM43e7h4Y=", + "owner": "nix-community", + "repo": "namaka", + "rev": "2deba2f416454aec770bc1cc7365e39c73e6b1d7", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "v0.1.1", + "repo": "namaka", + "type": "github" + } + }, + "namaka_2": { + "inputs": { + "haumea": [ + "std", + "paisano", + "haumea" + ], + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1681604203, + "narHash": "sha256-oA/fW/85GmSNprghgAnZi0XeVMvW9xVuCYprzPw2hz0=", + "owner": "nix-community", + "repo": "namaka", + "rev": "1550ddc025334cff2e8ec9021256473b2ffb27e5", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "namaka", + "type": "github" + } + }, + "nixago": { + "inputs": { + "flake-utils": [ + "std", + "flake-utils" + ], + "nixago-exts": [ + "std", + "blank" + ], + "nixpkgs": [ + "std", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1683210100, + "narHash": "sha256-bhGDOlkWtlhVECpoOog4fWiFJmLCpVEg09a40aTjCbw=", + "owner": "nix-community", + "repo": "nixago", + "rev": "1da60ad9412135f9ed7a004669fdcf3d378ec630", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixago", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1683475240, + "narHash": "sha256-sy6MYoCaIZsOenYplbzVXI4Ce9Bp/vIOpuFa97+a6wc=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "e040aab15638aaf8d0786894851a2b1ca09a7baf", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1675940568, + "narHash": "sha256-epG6pOT9V0kS+FUqd7R6/CWkgnZx2DMT5Veqo+y6G3c=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "6ccc4a59c3f1b56d039d93da52696633e641bc71", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1680758185, + "narHash": "sha256-sCVWwfnk7zEX8Z+OItiH+pcSklrlsLZ4TJTtnxAYREw=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "0e19daa510e47a40e06257e205965f3b96ce0ac9", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_4": { + "locked": { + "lastModified": 1677063315, + "narHash": "sha256-qiB4ajTeAOVnVSAwCNEEkoybrAlA+cpeiBxLobHndE8=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "988cc958c57ce4350ec248d2d53087777f9e1949", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nosys": { + "locked": { + "lastModified": 1668010795, + "narHash": "sha256-JBDVBnos8g0toU7EhIIqQ1If5m/nyBqtHhL3sicdPwI=", + "owner": "divnix", + "repo": "nosys", + "rev": "feade0141487801c71ff55623b421ed535dbdefa", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "nosys", + "type": "github" + } + }, + "paisano": { + "inputs": { + "haumea": "haumea_2", + "namaka": "namaka_2", + "nixpkgs": [ + "std", + "nixpkgs" + ], + "nosys": "nosys", + "yants": [ + "std", + "yants" + ] + }, + "locked": { + "lastModified": 1685757649, + "narHash": "sha256-gu21uo35i5OguZ5laGpqIFgVRcowbjvLn2mxSyNKZfQ=", + "owner": "paisano-nix", + "repo": "core", + "rev": "db53b8a8e2e3e557bf5ec5842b7a52ee5de04e87", + "type": "github" + }, + "original": { + "owner": "paisano-nix", + "ref": "0.1.0", + "repo": "core", + "type": "github" + } + }, + "paisano-actions": { + "inputs": { + "nixpkgs": [ + "std", + "paisano-mdbook-preprocessor", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1677306424, + "narHash": "sha256-H9/dI2rGEbKo4KEisqbRPHFG2ajF8Tm111NPdKGIf28=", + "owner": "paisano-nix", + "repo": "actions", + "rev": "65ec4e080b3480167fc1a748c89a05901eea9a9b", + "type": "github" + }, + "original": { + "owner": "paisano-nix", + "repo": "actions", + "type": "github" + } + }, + "paisano-mdbook-preprocessor": { + "inputs": { + "crane": "crane", + "fenix": "fenix", + "nixpkgs": [ + "std", + "nixpkgs" + ], + "paisano-actions": "paisano-actions", + "std": [ + "std" + ] + }, + "locked": { + "lastModified": 1680654400, + "narHash": "sha256-Qdpio+ldhUK3zfl22Mhf8HUULdUOJXDWDdO7MIK69OU=", + "owner": "paisano-nix", + "repo": "mdbook-paisano-preprocessor", + "rev": "11a8fc47f574f194a7ae7b8b98001f6143ba4cf1", + "type": "github" + }, + "original": { + "owner": "paisano-nix", + "repo": "mdbook-paisano-preprocessor", + "type": "github" + } + }, + "paisano-tui": { + "inputs": { + "nixpkgs": [ + "std", + "blank" + ], + "std": [ + "std" + ] + }, + "locked": { + "lastModified": 1681847764, + "narHash": "sha256-mdd7PJW1BZvxy0cIKsPfAO+ohVl/V7heE5ZTAHzTdv8=", + "owner": "paisano-nix", + "repo": "tui", + "rev": "3096bad91cae73ab8ab3367d31f8a143d248a244", + "type": "github" + }, + "original": { + "owner": "paisano-nix", + "ref": "0.1.1", + "repo": "tui", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "std": "std" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1677221702, + "narHash": "sha256-1M+58rC4eTCWNmmX0hQVZP20t3tfYNunl9D/PrGUyGE=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "f5401f620699b26ed9d47a1d2e838143a18dbe3b", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "std", + "paisano-mdbook-preprocessor", + "crane", + "flake-utils" + ], + "nixpkgs": [ + "std", + "paisano-mdbook-preprocessor", + "crane", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1675391458, + "narHash": "sha256-ukDKZw922BnK5ohL9LhwtaDAdCsJL7L6ScNEyF1lO9w=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "383a4acfd11d778d5c2efcf28376cbd845eeaedf", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "std": { + "inputs": { + "arion": [ + "std", + "blank" + ], + "blank": "blank", + "devshell": "devshell", + "dmerge": "dmerge", + "flake-utils": "flake-utils", + "incl": "incl", + "makes": [ + "std", + "blank" + ], + "microvm": [ + "std", + "blank" + ], + "n2c": "n2c", + "nixago": "nixago", + "nixpkgs": "nixpkgs_2", + "paisano": "paisano", + "paisano-mdbook-preprocessor": "paisano-mdbook-preprocessor", + "paisano-tui": "paisano-tui", + "yants": "yants" + }, + "locked": { + "lastModified": 1686006649, + "narHash": "sha256-6sdvFtQyx7SZoki1MlO2+3Xns4jmR34FEjlXawQdwhk=", + "owner": "divnix", + "repo": "std", + "rev": "d6bcee9c35fb4a905b51c39e4d5ca842e9a421eb", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "std", + "type": "github" + } + }, + "yants": { + "inputs": { + "nixpkgs": [ + "std", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1667096281, + "narHash": "sha256-wRRec6ze0gJHmGn6m57/zhz/Kdvp9HS4Nl5fkQ+uIuA=", + "owner": "divnix", + "repo": "yants", + "rev": "d18f356ec25cb94dc9c275870c3a7927a10f8c3c", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "yants", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/examples/__nixpkgsFlake/flake.nix b/examples/__nixpkgsFlake/flake.nix new file mode 100644 index 0000000..d356514 --- /dev/null +++ b/examples/__nixpkgsFlake/flake.nix @@ -0,0 +1,12 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + std.url = "github:divnix/std"; + }; + outputs = + { self, ... }@inputs: + { + inherit inputs; + packages = inputs.nixpkgs.legacyPackages.x86_64-linux.hello; + }; +} diff --git a/examples/__nixpkgsFlake/overlays.nix b/examples/__nixpkgsFlake/overlays.nix new file mode 100644 index 0000000..365bd62 --- /dev/null +++ b/examples/__nixpkgsFlake/overlays.nix @@ -0,0 +1,19 @@ +inputs: +let + inherit (inputs.POP.lib) kxPop extendPop; +in +pkgs: _: { + helloPop = extendPop pkgs.hello ( + hello: super: { + propagatedBuildInputs = super.propagatedBuildInputs ++ [ pkgs.curl ]; + + attrs = extendPop super.drvAttrs ( + _: superAttrs: { + src = extendPop superAttrs.src ( + params: superGL: { propagatedBuildInputs = [ pkgs.wget ]; } + ); + } + ); + } + ); +} diff --git a/examples/_fmt-style.nix b/examples/_fmt-style.nix new file mode 100644 index 0000000..f0166d8 --- /dev/null +++ b/examples/_fmt-style.nix @@ -0,0 +1,260 @@ +{ lib }: +let + inherit (lib) + dashboard + kPop + row + link + ; +in +[ + ((((((((((((lib.dashboard.new { title = "test"; }).addTemplate ( + kPop { test1 = true; } + )).addTemplates + ([ + (kPop { test2 = true; }) + (kPop { test3 = true; }) + ]) + ).addRow + ( + row.new { + title = "1"; + height = "250px"; + } + ) + ).addRow + ( + row.new { + title = "2"; + height = "250px"; + } + ) + ).addRows + [ + (row.new { + title = "1"; + height = "250px"; + }) + (row.new { + title = "2"; + height = "250px"; + }) + ] + ).addAnnotation + "foo" + ).addAnnotation + "bar" + ).addAnnotations + [ + "foo2" + "bar2" + ] + ).addLink + "foolinks" + ).addLink + "barlinks" + ).addLinks + [ + (link.dashboards { + title = "foo"; + tags = [ + "foo" + "bar" + ]; + }) + (link.dashboards { + title = "bar"; + tags = [ + "foo" + "bar" + ]; + }) + ] + ).__unpop__ + + ((((((dashboard.new { title = "test2"; }).addPanel { + panel = row.new { title = "id0"; }; + gridPos = { + x = 14; + y = 42; + w = 33; + h = 26; + }; + }).addPanel + { + panel = row.new { title = "id1"; }; + gridPos = { + x = 24; + y = 52; + w = 43; + h = 36; + }; + } + ).addPanel + { + panel = row.new { title = "id2"; }; + gridPos = { + x = 34; + y = 62; + w = 53; + h = 36; + }; + } + ).addPanel + { + panel = row.new { title = "id5"; }; + gridPos = { + x = 44; + y = 72; + w = 63; + h = 46; + }; + } + ).addPanels + [ + (lib.kxPop (row.new { title = "id5"; }) { + x = 41; + y = 71; + w = 61; + h = 41; + }) + ] + ).__unpop__ + + (((((dashboard.new { title = "test2"; }).addPanel { + panel = row.new { title = "id0"; }; + gridPos = { + x = 14; + y = 42; + w = 33; + h = 26; + }; + }).addPanel + { + panel = row.new { title = "id1"; }; + gridPos = { + x = 24; + y = 52; + w = 43; + h = 36; + }; + } + ).addPanel + { + panel = row.new { title = "id2"; }; + gridPos = { + x = 34; + y = 62; + w = 53; + h = 36; + }; + } + ).addPanel + { + panel = row.new { title = "id5"; }; + gridPos = { + x = 44; + y = 72; + w = 63; + h = 46; + }; + } + ).__unpop__ + + (((dashboard.new { title = "subId"; }).addPanels [ + (lib.kxPop + (row.new { + title = "id0"; + height = "250px"; + }) + { + panels = [ + (kPop { foo = "id1"; }) + (kPop { bar = "id2"; }) + ]; + } + ) + (row.new { + title = "id3"; + height = "250px"; + }) + (row.new { + title = "id4"; + height = "250px"; + }) + (kPop { title = "id5"; }) + (kPop { title = "id6"; }) + (kPop { title = "id7"; }) + (kPop { title = "id8"; }) + (lib.kxPop + (row.new { + title = "id9"; + height = "250px"; + }) + { + panels = [ + (kPop { foo = "id10"; }) + (kPop { bar = "id11"; }) + ]; + } + ) + (kPop { title = "id12"; }) + (kPop { title = "id13"; }) + (kPop { title = "id14"; }) + ]).addPanels + [ + (lib.kxPop (row.new { title = "id15"; }) { + panels = [ + (kPop { foo = "id16"; }) + (kPop { bar = "id17"; }) + ]; + }) + (row.new { title = "id18"; }) + (row.new { title = "id19"; }) + (kPop { title = "id20"; }) + (kPop { title = "id21"; }) + (kPop { title = "id22"; }) + (kPop { title = "id23"; }) + ] + ).__unpop__ + + (((((dashboard.new { title = "test3"; }).addPanel { + panel = kPop { foo = "bar"; }; + gridPos = { + x = 14; + y = 42; + w = 33; + h = 26; + }; + }).addPanel + { + panel = kPop { foo = "bar"; }; + gridPos = { + x = 24; + y = 52; + w = 43; + h = 36; + }; + } + ).addPanel + { + panel = kPop { foo = "bar"; }; + gridPos = { + x = 34; + y = 62; + w = 53; + h = 36; + }; + } + ).addPanel + { + panel = kPop { foo = "bar"; }; + gridPos = { + x = 44; + y = 72; + w = 63; + h = 46; + }; + } + ).__unpop__ +] diff --git a/examples/_loader.nix b/examples/_loader.nix new file mode 100644 index 0000000..64fd6e8 --- /dev/null +++ b/examples/_loader.nix @@ -0,0 +1,12 @@ +{ lib, inputs }: +let + inherit (inputs) nixlib; + l = nixlib // builtins; +in +inputs.haumea.lib.load { + src = ./.; + inputs = { + inherit inputs lib; + inherit (lib) configs flake; + }; +} diff --git a/examples/base.nix b/examples/base.nix new file mode 100644 index 0000000..c762573 --- /dev/null +++ b/examples/base.nix @@ -0,0 +1,18 @@ +{ inputs, lib }: +let + inherit (lib) configs; +in +(( + ((configs.pops.default.setInitRecipes { profiles = { }; }).addRecipesExtender { + exx = { + a = "2"; + }; + }) +).addArgsExtender + { nixos.default = { }; } +).addExporters + [ + (inputs.POP.lib.extendPop configs.pops.exporter ( + self: super: { exports.nixos = self.recipes; } + )) + ] diff --git a/examples/callFlake.nix b/examples/callFlake.nix new file mode 100644 index 0000000..77f3d27 --- /dev/null +++ b/examples/callFlake.nix @@ -0,0 +1,34 @@ +{ + lib, + inputs, + self, +}: +let + inherit (inputs) POP; + inherit (lib) flake; +in +{ + a = + ((((flake.pops.default.setInitInputs ./__nixpkgsFlake).setSystem "x86_64-linux") + .addInputsExtender + ( + POP.lib.extendPop flake.pops.inputsExtender ( + self: super: { + inputs.nixlib = inputs.nixlib; + inputs.b = throw "should not be evaluated"; + inputs.custom = self.inputs.nixlib; + } + ) + ) + ).addInputsOverrideExtender + ( + POP.lib.extendPop flake.pops.inputsExtender ( + self: super: { overrideInputs.std = "s"; } + ) + ) + ); + + b = self.a.addInputsExtender ( + POP.lib.extendPop flake.pops.inputsExtender (self: super: { inputs.b = "2"; }) + ); +} diff --git a/examples/checks.nix b/examples/checks.nix new file mode 100644 index 0000000..83b1bf2 --- /dev/null +++ b/examples/checks.nix @@ -0,0 +1,11 @@ +{ + inputs, + configs, + lib, +}: +inputs.haumea.lib.load { + src = ../tests; + inputs = { + inherit inputs configs lib; + }; +} diff --git a/examples/haumea.nix b/examples/haumea.nix new file mode 100755 index 0000000..8de2026 --- /dev/null +++ b/examples/haumea.nix @@ -0,0 +1,141 @@ +{ inputs, lib }: +with inputs.haumea.lib; +let + l = lib // builtins; + trace = x: l.trace x x; + inherit (inputs) dmerge; + inherit (inputs.POP.lib) pop extendPop kxPop; + inherit (lib.haumea) pops; + + a = + (pops.default.setInit { + src = ./.; + inputs = { + inherit lib; + }; + }).addLoadExtender + ( + extendPop pops.loadExtender ( + self: super: { + load.inputs = { + inherit inputs; + }; + } + ) + ); + + b = a.addLoadExtender { + load = { + src = ../..; + loader = [ (matchers.nix loaders.scoped) ]; + inputs = { + inherit dmerge; + }; + }; + }; + + b1 = b.addLoadExtender { + load = { + inputs = { + a = "1"; + }; + src = ../tests/haumeaData/__data; + }; + }; + + c = + ((b.addLoadExtender { src = ../tests/haumeaData/__data; }).addLoadExtender ( + extendPop pops.loadExtender ( + self: super: { + load = { + loader = [ (matchers.nix loaders.scoped) ]; + }; + } + ) + )).addExporters + [ + (extendPop pops.exporter ( + self: super: { + exports.a = self; + # exports.mergedOutputs = + # with dmerge; + # merge self.outputs.default { + # treefmt.formatter.prettier.includes = append [ "*.jsl" ]; + # data.foo = "barzf"; + # }; + } + )) + ]; + + # d = c.addExporters [ + # (extendPop pops.exporter ( + # self: super: { exports.mergedPrevOutputs = self.exports; } + # )) + # ]; + # + d = c.addLoadExtender { + loader = [ (matchers.nix loaders.scoped) ]; + inputs = { + inherit (inputs) nixlib; + }; + }; + + g = + (pops.default.setInit { + src = ../tests/evalModules/__fixture; + type = "nixosModules"; + inputs = { + inherit lib POP; + }; + }).addExporters + [ + (extendPop pops.exporter ( + self: super: { + exports.customModules = self.outputs.__extenders [ { + value = + { selfModule' }: + selfModule' ( + m: + dmerge m { + config.services.openssh.enable = false; + config.services.openssh.customList = [ "1" ]; + imports = with dmerge; append [ ]; + } + ); + + path = [ + "services" + "openssh" + ]; + } ]; + } + )) + ]; + + evalModules = l.evalModules { + modules = [ + g.exports.customModules.services.openssh + g.outputs.default.programs.emacs + g.outputs.default.programs.git + ]; + }; + + mkOpt = { + type = "string"; + default = x; + }; +in +{ + inherit + a + b + c + d + g + h + evalModules + loadd + b1 + ; + options = mkOpt { test = "1"; }; +} diff --git a/examples/idea.org b/examples/idea.org new file mode 100644 index 0000000..2b86cfc --- /dev/null +++ b/examples/idea.org @@ -0,0 +1,118 @@ +#+TITLE: idea +#+AUTHOR: GuangTao Zhang +#+EMAIL: gtrunsec@hardenedlinux.org +#+DATE: 2023-04-16 Sun 16:16 + + +* pops +** Example + +#+begin_src nix +{ + pops.configs.setInitConfigs { + nixos = nixosRecipes; + home-manager = homeManagerRecipes; + }; +} +#+end_src + +** configsExtender + +#+begin_src nix +{ + defaults = { + initConfigs = {}; + configs = { + # set the recipe from haumea load + nixos = { }; + terrnix = {}; + home-manager = {}; + nix-nomad = {}; + }; + }; +} +#+end_src + + +* recipes + +#+begin_src nix +{ + nixosModules = with haumea.lib; + load { + src = ./nixosModules; + transformer = with inputs.haumea.lib.transformers; [ + liftDefault + (hoistLists "_imports" "imports") + (hoistAttrs "_api" "options") + ]; + inherit inputs; + }; + + homeModules = with haumea.lib; + load { + src = ./homeModules; + transformer = with inputs.haumea.lib.transformers; [ + liftDefault + (hoistLists "_imports" "imports") + (hoistAttrs "_api" "options") + ]; + }; + terrnix = load { + src = ./terrnix; + transformer = with inputs.haumea.lib.transformers; [ + liftDefault + ]; + }; +} +#+end_src + +** nixosModules + +- toplevel + +#+begin_src nix +{ + common = load.nixosModules; + user_1 = load.nixosModules_1; + guangtao = load.nixosMules_2; +} +#+end_src + +- haumea Src + +#+begin_src nix +{ + nixosModules = { + imports = []; # hoisted by transformer + services = {}; + programs = {}; + users = {}; + }; +} +#+end_src + + + + +* FileSystems + +** top-level + +#+begin_src sh +{ + users = { user1_ user_2 } # user specifical + hosts = { host_1 host_2 } # +} +#+end_src + +** second-level + +#+begin_src nix +{ + user1 = { + nixosModules = {} + homeModules = {} + }; +} +#+end_src diff --git a/examples/learn.nix b/examples/learn.nix new file mode 100755 index 0000000..489f5cc --- /dev/null +++ b/examples/learn.nix @@ -0,0 +1,44 @@ +{ inputs }: +let + l = inputs.nixlib.lib // builtins; + inherit (inputs.POP.lib) pop extendPop kxPop; + A = pop { + defaults = { + a = 5; + b = 2; + e = { + x = 1; + y = 2; + }; + }; + extension = self: super: { + a = super.a + 1; + c = 3; + }; + }; + B = pop { + defaults = { + fExtenders = [ ]; + }; + supers = [ A ]; + extension = self: super: { + d = super.a + super.c; + inputs = l.fold (acc: ext: acc // ext) self.e self.fExtenders; + addf = + fExtenders: + extendPop self (self: super: { fExtenders = super.fExtenders ++ fExtenders; }); + }; + }; + C = B.addf [ (extendPop A (self: super: { g = self.a; })) ]; +in +{ + inherit A B C; + + functorOrPop = + (name: { + __functor = self: selectors: self // selectors; + inherit name; + type = "__functor"; + }) + "functor"; +} diff --git a/examples/nixpkgs.nix b/examples/nixpkgs.nix new file mode 100644 index 0000000..30215ac --- /dev/null +++ b/examples/nixpkgs.nix @@ -0,0 +1,13 @@ +{ lib, inputs }: +let + inherit (lib) flake; +in +let + callInputs = + ((flake.pops.default.setInitInputs ./__nixpkgsFlake).setSystem "x86_64-linux") + .outputs; + nixpkgs = callInputs.nixpkgs; +in +nixpkgs.legacyPackages.appendOverlays [ + (import ./__nixpkgsFlake/overlays.nix inputs) +] diff --git a/flake.lock b/flake.lock index 360a3e4..2613d2f 100644 --- a/flake.lock +++ b/flake.lock @@ -2,9 +2,9 @@ "nodes": { "POP": { "inputs": { - "flake-compat": "flake-compat", + "flake-compat": [], "nixlib": "nixlib", - "nixpkgs": "nixpkgs" + "nixpkgs": [] }, "locked": { "lastModified": 1655410953, @@ -20,83 +20,98 @@ "type": "github" } }, - "flake-compat": { - "flake": false, + "call-flake": { "locked": { - "lastModified": 1650374568, - "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "b4a34015c698c7793d592d66adbab377907a2be8", + "lastModified": 1696728032, + "narHash": "sha256-bmhE1TmrJG4ba93l9WQTLuYM53kwGQAjYHRvHOeuxWU=", + "owner": "divnix", + "repo": "call-flake", + "rev": "c4928386ea2065351750992411c6e53f11552397", "type": "github" }, "original": { - "owner": "edolstra", - "repo": "flake-compat", + "owner": "divnix", + "repo": "call-flake", "type": "github" } }, - "nixlib": { + "dmerge": { + "inputs": { + "haumea": [ + "haumea" + ], + "nixlib": [ + "nixlib" + ], + "yants": [ + "yants" + ] + }, "locked": { - "lastModified": 1653180592, - "narHash": "sha256-sVGwmxTj7CY1D4ioy7E+iJE+1/yHqQlxjnTpar3ap/E=", - "owner": "nix-community", - "repo": "nixpkgs.lib", - "rev": "42c5f5785b70cd64b4afd830dc31d0b08461abd5", + "lastModified": 1686862774, + "narHash": "sha256-ojGtRQ9pIOUrxsQEuEPerUkqIJEuod9hIflfNkY+9CE=", + "owner": "divnix", + "repo": "dmerge", + "rev": "9f7f7a8349d33d7bd02e0f2b484b1f076e503a96", "type": "github" }, "original": { - "owner": "nix-community", - "repo": "nixpkgs.lib", + "owner": "divnix", + "repo": "dmerge", "type": "github" } }, - "nixlib_2": { + "haumea": { + "inputs": { + "nixpkgs": [ + "nixlib" + ] + }, "locked": { - "lastModified": 1670719927, - "narHash": "sha256-HFFqs0tj+ebkNzdCjq+3gACKtdEZKYc/sZms4DTIx3Q=", + "lastModified": 1689557889, + "narHash": "sha256-kllmt6JnHlry+WAASdSMDaRwbiuk2dFhkbW3Qz1w8BU=", "owner": "nix-community", - "repo": "nixpkgs.lib", - "rev": "326ba2ee6cb73c64e8bd73932f61439ea082cde9", + "repo": "haumea", + "rev": "d6a9593ff2160ce29bf6d905e9ccbcecd66baeef", "type": "github" }, "original": { "owner": "nix-community", - "repo": "nixpkgs.lib", + "repo": "haumea", "type": "github" } }, - "nixpkgs": { + "nixlib": { "locked": { - "lastModified": 1653581809, - "narHash": "sha256-Uvka0V5MTGbeOfWte25+tfRL3moECDh1VwokWSZUdoY=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "83658b28fe638a170a19b8933aa008b30640fbd1", + "lastModified": 1653180592, + "narHash": "sha256-sVGwmxTj7CY1D4ioy7E+iJE+1/yHqQlxjnTpar3ap/E=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "42c5f5785b70cd64b4afd830dc31d0b08461abd5", "type": "github" }, "original": { - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", + "owner": "nix-community", + "repo": "nixpkgs.lib", "type": "github" } }, - "nixpkgs_2": { + "nixlib_2": { "locked": { - "lastModified": 1671728284, - "narHash": "sha256-u5Tlz4bl2vb9CB+L/A/Xp8F32062vo3K6yl7J9FBXdc=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "7ba7b4599367c07f2f5d1e26151b68a71a1336b2", + "lastModified": 1696726172, + "narHash": "sha256-89yxFXzTA7JRyWo6hg7SD4DlS/ejYt8Y8IvGZHbSWsg=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "59da6ac0c02c48aa92dee37057f978412797db2a", "type": "github" }, "original": { - "id": "nixpkgs", - "type": "indirect" + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" } }, - "nixpkgs_3": { + "nixpkgs": { "locked": { "lastModified": 1660438583, "narHash": "sha256-rJUTYxFKlWUJI3njAwEc1pKAVooAViZGJvsgqfh/q/E=", @@ -114,26 +129,27 @@ "root": { "inputs": { "POP": "POP", + "call-flake": "call-flake", + "dmerge": "dmerge", + "haumea": "haumea", "nixlib": "nixlib_2", - "nixpkgs": "nixpkgs_2", "yants": "yants" } }, "yants": { "inputs": { - "nixpkgs": "nixpkgs_3" + "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1671695273, - "narHash": "sha256-KC032e1G3MKPeW8JWgL/bBvbv529ch13sFgsd2MNSFQ=", - "owner": "Pacman99", + "lastModified": 1686863218, + "narHash": "sha256-kooxYm3/3ornWtVBNHM3Zh020gACUyFX2G0VQXnB+mk=", + "owner": "divnix", "repo": "yants", - "rev": "8188069859ed05a3036d4bf079160a6b8edb01ca", + "rev": "8f0da0dba57149676aa4817ec0c880fbde7a648d", "type": "github" }, "original": { - "owner": "Pacman99", - "ref": "open-structs", + "owner": "divnix", "repo": "yants", "type": "github" } diff --git a/flake.nix b/flake.nix index 5d84098..31027f1 100644 --- a/flake.nix +++ b/flake.nix @@ -2,239 +2,30 @@ inputs = { nixlib.url = "github:nix-community/nixpkgs.lib"; POP.url = "github:divnix/POP"; - yants.url = "github:Pacman99/yants/open-structs"; - }; - - outputs = { - self, - nixlib, - POP, - yants, - nixpkgs, - }: let - inherit (builtins) removeAttrs attrNames isAttrs filter; - inherit (nixlib.lib) mapAttrs genAttrs foldl mapAttrsToList flatten; - inherit (POP.lib) pop unpop extendPop kxPop; - inherit (self.lib) deSystemize mergeToDepth; - inherit (yants) defun; - - types = self.types // yants; - - structAttrs = with yants; { - pop = { - __meta__ = option (struct "__meta__" { - name = string; - supers = list types.pop; - defaults = attrs any; - extension = function; - precedenceList = list (attrs any); - }); - }; - - exporterPop = - structAttrs.pop - // { - inputs = attrs any; - exports = attrs any; - setInputs = function; - }; - - inputsExtenderPop = - structAttrs.pop - // { - initInputs = attrs any; - inputs = attrs any; - setInitInputs = function; - }; + POP.inputs.nixpkgs.follows = ""; + POP.inputs.flake-compat.follows = ""; + yants.url = "github:divnix/yants"; - flakePop = - structAttrs.exporterPop - // structAttrs.inputsExtenderPop - // { - exporters = list types.exporterPop; - inputsExtenders = list types.inputsExtenderPop; - system = string; + haumea.url = "github:nix-community/haumea"; + haumea.inputs.nixpkgs.follows = "nixlib"; - exports = attrs any; - initInputs = attrs any; - inputs = attrs any; - - addInputsExtenders = function; - addInputsExtender = function; - addExporters = function; - addExporter = function; - }; - }; - in { - lib = rec { - deSystemize = import ./de-systemize.nix; # Stolen from standard - mergeToDepth = depth: lhs: rhs: - if depth == 1 - then lhs // rhs - else - lhs - // (mapAttrs ( - n: v: - if isAttrs v - then mergeToDepth (depth - 1) (lhs.${n} or {}) v - else v - ) - rhs); - }; - - types = with (yants "flops"); { - pop = openStruct structAttrs.pop; - exporterPop = openStruct structAttrs.exporterPop; - inputsExtenderPop = openStruct structAttrs.inputsExtenderPop; - flakePop = openStruct structAttrs.flakePop; - }; - - pops = { - inputsExtender = pop { - defaults = { - initInputs = {}; - inputs = {}; - }; - extension = self: super: { - setInitInputs = defun (with types; [(attrs any) inputsExtenderPop]) ( - initInputs: - extendPop self (self: super: { - inherit initInputs; - }) - ); - }; - }; + dmerge.url = "github:divnix/dmerge"; + dmerge.inputs.haumea.follows = "haumea"; + dmerge.inputs.nixlib.follows = "nixlib"; + dmerge.inputs.yants.follows = "yants"; - exporter = pop { - defaults = { - inputs = {}; - exports = {}; - - # If system is empty (unchanged default) then exports will end up being system-spaced - # and exporter will be called for all systems and inputs will be desystemized for each system. - # If system is set to anything else, then exports will not be system-spaced and inputs - # Examples: - # - a packages exporter should leave system as default - # - a nixosConfigurations should set the system to the one its exporting configs for - # - a lib export (with pure nix functions) could set the system to "-" - system = ""; - }; - extension = self: super: { - setInputs = defun (with types; [(attrs any) exporterPop]) ( - inputs: - extendPop self (self: super: { - inherit inputs; - }) - ); - setSystem = defun (with types; [string exporterPop]) ( - system: - extendPop self (self: super: { - inherit system; - }) - ); - }; - }; - - flake = pop { - supers = [ - # Extend both pops and add apis for multiple extenders/exporters - self.pops.exporter - self.pops.inputsExtender - ]; - defaults = { - inputsExtenders = []; - exporters = []; - }; - extension = self: super: { - inputs = let - systemInputs = mapAttrs (_: input: deSystemize self.system input) self.initInputs; - in - foldl (cinputs: extender: mergeToDepth 3 cinputs (extender.setInitInputs systemInputs).inputs) - systemInputs - self.inputsExtenders; - - systemExporters = filter (exporter: exporter.system == "") self.exporters; # will be system-spaced - generalExporters = filter (exporter: exporter.system != "") self.exporters; # not system-spaced, just top-level exports - exports = let - foldExporters = foldl ( - attrs: exporter: - mergeToDepth 2 attrs (exporter.setInputs self.inputs).exports - ) {}; - in { - system = foldExporters self.systemExporters; - general = foldExporters self.generalExporters; - }; - - addInputsExtenders = defun (with types; [(list inputsExtenderPop) flakePop]) ( - inputsExtenders: - extendPop self (self: super: { - inputsExtenders = super.inputsExtenders ++ inputsExtenders; - }) - ); - addInputsExtender = defun (with types; [inputsExtenderPop flakePop]) ( - inputsExtender: - self.addInputsExtenders [inputsExtender] - ); - - addExporters = defun (with types; [(list exporterPop) flakePop]) ( - exporters: - extendPop self (self: super: { - exporters = super.exporters ++ exporters; - }) - ); - addExporter = defun (with types; [exporterPop flakePop]) ( - exporter: - self.addExporters [exporter] - ); - - # Function to call at the end to get exported flake outputs - outputsForSystem = defun (with types; [string (attrs any)]) ( - system: let - inherit (self.setSystem system) exports; - - # Embed system into system-spaced exports - systemSpacedExports = mapAttrs (_: export: {${system} = export;}) exports.system; - in - mergeToDepth 3 systemSpacedExports exports.general - ); - outputsForSystems = defun (with types; [(list string) (attrs any)]) ( - systems: - foldl ( - attrs: system: - mergeToDepth 3 attrs (self.outputsForSystem system) - ) {} - systems - ); - }; - }; - }; - - exampleFlake = { - inputs = { - inherit nixlib POP nixpkgs; - self = self.exampleFlake; + call-flake.url = "github:divnix/call-flake"; + }; + outputs = + { self, ... }@inputs: + let + lib = import ./src/__loader.nix self.inputs; + in + { + inherit lib; + examples = import ./examples/_loader.nix { + inherit inputs; + lib = lib // inputs.nixlib.lib; }; - outputs = inputs: - ( - ( - ( - self.pops.flake.setInitInputs inputs - ) - .addInputsExtenders [ - (POP.lib.extendPop self.pops.inputsExtender (self: super: { - inputs = { - nixlib.lib.func = self.initInputs.nixlib.lib.genAttrs; - }; - })) - ] - ) - .addExporters [ - (POP.lib.extendPop self.pops.exporter (self: _: { - exports.packages.firefox = self.inputs.nixpkgs.legacyPackages.firefox; - })) - ] - ) - .outputsForSystems ["x86_64-linux" "x86_64-darwin"]; }; - }; } diff --git a/local/.github/settings.yml b/local/.github/settings.yml new file mode 100755 index 0000000..a4b9c93 --- /dev/null +++ b/local/.github/settings.yml @@ -0,0 +1,15 @@ +repository: + allow_merge_commit: false + allow_rebase_merge: true + allow_squash_merge: false + default_branch: main + delete_branch_on_merge: true + description: 'A nix language configuration framework based on POP: Pure Object' + has_downloads: false + has_issues: false + has_projects: false + has_wiki: false + homepage: CONFIGURE-ME + name: CONFIGURE-ME + private: true + topics: CONFIGURE-ME diff --git a/local/.gitignore b/local/.gitignore new file mode 100755 index 0000000..bf5da0a --- /dev/null +++ b/local/.gitignore @@ -0,0 +1,22 @@ +.std + +# prj-spec dirs +# +.bin +.cache +.config +.data +.run + +# nixago: ignore-linked-files +/lefthook.yml +/.editorconfig +/.conform.yaml +/treefmt.toml +lefthook.yml +.editorconfig +.conform.yaml +treefmt.toml + +# nixago-auto-created: mdbook-build-folder +docs/build \ No newline at end of file diff --git a/local/cells/repo/configs.nix b/local/cells/repo/configs.nix new file mode 100755 index 0000000..c271fa8 --- /dev/null +++ b/local/cells/repo/configs.nix @@ -0,0 +1,14 @@ +/* This file holds configuration data for repo dotfiles. + + Q: Why not just put the put the file there? + + A: (1) dotfile proliferation + (2) have all the things in one place / fromat + (3) potentially share / re-use configuration data - keeping it in sync +*/ +{ inputs, cell }: +with inputs.std.inputs.dmerge; { + conform.data = { + commit.conventional.scopes = append [ "nixosModules" ]; + }; +} diff --git a/local/cells/repo/devshells.nix b/local/cells/repo/devshells.nix new file mode 100755 index 0000000..815445e --- /dev/null +++ b/local/cells/repo/devshells.nix @@ -0,0 +1,25 @@ +/* This file holds reproducible shells with commands in them. + + They conveniently also generate config files in their startup hook. +*/ +{ inputs, cell }: +let + inherit (inputs.std) lib; +in +{ + # Tool Homepage: https://numtide.github.io/devshell/ + default = lib.dev.mkShell { + name = "flops devshell"; + + # Tool Homepage: https://nix-community.github.io/nixago/ + # This is Standard's devshell integration. + # It runs the startup hook when entering the shell. + nixago = [ + (inputs.std-ext.presets.nixago.conform cell.configs.conform) + (inputs.std-ext.presets.nixago.treefmt) + (inputs.std-ext.presets.nixago.lefthook) + ]; + + commands = [ ]; + }; +} diff --git a/local/flake.lock b/local/flake.lock new file mode 100755 index 0000000..1b93a7c --- /dev/null +++ b/local/flake.lock @@ -0,0 +1,990 @@ +{ + "nodes": { + "POP": { + "inputs": { + "flake-compat": "flake-compat", + "nixlib": "nixlib", + "nixpkgs": [ + "std-ext", + "flops" + ] + }, + "locked": { + "lastModified": 1655410953, + "narHash": "sha256-Er0zdhu7QwpWvVKfauqZqTnxDz6THTWOTVWLoz+Opmw=", + "owner": "divnix", + "repo": "POP", + "rev": "8babe4c9126298d05ebb5ab04727d741b51c022e", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "POP", + "type": "github" + } + }, + "blank": { + "locked": { + "lastModified": 1625557891, + "narHash": "sha256-O8/MWsPBGhhyPoPLHZAuoZiiHo9q6FLlEeIDEXuj6T4=", + "owner": "divnix", + "repo": "blank", + "rev": "5a5d2684073d9f563072ed07c871d577a6c614a8", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "blank", + "type": "github" + } + }, + "call-flake": { + "locked": { + "lastModified": 1691284812, + "narHash": "sha256-bmhE1TmrJG4ba93l9WQTLuYM53kwGQAjYHRvHOeuxWU=", + "owner": "divnix", + "repo": "call-flake", + "rev": "0510cb1562720ae66cb5010c56b856142b837a3f", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "call-flake", + "type": "github" + } + }, + "call-flake_2": { + "locked": { + "lastModified": 1689473344, + "narHash": "sha256-bmhE1TmrJG4ba93l9WQTLuYM53kwGQAjYHRvHOeuxWU=", + "owner": "divnix", + "repo": "call-flake", + "rev": "a07e91d3fb59eb9f7ec706a151e1a7b36a1e8727", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "call-flake", + "type": "github" + } + }, + "call-flake_3": { + "locked": { + "lastModified": 1687380775, + "narHash": "sha256-bmhE1TmrJG4ba93l9WQTLuYM53kwGQAjYHRvHOeuxWU=", + "owner": "divnix", + "repo": "call-flake", + "rev": "74061f6c241227cd05e79b702db9a300a2e4131a", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "call-flake", + "type": "github" + } + }, + "cortex": { + "flake": false, + "locked": { + "lastModified": 1643528409, + "narHash": "sha256-ldmenmCzCEuuBlMtaQYe79vYbcTORgkCXgYgGkOzkL8=", + "owner": "jethrokuan", + "repo": "cortex", + "rev": "ad9a963534e5be323a33eaf0f9aa3e914cca8093", + "type": "github" + }, + "original": { + "owner": "jethrokuan", + "repo": "cortex", + "type": "github" + } + }, + "devshell": { + "inputs": { + "nixpkgs": "nixpkgs", + "systems": "systems" + }, + "locked": { + "lastModified": 1692793255, + "narHash": "sha256-yVyj0AE280JkccDHuG1XO9oGxN6bW8ksr/xttXcXzK0=", + "owner": "numtide", + "repo": "devshell", + "rev": "2aa26972b951bc05c3632d4e5ae683cb6771a7c6", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "dmerge": { + "inputs": { + "haumea": [ + "std-ext", + "flops", + "haumea" + ], + "nixlib": [ + "std-ext", + "flops", + "nixlib" + ], + "yants": [ + "std-ext", + "flops", + "yants" + ] + }, + "locked": { + "lastModified": 1686862774, + "narHash": "sha256-ojGtRQ9pIOUrxsQEuEPerUkqIJEuod9hIflfNkY+9CE=", + "owner": "divnix", + "repo": "dmerge", + "rev": "9f7f7a8349d33d7bd02e0f2b484b1f076e503a96", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "dmerge", + "type": "github" + } + }, + "dmerge_2": { + "inputs": { + "haumea": [ + "std-ext", + "std", + "haumea" + ], + "nixlib": [ + "std-ext", + "std", + "lib" + ], + "yants": [ + "std-ext", + "std", + "yants" + ] + }, + "locked": { + "lastModified": 1686862774, + "narHash": "sha256-ojGtRQ9pIOUrxsQEuEPerUkqIJEuod9hIflfNkY+9CE=", + "owner": "divnix", + "repo": "dmerge", + "rev": "9f7f7a8349d33d7bd02e0f2b484b1f076e503a96", + "type": "github" + }, + "original": { + "owner": "divnix", + "ref": "0.2.1", + "repo": "dmerge", + "type": "github" + } + }, + "emacs-overlay": { + "inputs": { + "flake-utils": "flake-utils_6", + "nixpkgs": "nixpkgs_4", + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1690483432, + "narHash": "sha256-o4/IGadFvyT68byD+NglNK+zykMMjglXdsCSL63OJLc=", + "owner": "nix-community", + "repo": "emacs-overlay", + "rev": "01c076bb6f9fd34630f4c87cfab18ea4e85ef819", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "emacs-overlay", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1650374568, + "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "b4a34015c698c7793d592d66adbab377907a2be8", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1653893745, + "narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1653893745, + "narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "locked": { + "lastModified": 1653893745, + "narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_4": { + "locked": { + "lastModified": 1653893745, + "narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_5": { + "locked": { + "lastModified": 1653893745, + "narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_6": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1689068808, + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_7": { + "inputs": { + "systems": "systems_3" + }, + "locked": { + "lastModified": 1689068808, + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flops": { + "inputs": { + "POP": "POP", + "call-flake": "call-flake_2", + "dmerge": "dmerge", + "haumea": "haumea", + "nixlib": "nixlib_2", + "yants": "yants" + }, + "locked": { + "lastModified": 1694677528, + "narHash": "sha256-j29810CVcDZGPkm1EeBn0hfeOt2kfpLYhXrDjI02eL0=", + "owner": "gtrunsec", + "repo": "flops", + "rev": "1004a97ea0c3960d162d2b13e862b347191e3ba9", + "type": "github" + }, + "original": { + "owner": "gtrunsec", + "repo": "flops", + "type": "github" + } + }, + "haumea": { + "inputs": { + "nixpkgs": [ + "std-ext", + "flops", + "nixlib" + ] + }, + "locked": { + "lastModified": 1689557889, + "narHash": "sha256-kllmt6JnHlry+WAASdSMDaRwbiuk2dFhkbW3Qz1w8BU=", + "owner": "nix-community", + "repo": "haumea", + "rev": "d6a9593ff2160ce29bf6d905e9ccbcecd66baeef", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "haumea", + "type": "github" + } + }, + "haumea_2": { + "inputs": { + "nixpkgs": "nixpkgs_5" + }, + "locked": { + "lastModified": 1685133229, + "narHash": "sha256-FePm/Gi9PBSNwiDFq3N+DWdfxFq0UKsVVTJS3cQPn94=", + "owner": "nix-community", + "repo": "haumea", + "rev": "34dd58385092a23018748b50f9b23de6266dffc2", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "v0.2.2", + "repo": "haumea", + "type": "github" + } + }, + "incl": { + "inputs": { + "nixlib": [ + "std-ext", + "std", + "lib" + ] + }, + "locked": { + "lastModified": 1669263024, + "narHash": "sha256-E/+23NKtxAqYG/0ydYgxlgarKnxmDbg6rCMWnOBqn9Q=", + "owner": "divnix", + "repo": "incl", + "rev": "ce7bebaee048e4cd7ebdb4cee7885e00c4e2abca", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "incl", + "type": "github" + } + }, + "lib": { + "locked": { + "lastModified": 1694306727, + "narHash": "sha256-26fkTOJOI65NOTNKFvtcJF9mzzf/kK9swHzfYt1Dl6Q=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "c30b6a84c0b84ec7aecbe74466033facc9ed103f", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nix-filter": { + "locked": { + "lastModified": 1687178632, + "narHash": "sha256-HS7YR5erss0JCaUijPeyg2XrisEb959FIct3n2TMGbE=", + "owner": "numtide", + "repo": "nix-filter", + "rev": "d90c75e8319d0dd9be67d933d8eb9d0894ec9174", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "nix-filter", + "type": "github" + } + }, + "nixago": { + "inputs": { + "flake-utils": "flake-utils", + "nixago-exts": "nixago-exts", + "nixpkgs": [ + "std-ext", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1687381756, + "narHash": "sha256-IUMIlYfrvj7Yli4H2vvyig8HEPpfCeMaE6+kBGPzFyk=", + "owner": "nix-community", + "repo": "nixago", + "rev": "dacceb10cace103b3e66552ec9719fa0d33c0dc9", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixago", + "type": "github" + } + }, + "nixago-exts": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixago": "nixago_2", + "nixpkgs": [ + "std-ext", + "nixago", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1676070308, + "narHash": "sha256-QaJ65oc2l8iwQIGWUJ0EKjCeSuuCM/LqR8RauxZUUkc=", + "owner": "nix-community", + "repo": "nixago-extensions", + "rev": "e5380cb0456f4ea3c86cf94e3039eb856bf07d0b", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixago-extensions", + "type": "github" + } + }, + "nixago-exts_2": { + "inputs": { + "flake-utils": "flake-utils_4", + "nixago": "nixago_3", + "nixpkgs": [ + "std-ext", + "nixago", + "nixago-exts", + "nixago", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1655508669, + "narHash": "sha256-BDDdo5dZQMmwNH/GNacy33nPBnCpSIydWFPZs0kkj/g=", + "owner": "nix-community", + "repo": "nixago-extensions", + "rev": "3022a932ce109258482ecc6568c163e8d0b426aa", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixago-extensions", + "type": "github" + } + }, + "nixago_2": { + "inputs": { + "flake-utils": "flake-utils_3", + "nixago-exts": "nixago-exts_2", + "nixpkgs": [ + "std-ext", + "nixago", + "nixago-exts", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1676070010, + "narHash": "sha256-iYzJIWptE1EUD8VINAg66AAMUajizg8JUYN3oBmb8no=", + "owner": "nix-community", + "repo": "nixago", + "rev": "d480ba6c0c16e2c5c0bd2122852d6a0c9ad1ed0e", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "rename-config-data", + "repo": "nixago", + "type": "github" + } + }, + "nixago_3": { + "inputs": { + "flake-utils": "flake-utils_5", + "nixpkgs": [ + "std-ext", + "nixago", + "nixago-exts", + "nixago", + "nixago-exts", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1655405483, + "narHash": "sha256-Crd49aZWNrpczlRTOwWGfwBMsTUoG9vlHDKQC7cx264=", + "owner": "nix-community", + "repo": "nixago", + "rev": "e6a9566c18063db5b120e69e048d3627414e327d", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixago", + "type": "github" + } + }, + "nixlib": { + "locked": { + "lastModified": 1653180592, + "narHash": "sha256-sVGwmxTj7CY1D4ioy7E+iJE+1/yHqQlxjnTpar3ap/E=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "42c5f5785b70cd64b4afd830dc31d0b08461abd5", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixlib_2": { + "locked": { + "lastModified": 1689469483, + "narHash": "sha256-2SBhY7rZQ/iNCxe04Eqxlz9YK9KgbaTMBssq3/BgdWY=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "02fea408f27186f139153e1ae88f8ab2abd9c22c", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1677383253, + "narHash": "sha256-UfpzWfSxkfXHnb4boXZNaKsAcUrZT9Hw+tao1oZxd08=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9952d6bc395f5841262b006fbace8dd7e143b634", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1690370995, + "narHash": "sha256-9z//23jGegLJrf3ITStLwVf715O39dq5u48Kr/XW14U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f3fbbc36b4e179a5985b9ab12624e9dfe7989341", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1660438583, + "narHash": "sha256-rJUTYxFKlWUJI3njAwEc1pKAVooAViZGJvsgqfh/q/E=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "bbd8f7cd87d0b29294ef3072ffdbd61d60f05da4", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1692190437, + "narHash": "sha256-yJUZzmzSmDYb9ONPnMQDru66RjZgGQZRvj3tQebkexk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9b2aa98db6b10503666a50f4eb93b2fc0d57bde5", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_4": { + "locked": { + "lastModified": 1690272529, + "narHash": "sha256-MakzcKXEdv/I4qJUtq/k/eG+rVmyOZLnYNC2w1mB59Y=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ef99fa5c5ed624460217c31ac4271cfb5cb2502c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_5": { + "locked": { + "lastModified": 1681001314, + "narHash": "sha256-5sDnCLdrKZqxLPK4KA8+f4A3YKO/u6ElpMILvX0g72c=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "367c0e1086a4eb4502b24d872cea2c7acdd557f4", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nosys": { + "locked": { + "lastModified": 1668010795, + "narHash": "sha256-JBDVBnos8g0toU7EhIIqQ1If5m/nyBqtHhL3sicdPwI=", + "owner": "divnix", + "repo": "nosys", + "rev": "feade0141487801c71ff55623b421ed535dbdefa", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "nosys", + "type": "github" + } + }, + "org-roam-book-template": { + "inputs": { + "cortex": "cortex", + "emacs-overlay": "emacs-overlay", + "flake-utils": "flake-utils_7", + "nix-filter": "nix-filter", + "nixpkgs": [ + "std-ext", + "nixpkgs" + ], + "ox-hugo": "ox-hugo" + }, + "locked": { + "lastModified": 1690491859, + "narHash": "sha256-m50lZ8IU04pBsFaRvGmrUB47an3dGm2vRZPJ56yB49Y=", + "owner": "gtrunsec", + "repo": "org-roam-book-template", + "rev": "e866a31a36ce3f8673c08f5d1053646c3aa8acc8", + "type": "github" + }, + "original": { + "owner": "gtrunsec", + "repo": "org-roam-book-template", + "type": "github" + } + }, + "ox-hugo": { + "flake": false, + "locked": { + "lastModified": 1689004512, + "narHash": "sha256-eMS2aR9DZMN/t5bt31Jsi8a2pCqKopQKjqXbNl6VHKY=", + "owner": "kaushalmodi", + "repo": "ox-hugo", + "rev": "cb1b6cfd7b080e889352150416c1725f11ba937a", + "type": "github" + }, + "original": { + "owner": "kaushalmodi", + "repo": "ox-hugo", + "type": "github" + } + }, + "paisano": { + "inputs": { + "call-flake": "call-flake_3", + "nixpkgs": [ + "std-ext", + "std", + "nixpkgs" + ], + "nosys": "nosys", + "yants": [ + "std-ext", + "std", + "yants" + ] + }, + "locked": { + "lastModified": 1693982790, + "narHash": "sha256-WTZYlqGUjzzz/PSzcvjEZz2kkwYSXObjeQVrFBaqa2Y=", + "owner": "paisano-nix", + "repo": "core", + "rev": "3e897a19418361ece34841105122ed4f9379ca96", + "type": "github" + }, + "original": { + "owner": "paisano-nix", + "repo": "core", + "type": "github" + } + }, + "paisano-tui": { + "flake": false, + "locked": { + "lastModified": 1694014205, + "narHash": "sha256-u0+T6vMznzfjDMUd01ZXQsrQPMEhMjrQwUPTFsPBR1k=", + "owner": "paisano-nix", + "repo": "tui", + "rev": "587ab9fd07bd969d59df73bfe527b5f8a4e752d1", + "type": "github" + }, + "original": { + "owner": "paisano-nix", + "ref": "0.2.0", + "repo": "tui", + "type": "github" + } + }, + "root": { + "inputs": { + "call-flake": "call-flake", + "namaka": [], + "nixpkgs": [ + "std-ext", + "nixpkgs" + ], + "std": [ + "std-ext", + "std" + ], + "std-ext": "std-ext" + } + }, + "std": { + "inputs": { + "arion": [ + "std-ext", + "std", + "blank" + ], + "blank": "blank", + "devshell": [ + "std-ext", + "devshell" + ], + "dmerge": "dmerge_2", + "haumea": "haumea_2", + "incl": "incl", + "lib": "lib", + "makes": [ + "std-ext", + "std", + "blank" + ], + "microvm": [ + "std-ext", + "std", + "blank" + ], + "n2c": [ + "std-ext", + "std", + "blank" + ], + "nixago": [ + "std-ext", + "nixago" + ], + "nixpkgs": [ + "std-ext", + "nixpkgs" + ], + "paisano": "paisano", + "paisano-tui": "paisano-tui", + "terranix": [ + "std-ext", + "std", + "blank" + ], + "yants": "yants_2" + }, + "locked": { + "lastModified": 1694795560, + "narHash": "sha256-zRSBVfgWMqOuLg74pQKiZv5Jz34lXVlg9rnHolBtB9s=", + "owner": "divnix", + "repo": "std", + "rev": "927807fc745e158b05b8c7daa733b9412a6322f2", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "std", + "type": "github" + } + }, + "std-ext": { + "inputs": { + "devshell": "devshell", + "flops": "flops", + "nixago": "nixago", + "nixpkgs": "nixpkgs_3", + "org-roam-book-template": "org-roam-book-template", + "std": "std" + }, + "locked": { + "lastModified": 1694809007, + "narHash": "sha256-roWdj2iGzoY9Pq8AMtfkhpd56aRjELmUEteD3Dk6e/o=", + "owner": "gtrunsec", + "repo": "std-ext", + "rev": "93b5aec9c0d42e2d0dd1ecc76cbbe741b136f6e9", + "type": "github" + }, + "original": { + "owner": "gtrunsec", + "repo": "std-ext", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "yants": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1686863218, + "narHash": "sha256-kooxYm3/3ornWtVBNHM3Zh020gACUyFX2G0VQXnB+mk=", + "owner": "divnix", + "repo": "yants", + "rev": "8f0da0dba57149676aa4817ec0c880fbde7a648d", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "yants", + "type": "github" + } + }, + "yants_2": { + "inputs": { + "nixpkgs": [ + "std-ext", + "std", + "haumea", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1686863218, + "narHash": "sha256-kooxYm3/3ornWtVBNHM3Zh020gACUyFX2G0VQXnB+mk=", + "owner": "divnix", + "repo": "yants", + "rev": "8f0da0dba57149676aa4817ec0c880fbde7a648d", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "yants", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/local/flake.nix b/local/flake.nix new file mode 100755 index 0000000..f5bac9e --- /dev/null +++ b/local/flake.nix @@ -0,0 +1,40 @@ +{ + description = "Flops"; + + inputs.std.follows = "std-ext/std"; + inputs.nixpkgs.follows = "std-ext/nixpkgs"; + inputs.std-ext.url = "github:gtrunsec/std-ext"; + inputs.call-flake.url = "github:divnix/call-flake"; + inputs.namaka.follows = ""; + + outputs = + { std, ... }@inputs: + let + main = inputs.call-flake ../.; + in + std.growOn + { + inherit inputs; + cellsFrom = ./cells; + cellBlocks = with std.blockTypes; [ + # Development Environments + (nixago "configs") + (devshells "devshells") + ]; + } + { + devShells = std.harvest inputs.self [ [ + "repo" + "devshells" + ] ]; + } + { + checks = inputs.namaka.lib.load { + src = ../tests; + inputs = main.lib // { + inherit (main) inputs; + lib = main.inputs.nixlib.lib // main.lib; + }; + }; + }; +} diff --git a/namaka.toml b/namaka.toml new file mode 100644 index 0000000..a95d85c --- /dev/null +++ b/namaka.toml @@ -0,0 +1,20 @@ +[check] +cmd = [ + "nix", + "flake", + "check", + "./local", + "--override-input", + "namaka", + "github:nix-community/namaka" +] + +[eval] +cmd = [ + "nix", + "eval", + "./local#checks", + "--override-input", + "namaka", + "github:nix-community/namaka" +] diff --git a/src/__lib/__lock/flake.lock b/src/__lib/__lock/flake.lock new file mode 100644 index 0000000..8b3e9e2 --- /dev/null +++ b/src/__lib/__lock/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "call-flake": { + "locked": { + "lastModified": 1686448809, + "narHash": "sha256-Cc+Krf2Ar5NjFMxUWaJFOAQkj8s40r6iEJwIfbxa0Vc=", + "owner": "divnix", + "repo": "call-flake", + "rev": "a0b97f9c6d21997fe5f1ff9a5eedc05a7935a917", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "call-flake", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1686890976, + "narHash": "sha256-/PpdA67EEsOQafiS3snVbQ0uCfu/ZmcB5mkGjrXlvmo=", + "owner": "gtrunsec", + "repo": "flake-compat", + "rev": "eba2496406651535078e89b4b2dae1d9adef6b37", + "type": "github" + }, + "original": { + "owner": "gtrunsec", + "ref": "lockFile", + "repo": "flake-compat", + "type": "github" + } + }, + "nosys": { + "locked": { + "lastModified": 1683048500, + "narHash": "sha256-jSCjAy+MEbZZ7Iv92iVJeLuwm90J83RouXFOPSxr05g=", + "owner": "divnix", + "repo": "nosys", + "rev": "52ff559e63d4d8e2a3a0cfbc50a7b2a4361d9101", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "nosys", + "type": "github" + } + }, + "root": { + "inputs": { + "call-flake": "call-flake", + "flake-compat": "flake-compat", + "nosys": "nosys" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/src/__lib/__lock/flake.nix b/src/__lib/__lock/flake.nix new file mode 100644 index 0000000..2417793 --- /dev/null +++ b/src/__lib/__lock/flake.nix @@ -0,0 +1,11 @@ +{ + inputs = { + nosys.url = "github:divnix/nosys"; + flake-compat = { + url = "github:gtrunsec/flake-compat/lockFile"; + flake = false; + }; + call-flake.url = "github:divnix/call-flake"; + }; + outputs = _: { }; +} diff --git a/src/__lib/call-flake-override.nix b/src/__lib/call-flake-override.nix new file mode 100644 index 0000000..8f1215b --- /dev/null +++ b/src/__lib/call-flake-override.nix @@ -0,0 +1,10 @@ +{ lib }: +let + lock = builtins.fromJSON (builtins.readFile ./__lock/flake.lock); + flake-compat = builtins.fetchTarball { + url = "https://github.com/gtrunsec/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + }; +in +src: override-inputs: +(import "${flake-compat}" { inherit src override-inputs; }).defaultNix.inputs diff --git a/src/__lib/concatMapAttrsWith.nix b/src/__lib/concatMapAttrsWith.nix new file mode 100644 index 0000000..0350025 --- /dev/null +++ b/src/__lib/concatMapAttrsWith.nix @@ -0,0 +1,23 @@ +{ lib }: +# map each attribute in the given set into +# a list of attributes and subsequently merge them into +# a new attribute set with the specified mergeFun. +# Type: ({ ... } -> { ... } -> { ... }) -> (String -> a -> { ... }) -> { ... } -> { ... } +# Example: +# concatMapAttrsWith (mergeAttrsButConcatOn "mykey") +# (name: value: { +# ${name} = value; +# ${key} = value ++ value; +# }) +# { x = "a"; y = "b"; } +# => { x = "a"; y = "b"; mykey = [ "aa" "bb"]; } +let + inherit (builtins) attrValues foldl' mapAttrs; + inherit (lib) flip pipe; +in +merge: f: +flip pipe [ + (mapAttrs f) + attrValues + (foldl' merge { }) +] diff --git a/src/__lib/deSystemize.nix b/src/__lib/deSystemize.nix new file mode 100644 index 0000000..3deb111 --- /dev/null +++ b/src/__lib/deSystemize.nix @@ -0,0 +1,26 @@ +{ lib }: +let + l = lib // builtins; + /* A helper function which hides the complexities of dealing + with 'system' properly from you, while still providing + escape hatches when dealing with cross-compilation. + + You can use this function independently of the rest of std. + */ + deSystemize = + let + iteration = + cutoff: system: fragment: + if !(l.isAttrs fragment) || cutoff == 0 then + fragment + else if l.hasAttr "${system}" fragment && !l.isFunction fragment.${system} then + fragment // fragment.${system} + else if l.hasAttr "${system}" fragment && l.isFunction fragment.${system} then + fragment // { __functor = _: fragment.${system}; } + else + l.mapAttrs (_: iteration (cutoff - 1) system) fragment + ; + in + iteration 3; +in +deSystemize diff --git a/src/__lib/mergeToDepth.nix b/src/__lib/mergeToDepth.nix new file mode 100644 index 0000000..a425f55 --- /dev/null +++ b/src/__lib/mergeToDepth.nix @@ -0,0 +1,17 @@ +{ lib, root }: +let + inherit (lib) mapAttrs isAttrs; + + mergeToDepth = + depth: lhs: rhs: + if depth == 1 then + lhs // rhs + else + lhs + // (mapAttrs + (n: v: if isAttrs v then mergeToDepth (depth - 1) (lhs.${n} or { }) v else v) + rhs + ) + ; +in +mergeToDepth diff --git a/src/__lib/recursiveMerge.nix b/src/__lib/recursiveMerge.nix new file mode 100644 index 0000000..9290135 --- /dev/null +++ b/src/__lib/recursiveMerge.nix @@ -0,0 +1,21 @@ +{ lib }: +let + l = lib // builtins; +in +attrList: +let + f = + attrPath: + builtins.zipAttrsWith ( + n: values: + if l.tail values == [ ] then + l.head values + else if l.all l.isList values then + l.unique (l.concatLists values) + else if l.all l.isAttrs values then + f [ n ] values + else + l.last values + ); +in +f [ ] attrList diff --git a/src/__lib/removeAttrsFromDepth.nix b/src/__lib/removeAttrsFromDepth.nix new file mode 100644 index 0000000..417aa5c --- /dev/null +++ b/src/__lib/removeAttrsFromDepth.nix @@ -0,0 +1,18 @@ +{ lib, super }: +from: +let + inherit (lib) recursiveUpdate; + inherit (super) concatMapAttrsWith; + + getPath = l: n: lib.elemAt l n; +in +cursor: +concatMapAttrsWith recursiveUpdate ( + file: value: + if file == getPath from 0 && lib.length from == 1 then + { } + else if file == getPath from 0 && (lib.hasAttr (getPath from 1) value) then + { ${file} = removeAttrs value [ (getPath from 1) ]; } + else + { ${file} = value; } +) diff --git a/src/__loader.nix b/src/__loader.nix new file mode 100644 index 0000000..9d6d8da --- /dev/null +++ b/src/__loader.nix @@ -0,0 +1,17 @@ +inputs': +let + selfLib = inputs.haumea.lib.load { + src = ./__lib; + inputs = { + lib = inputs.nixlib.lib; + }; + }; + inputs = inputs' // { + lib = inputs.nixlib.lib // selfLib; + }; +in +selfLib +// inputs.haumea.lib.load { + src = ./.; + inherit inputs; +} diff --git a/src/configs/pops.nix b/src/configs/pops.nix new file mode 100644 index 0000000..4d8b83e --- /dev/null +++ b/src/configs/pops.nix @@ -0,0 +1,111 @@ +{ + root, + POP, + lib, + yants, + haumea, + self, +}: +let + types = root.types // yants; + inherit (POP.lib) pop extendPop; + inherit (root) pops; + inherit (yants) defun; + inherit (lib) + mapAttrs + mergeToDepth + foldl + filter + deSystemize + ; +in +{ + recipesExtender = pop { + defaults = { + recipes = { }; + initRecipes = { }; + }; + extension = self: super: { + setInitRecipes = + (initRecipes: extendPop self (self: super: { inherit initRecipes; })); + }; + }; + + argsExtender = pop { + defaults = { + args = { }; + argsExtenders = [ ]; + }; + extension = self: super: { + args = foldl (args: extender: args // extender) { } self.argsExtenders; + + addArgsExtenders = + ( + argsExtenders: + extendPop self ( + self: super: { argsExtenders = super.argsExtenders ++ argsExtenders; } + ) + ); + addArgsExtender = (argsExtender: self.addArgsExtenders [ argsExtender ]); + }; + }; + + exporter = pop { + defaults = { + recipes = { }; + args = { }; + exports = { }; + }; + extension = self: super: { + setRecipes = (recipes: extendPop self (self: super: { inherit recipes; })); + setArgs = (args: extendPop self (self: super: { inherit args; })); + addExporters = + ( + exporters: + extendPop self (self: super: { exporters = super.exporters ++ exporters; }) + ); + addExporter = (exporter: self.addExporters [ exporter ]); + }; + }; + + default = pop { + supers = [ + self.recipesExtender + self.argsExtender + self.exporter + ]; + defaults = { + recipesExtenders = [ ]; + exporters = [ ]; + }; + extension = self: super: { + recipes = + foldl (attrs: extender: attrs // extender) self.initRecipes + self.recipesExtenders; + + addRecipesExtenders = + ( + recipesExtenders: + extendPop self ( + self: super: { recipesExtenders = super.recipesExtenders ++ recipesExtenders; } + ) + ); + + addRecipesExtender = + (recipesExtender: self.addRecipesExtenders [ recipesExtender ]); + + exports = + foldl + ( + attrs: exporter: + if self.args != { } then + mergeToDepth 2 attrs + ((exporter.setRecipes self.recipes).setArgs self.args).exports + else + mergeToDepth 2 attrs (exporter.setRecipes self.recipes).exports + ) + { } + self.exporters; + }; + }; +} diff --git a/src/configs/structAttrs.nix b/src/configs/structAttrs.nix new file mode 100644 index 0000000..af9e8b7 --- /dev/null +++ b/src/configs/structAttrs.nix @@ -0,0 +1,19 @@ +{ yants, root }: +let + types = root.configs.types // yants; + + structAttrs = with yants; { + pop = { + __meta__ = option ( + struct "__meta__" { + name = string; + supers = list types.pop; + defaults = attrs any; + extension = function; + precedenceList = list (attrs any); + } + ); + }; + }; +in +structAttrs diff --git a/src/configs/types.nix b/src/configs/types.nix new file mode 100644 index 0000000..c0187ec --- /dev/null +++ b/src/configs/types.nix @@ -0,0 +1,4 @@ +{ yants, root }: +with (yants "configs"); { + pop = openStruct root.configs.structAttrs.pop; +} diff --git a/src/flake/pops.nix b/src/flake/pops.nix new file mode 100644 index 0000000..4b0224e --- /dev/null +++ b/src/flake/pops.nix @@ -0,0 +1,254 @@ +{ + root, + POP, + lib, + yants, + self, + call-flake, +}: +let + types = root.flake.types // yants; + inherit (POP.lib) pop extendPop; + trace = t: (lib.trace t) t; + inherit (yants) defun; + inherit (lib) + mapAttrs + mergeToDepth + foldl + filter + call-flake-override + ; + + __inputs__ = (call-flake ../__lib/__lock).inputs; +in +{ + inputsExtender = pop { + defaults = { + initInputs = { }; + inputs = { }; + sysInputs = { }; + overrideInputs = { }; + }; + extension = self: super: { + setInitInputs = + ( + initInputs: + extendPop self ( + self: super: { + initInputs = + if (lib.isPath initInputs || lib.isString initInputs) then + call-flake-override initInputs self.overrideInputs + else if lib.hasAttr "outPath" initInputs then + call-flake-override initInputs.outPath self.overrideInputs + else + initInputs + ; + } + ) + ); + setOverrideInputs = + (overrideInputs: extendPop self (self: super: { inherit overrideInputs; })); + }; + }; + + exporter = pop { + defaults = { + inputs = { }; + exports = { }; + # If system is empty (unchanged default) then exports will end up being system-spaced + # and exporter will be called for all systems and inputs will be desystemized for each system. + # If system is set to anything else, then exports will not be system-spaced and inputs + # Examples: + # - a packages exporter should leave system as default + # - a nixosConfigurations should set the system to the one its exporting configs for + # - a lib export (with pure nix functions) could set the system to "-" + system = ""; + }; + extension = self: super: { + setInputs = + defun + ( + with types; [ + (attrs any) + exporterPop + ] + ) + (inputs: extendPop self (self: super: { inherit inputs; })); + setSystem = + defun + ( + with types; [ + string + exporterPop + ] + ) + (system: extendPop self (self: super: { inherit system; })); + }; + }; + + default = pop { + supers = [ + # Extend both pops and add apis for multiple extenders/exporters + self.exporter + self.inputsExtender + ]; + defaults = { + inputsExtenders = [ ]; + inputsOverrideExtenders = [ ]; + exporters = [ ]; + }; + extension = + self: super: + let + deSysInputs = + mapAttrs (_: input: __inputs__.nosys.lib.deSys self.system input) + extendedInputs; + + extendedInputs = + foldl + ( + cinputs: extender: + let + ext' = extender.setInitInputs self.initInputs; + in + mergeToDepth 3 cinputs ext'.inputs + ) + self.initInputs + self.inputsExtenders; + in + { + overrideInputs = + foldl + ( + acc: ext: + let + ext' = ext.setInitInputs extendedInputs; + in + acc // ext'.overrideInputs + ) + { } + self.inputsOverrideExtenders; + + sysInputs = extendedInputs; + + inputs = deSysInputs; + + systemExporters = filter (exporter: exporter.system == "") self.exporters; # will be system-spaced + generalExporters = filter (exporter: exporter.system != "") self.exporters; # not system-spaced, just top-level exports + + exports = + let + foldExporters = + foldl + (attrs: exporter: mergeToDepth 2 attrs (exporter.setInputs self.inputs).exports) + { }; + in + { + system = foldExporters self.systemExporters; + general = foldExporters self.generalExporters; + }; + + addInputsOverrideExtenders = + ( + inputsOverrideExtenders: + extendPop self ( + self: super: { + inputsOverrideExtenders = + super.inputsOverrideExtenders ++ inputsOverrideExtenders; + } + ) + ); + + addInputsOverrideExtender = + ( + inputsOverrideExtender: + self.addInputsOverrideExtenders [ inputsOverrideExtender ] + ); + + addInputsExtenders = + defun + ( + with types; [ + (list inputsExtenderPop) + flakePop + ] + ) + ( + inputsExtenders: + extendPop self ( + self: super: { inputsExtenders = super.inputsExtenders ++ inputsExtenders; } + ) + ); + + addInputsExtender = + defun + ( + with types; [ + inputsExtenderPop + flakePop + ] + ) + (inputsExtender: self.addInputsExtenders [ inputsExtender ]); + + addExporters = + defun + ( + with types; [ + (list exporterPop) + flakePop + ] + ) + ( + exporters: + extendPop self (self: super: { exporters = super.exporters ++ exporters; }) + ); + + addExporter = + defun + ( + with types; [ + exporterPop + flakePop + ] + ) + (exporter: self.addExporters [ exporter ]); + + # Function to call at the end to get exported flake outputs + outputsForSystem = + defun + ( + with types; [ + string + (attrs any) + ] + ) + ( + system: + let + inherit (self.setSystem system) exports; + # Embed system into system-spaced exports + systemSpacedExports = + mapAttrs (_: export: { ${system} = export; }) + exports.system; + in + mergeToDepth 3 systemSpacedExports exports.general + ); + + outputsForSystems = + defun + ( + with types; [ + (list string) + (attrs any) + ] + ) + ( + systems: + foldl (attrs: system: mergeToDepth 3 attrs (self.outputsForSystem system)) { } + systems + ); + + outputs = self.inputs; + }; + }; +} diff --git a/src/flake/structAttrs.nix b/src/flake/structAttrs.nix new file mode 100644 index 0000000..0ea8f35 --- /dev/null +++ b/src/flake/structAttrs.nix @@ -0,0 +1,52 @@ +{ yants, root }: +let + types = root.flake.types // yants; + structAttrs = with yants; { + pop = { + __meta__ = option ( + struct "__meta__" { + name = string; + supers = list types.pop; + defaults = attrs any; + extension = function; + precedenceList = list (attrs any); + } + ); + }; + + exporterPop = structAttrs.pop // { + inputs = attrs any; + exports = attrs any; + setInputs = function; + setSystem = function; + }; + + inputsExtenderPop = structAttrs.pop // { + initInputs = attrs any; + inputs = attrs any; + setInitInputs = function; + }; + + flakePop = + structAttrs.exporterPop + // structAttrs.inputsExtenderPop + // { + exporters = list types.exporterPop; + inputsExtenders = list types.inputsExtenderPop; + system = string; + + exports = attrs any; + initInputs = attrs any; + inputs = attrs any; + # without deSystemize + sysInputs = attrs any; + + addInputsExtenders = function; + addInputsExtender = function; + addExporters = function; + addExporter = function; + } + ; + }; +in +structAttrs diff --git a/src/flake/types.nix b/src/flake/types.nix new file mode 100644 index 0000000..c665f9f --- /dev/null +++ b/src/flake/types.nix @@ -0,0 +1,7 @@ +{ yants, root }: +with (yants "flops"); { + pop = openStruct root.flake.structAttrs.pop; + exporterPop = openStruct root.flake.structAttrs.exporterPop; + inputsExtenderPop = openStruct root.flake.structAttrs.inputsExtenderPop; + flakePop = openStruct root.flake.structAttrs.flakePop; +} diff --git a/src/haumea/nixosModules.nix b/src/haumea/nixosModules.nix new file mode 100644 index 0000000..4b06b9a --- /dev/null +++ b/src/haumea/nixosModules.nix @@ -0,0 +1,177 @@ +{ + haumea, + lib, + dmerge, +}: +{ cfg }: +let + l = lib // builtins; + trace = x: l.trace x x; + inherit (builtins) mapAttrs; + inherit (lib) functionArgs pipe toFunction; + + lazyArgsPerParameter = + f: inputs: + pipe f [ + functionArgs + (mapAttrs (name: _: inputs.${name})) + f + ]; + callModuleLazily = + inputs: path: + let + importer = l.scopedImport inputs; + f = toFunction (importer path); + in + lazyArgsPerParameter f inputs; + removeFileSuffix = l.removeSuffix ".nix"; + removeDefault = l.removeSuffix "/default"; + relModulePathWithoutDefault = + path: + (l.drop 1 ( + l.splitString "/" ( + removeDefault ( + removeFileSuffix (l.last (l.splitString cfg.src (toString path))) + ) + ) + )); + + isEvalModule = l.elem cfg.type [ + "nixosModules" + "evalModules" + ]; + + base = + { + extenders ? [ ], + }: + haumea.lib.load { + inherit (cfg) src inputs; + loader = + inputs: path: + ( + let + module = + { + config ? { }, + options ? { }, + ... + }@args: + let + mkModulePath = + attrs': l.setAttrByPath (relModulePathWithoutDefault path) attrs'; + test = config._module.args.pkgs or { }; + baseModuleArgs = + ( + inputs + // args + // ( + { + cfg = l.attrByPath (relModulePathWithoutDefault path) { } config; + opt = l.attrByPath (relModulePathWithoutDefault path) { } options; + inherit mkModulePath; + moduleArgs = config._module.args // config._module.specialArgs; + } + // + l.optionalAttrs + (l.elem cfg.type [ + "nixosModules" + "nixosProfiles" + ]) + { pkgs = config._module.args.pkgs; } + ) + ); + + moduleArgs = baseModuleArgs // { + loadSubmodule = + path: (mkExtenders (builtins.scopedImport baseModuleArgs path) path); + }; + + callArgsLazily = + attrs: extraArgs: + if (l.isFunction attrs) then + lazyArgsPerParameter attrs (moduleArgs // extraArgs) + else + attrs + ; + + s3 = callModuleLazily moduleArgs path; + # => { config = { }; imports = [... ]; _file } + s3final = + let + s3Module = mkExtenders (winnow path s3 mkModulePath) path; + s3Profile = mkExtenders s3 path; + in + if isEvalModule then s3Module else s3Profile; + + mkExtenders = + module: path: + let + removedOptionModule = removeAttrs module [ "options" ]; + filteredList = + l.filter (item: item.path == (relModulePathWithoutDefault path)) + extenders; + + foundItem = + if (builtins.length filteredList) > 0 then + (builtins.head filteredList) + else + [ ] + ; + + loadExtendModuleFromValue = + if foundItem != [ ] then + (callArgsLazily foundItem.value { + selfModule = module; + # add the options back in + # dmerge self' {} + selfModule' = x: module // (x removedOptionModule); + # add dmerge support + inherit dmerge; + }) + else + module + ; + in + loadExtendModuleFromValue; + + winnow = + path: module: fun: + ({ + config = + if module ? config then + fun module.config + else + fun ( + removeAttrs module [ + "options" + "imports" + ] + ) + ; + imports = module.imports or [ ]; + }) + // { + _file = path; + options = fun module.options or { }; + } + ; + in + s3final; + in + module + ); + transformer = + if cfg.transformer != [ ] then + cfg.transformer + else + [ (_cursor: dir: if dir ? default then dir.default else dir) ] + ; + }; +in +{ + default = base { }; + __extenders = extenders: base { inherit extenders; }; +} +// l.optionalAttrs (cfg.type == "nixosModules") { nixosModules = base { }; } +// l.optionalAttrs (cfg.type == "nixosProfiles") { nixosProfiles = base { }; } diff --git a/src/haumea/pops.nix b/src/haumea/pops.nix new file mode 100644 index 0000000..f433cc4 --- /dev/null +++ b/src/haumea/pops.nix @@ -0,0 +1,226 @@ +{ + POP, + haumea, + yants, + super, + lib, + dmerge, + self, +}: +let + inherit (POP.lib) pop extendPop; + inherit (yants) defun; + inherit (super) nixosModules; + + trace = x: l.trace x x; + types = yants // super.types; + l = lib // builtins; + + loadExtender = pop { + defaults = { + initLoad = { + src = ./.; + loader = haumea.lib.loaders.default; + inputs = { }; + transformer = [ ]; + type = "default"; + }; + load = { }; + }; + extension = self: super: { + setInit = + defun + ( + with types; [ + (attrs any) + haumeaInitLoadPop + ] + ) + ( + initLoad: + extendPop self (self: super: { initLoad = super.initLoad // initLoad; }) + ); + }; + }; + + exporter = pop { + defaults = { + exports = { }; + load = { }; + }; + supers = [ ]; + extension = self: super: { + setLoad = + defun + ( + with types; [ + haumeaLoadPop + haumeaExporterPop + ] + ) + ( + load: + extendPop self ( + self: super: { + load = { + inherit (load) loader transformer type; + src = + if l.isString load.src then l.unsafeDiscardStringContext load.src else load.src; + inputs = l.removeAttrs load.inputs [ "self" ]; + }; + } + ) + ); + + setLayouts = (layouts: extendPop self (self: super: { inherit layouts; })); + + setOutputs = + defun + ( + with types; [ + (attrs any) + haumeaExporterPop + ] + ) + (outputs: extendPop self (self: super: { inherit outputs; })); + }; + }; + + default = pop { + supers = [ + loadExtender + exporter + ]; + defaults = { + loadExtenders = [ ]; + exporters = [ ]; + }; + extension = self: super: { + # -- exports -- + exports = + let + generalExporters = + l.foldl + ( + acc: extender: + let + ex' = + if extender ? setOutputs then + ((extender.setOutputs self.outputs).setLayouts self.layouts).exports + else + extender.exports + ; + in + acc // ex' + ) + { } + self.exporters; + in + generalExporters; + + # -- exportersExtener -- + addExporter = exporter: self.addExporters [ exporter ]; + addExporters = + exporters: + extendPop self (self: super: { exporters = super.exporters ++ exporters; }); + + # -- load -- + load = + l.foldl + ( + acc: extender: + let + ext' = + if (extender ? setInit) then + (extender.setInit self.initLoad).load + else + extender.load + ; + in + l.recursiveMerge ([ + # NOTE: put the ext' first so that the initLoad is the last to be merged + acc + ext' + ]) + ) + self.initLoad + self.loadExtenders; + + # -- loadExtenders -- + addLoadExtender = + defun + ( + with types; [ + (either haumeaInitLoadPop (attrs any)) + haumeaDefaultPop + ] + ) + (loadExtender: self.addLoadExtenders [ loadExtender ]); + + addLoadExtenders = + defun + ( + with types; [ + (either (list haumeaInitLoadPop) (list (attrs any))) + haumeaDefaultPop + ] + ) + ( + loadExtenders: + extendPop self ( + self: super: { loadExtenders = super.loadExtenders ++ loadExtenders; } + ) + ); + + # -- outputs -- + # laziest way to get the outputs + # default is to merge the outputs with dmerege + outputs = + defun + ( + with types; [ + (eitherN [ + function + (attrs any) + (list (attrs any)) + ]) + (attrs any) + ] + ) + ( + x: + if self.layouts ? __extenders then + self.layouts.__extenders x + else if l.isFunction x then + x self.layouts.default + else if x != { } then + dmerge.merge self.layouts.default x + else + self.layouts.default + ); + + layouts = + ( + let + cfg = (exporter.setLoad self.load).load; + haumeaOutputs = + if + (l.elem cfg.type [ + "nixosModules" + "nixosProfiles" + "evalModules" + ]) + then + nixosModules { inherit cfg; } + else + { default = haumea.lib.load (l.removeAttrs cfg [ "type" ]); } + ; + in + haumeaOutputs // (l.removeAttrs self.exports [ "default" ]) + ); + }; + }; +in +{ + inherit default loadExtender exporter; +} diff --git a/src/haumea/structAttrs.nix b/src/haumea/structAttrs.nix new file mode 100644 index 0000000..c4663af --- /dev/null +++ b/src/haumea/structAttrs.nix @@ -0,0 +1,79 @@ +{ + yants, + root, + lib, + self, +}: +let + types = root.haumea.types // yants; + l = lib // builtins; + + enum' = + o: e: v: + (with yants; enum o e) + // { + toError = + x: + throw '' + Invalid value for '${v}': "${x}" + Valid values are: [ ${l.concatStringsSep " " e} ] + ''; + } + ; + structAttrs = with yants; { + pop = { + __meta__ = option ( + struct "__meta__" { + name = string; + supers = list types.pop; + defaults = attrs any; + extension = function; + precedenceList = list (attrs any); + } + ); + }; + + haumeaDefaultPop = structAttrs.pop // { + exports = attrs any; + + loadExtenders = list any; + + addLoadExtender = function; + addLoadExtenders = function; + + addExporters = function; + addExporter = function; + }; + + haumeaExporterPop = structAttrs.pop // { + exports = attrs any; + load = attrs any; + + setLoad = function; + setOutputs = function; + }; + + haumeaLoad = { + src = either path string; + transformer = either function (list any); + inputs = attrs any; + loader = either function (list any); + type = + enum' "options" + [ + "nixosModules" + "default" + "nixosProfiles" + "evalModules" + ] + "type"; + }; + haumeaLoadPop = structAttrs.pop // structAttrs.haumeaLoad; + haumeaInitLoadPop = structAttrs.pop // rec { + initLoad = struct "haumea.load" structAttrs.haumeaLoad; + #list (either function any); + setInit = function; + }; + }; +in +structAttrs diff --git a/src/haumea/types.nix b/src/haumea/types.nix new file mode 100644 index 0000000..3c80b93 --- /dev/null +++ b/src/haumea/types.nix @@ -0,0 +1,24 @@ +{ + yants, + root, + super, +}: +with (yants "flops"); +let + inherit (super.structAttrs) + haumeaLoadPop + haumeaExporterPop + haumeaInitLoadPop + haumeaDefaultPop + pop + ; + inherit (haumeaInitLoadPop) initLoad; +in +{ + pop = openStruct pop; + haumeaLoadPop = openStruct haumeaLoadPop; + haumeaExporterPop = openStruct haumeaExporterPop; + haumeaDefaultPop = openStruct haumeaDefaultPop; + haumeaInitLoadPop = openStruct haumeaInitLoadPop; + haumeaLoad = initLoad; +} diff --git a/templates/default/flake.lock b/templates/default/flake.lock new file mode 100644 index 0000000..eb962c3 --- /dev/null +++ b/templates/default/flake.lock @@ -0,0 +1,255 @@ +{ + "nodes": { + "POP": { + "inputs": { + "flake-compat": "flake-compat", + "nixlib": "nixlib", + "nixpkgs": [ + "flops" + ] + }, + "locked": { + "lastModified": 1655410953, + "narHash": "sha256-Er0zdhu7QwpWvVKfauqZqTnxDz6THTWOTVWLoz+Opmw=", + "owner": "divnix", + "repo": "POP", + "rev": "8babe4c9126298d05ebb5ab04727d741b51c022e", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "POP", + "type": "github" + } + }, + "call-flake": { + "locked": { + "lastModified": 1689473344, + "narHash": "sha256-bmhE1TmrJG4ba93l9WQTLuYM53kwGQAjYHRvHOeuxWU=", + "owner": "divnix", + "repo": "call-flake", + "rev": "a07e91d3fb59eb9f7ec706a151e1a7b36a1e8727", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "call-flake", + "type": "github" + } + }, + "dmerge": { + "inputs": { + "haumea": [ + "flops", + "haumea" + ], + "nixlib": [ + "flops", + "nixlib" + ], + "yants": [ + "flops", + "yants" + ] + }, + "locked": { + "lastModified": 1686862774, + "narHash": "sha256-ojGtRQ9pIOUrxsQEuEPerUkqIJEuod9hIflfNkY+9CE=", + "owner": "divnix", + "repo": "dmerge", + "rev": "9f7f7a8349d33d7bd02e0f2b484b1f076e503a96", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "dmerge", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1650374568, + "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "b4a34015c698c7793d592d66adbab377907a2be8", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flops": { + "inputs": { + "POP": "POP", + "call-flake": "call-flake", + "dmerge": "dmerge", + "haumea": "haumea", + "nixlib": "nixlib_2", + "yants": "yants" + }, + "locked": { + "lastModified": 1694677377, + "narHash": "sha256-oT6S09hN+6elGlWX0d7euzhplCfveCUtFr4QsmHDeus=", + "owner": "gtrunsec", + "repo": "flops", + "rev": "b31402c55ea03e135edb45b5af127864c29a573c", + "type": "github" + }, + "original": { + "owner": "gtrunsec", + "repo": "flops", + "type": "github" + } + }, + "haumea": { + "inputs": { + "nixpkgs": [ + "flops", + "nixlib" + ] + }, + "locked": { + "lastModified": 1689557889, + "narHash": "sha256-kllmt6JnHlry+WAASdSMDaRwbiuk2dFhkbW3Qz1w8BU=", + "owner": "nix-community", + "repo": "haumea", + "rev": "d6a9593ff2160ce29bf6d905e9ccbcecd66baeef", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "haumea", + "type": "github" + } + }, + "haumea_2": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1685133229, + "narHash": "sha256-FePm/Gi9PBSNwiDFq3N+DWdfxFq0UKsVVTJS3cQPn94=", + "owner": "nix-community", + "repo": "haumea", + "rev": "34dd58385092a23018748b50f9b23de6266dffc2", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "v0.2.2", + "repo": "haumea", + "type": "github" + } + }, + "nixlib": { + "locked": { + "lastModified": 1653180592, + "narHash": "sha256-sVGwmxTj7CY1D4ioy7E+iJE+1/yHqQlxjnTpar3ap/E=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "42c5f5785b70cd64b4afd830dc31d0b08461abd5", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixlib_2": { + "locked": { + "lastModified": 1689469483, + "narHash": "sha256-2SBhY7rZQ/iNCxe04Eqxlz9YK9KgbaTMBssq3/BgdWY=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "02fea408f27186f139153e1ae88f8ab2abd9c22c", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixlib_3": { + "locked": { + "lastModified": 1694306727, + "narHash": "sha256-26fkTOJOI65NOTNKFvtcJF9mzzf/kK9swHzfYt1Dl6Q=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "c30b6a84c0b84ec7aecbe74466033facc9ed103f", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1660438583, + "narHash": "sha256-rJUTYxFKlWUJI3njAwEc1pKAVooAViZGJvsgqfh/q/E=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "bbd8f7cd87d0b29294ef3072ffdbd61d60f05da4", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1694422566, + "narHash": "sha256-lHJ+A9esOz9vln/3CJG23FV6Wd2OoOFbDeEs4cMGMqc=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "3a2786eea085f040a66ecde1bc3ddc7099f6dbeb", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flops": "flops", + "haumea": "haumea_2", + "nixlib": "nixlib_3", + "nixpkgs": "nixpkgs_2" + } + }, + "yants": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1686863218, + "narHash": "sha256-kooxYm3/3ornWtVBNHM3Zh020gACUyFX2G0VQXnB+mk=", + "owner": "divnix", + "repo": "yants", + "rev": "8f0da0dba57149676aa4817ec0c880fbde7a648d", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "yants", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/templates/default/flake.nix b/templates/default/flake.nix new file mode 100644 index 0000000..6818c1d --- /dev/null +++ b/templates/default/flake.nix @@ -0,0 +1,37 @@ +{ + inputs = { + haumea = { + url = "github:nix-community/haumea/v0.2.2"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + nixlib.url = "github:nix-community/nixpkgs.lib"; + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + flops.url = "github:gtrunsec/flops"; + }; + + outputs = + { + self, + haumea, + nixlib, + nixpkgs, + flops, + }: + let + l = nixlib.lib; + in + { + eval = nixpkgs.lib.evalModules { + modules = [ self.loadModules.outputs.default.programs.git ]; + }; + + nixos = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ self.loadModules.outputs.default.programs.git ]; + }; + loadModules = flops.lib.haumea.pops.default.setInit { + src = ./nixosModules; + type = "nixosModules"; + }; + }; +} diff --git a/templates/default/nixosModules/programs/git/default.nix b/templates/default/nixosModules/programs/git/default.nix new file mode 100644 index 0000000..64352fe --- /dev/null +++ b/templates/default/nixosModules/programs/git/default.nix @@ -0,0 +1,10 @@ +{ + enable = true; + + options = { + custom = lib.mkOption { + type = lib.types.str; + default = "default"; + }; + }; +} diff --git a/tests/_snapshots/configs b/tests/_snapshots/configs new file mode 100644 index 0000000..0920f16 --- /dev/null +++ b/tests/_snapshots/configs @@ -0,0 +1,15 @@ +#pretty +{ + home-manager = { + success = true; + value = { + modules = [ ]; + }; + }; + nixos = { + success = true; + value = { + modules = [ ]; + }; + }; +} \ No newline at end of file diff --git a/tests/_snapshots/evalModules b/tests/_snapshots/evalModules new file mode 100644 index 0000000..317301a --- /dev/null +++ b/tests/_snapshots/evalModules @@ -0,0 +1,53 @@ +#pretty +{ + custom = { + programs = { + git = { + __profiles__ = { + enable = false; + name = "guangtao"; + }; + }; + }; + }; + default = { + programs = { + emacs = { + customAttr = { + a = "a"; + }; + customAttr2 = { + a = "a"; + }; + customList = [ + "a" + ]; + customList2 = [ + "a" + "b" + ]; + enable = true; + }; + git = { + __profiles__ = { + enable = true; + name = "John Doe"; + }; + }; + }; + services = { + openssh = { + customList = [ + "a" + ]; + customList2 = [ ]; + customList3 = [ ]; + customList4 = [ + "mkMerge" + ]; + enable = true; + enableCustom = true; + }; + }; + }; +} \ No newline at end of file diff --git a/tests/_snapshots/flake b/tests/_snapshots/flake new file mode 100644 index 0000000..28c0cc4 --- /dev/null +++ b/tests/_snapshots/flake @@ -0,0 +1,28 @@ +#pretty +{ + exampleFlake = { + packages = { + x86_64-darwin = { + firefox = ; + }; + x86_64-linux = { + firefox = ; + }; + }; + }; + outputs = { + flake-compat = { + lastModified = 1683211519; + lastModifiedDate = "20230504144519"; + narHash = "sha256-/PpdA67EEsOQafiS3snVbQ0uCfu/ZmcB5mkGjrXlvmo="; + outPath = "/nix/store/7l3qc8z1zcvbiwidggw5bhnl5w0a9m4k-source"; + rev = "fe6baef74f390a1d63b22f0be33ac95a4101cca5"; + shortRev = "fe6baef"; + }; + nixlib = { + lib = { + func = ; + }; + }; + }; +} \ No newline at end of file diff --git a/tests/_snapshots/haumeaData b/tests/_snapshots/haumeaData new file mode 100644 index 0000000..4510438 --- /dev/null +++ b/tests/_snapshots/haumeaData @@ -0,0 +1,100 @@ +#pretty +{ + exports = { + success = true; + value = { + customData = { + data = { + foo = "baz"; + }; + treefmt = { + formatter = { + nix = { + command = "alejandra"; + excludes = [ + "data.nix" + ]; + }; + prettier = { + includes = [ + "*.jsl" + ]; + }; + }; + prettier = { + includes = [ + "*.toml" + ]; + }; + }; + }; + }; + }; + outputs = { + success = true; + value = { + default = { + data = { + foo = "baz"; + }; + treefmt = { + formatter = { + nix = { + command = "alejandra"; + excludes = [ ]; + }; + }; + prettier = { + includes = [ + "*.toml" + ]; + }; + }; + }; + dmergeWithOutputs = { + data = { + foo = "baz"; + }; + treefmt = { + formatter = { + nix = { + command = "nixfmt"; + excludes = [ ]; + }; + prettier = { + includes = [ + "*.dmergeOutputs" + ]; + }; + }; + prettier = { + includes = [ + "*.toml" + ]; + }; + }; + }; + funWithOutputs = { + data = { + foo = "baz"; + }; + dataExt = { + foo = "bar"; + }; + treefmt = { + formatter = { + nix = { + command = "alejandra"; + excludes = [ ]; + }; + }; + prettier = { + includes = [ + "*.toml" + ]; + }; + }; + }; + }; + }; +} \ No newline at end of file diff --git a/tests/_snapshots/haumeaNixOSModules b/tests/_snapshots/haumeaNixOSModules new file mode 100644 index 0000000..ab96a14 --- /dev/null +++ b/tests/_snapshots/haumeaNixOSModules @@ -0,0 +1,19 @@ +#pretty +{ + exports = { + success = true; + value = { }; + }; + outputs = { + success = true; + value = { + programs = { + emacs = ; + git = ; + }; + services = { + openssh = ; + }; + }; + }; +} \ No newline at end of file diff --git a/tests/configs/expr.nix b/tests/configs/expr.nix new file mode 100644 index 0000000..081bdb5 --- /dev/null +++ b/tests/configs/expr.nix @@ -0,0 +1,29 @@ +{ configs, inputs }: +let + inherit (inputs) POP dmerge; + default = + ((configs.pops.default.setInitRecipes { + nixos = { + modules = [ ]; + }; + }).addRecipesExtender + { + home-manager = { + modules = [ ]; + }; + } + ).addExporters + [ + (inputs.POP.lib.extendPop configs.pops.exporter ( + self: super: { + exports.home-manager = self.recipes.home-manager; + exports.nixos = self.recipes.nixos; + } + )) + ]; + inherit (builtins) deepSeq mapAttrs tryEval; +in +mapAttrs (_: x: tryEval (deepSeq x x)) { + home-manager = default.exports.home-manager; + nixos = default.exports.nixos; +} diff --git a/tests/configs/format.nix b/tests/configs/format.nix new file mode 100644 index 0000000..f9e1770 --- /dev/null +++ b/tests/configs/format.nix @@ -0,0 +1 @@ +"pretty" diff --git a/tests/evalModules/__fixture/programs/emacs/default.nix b/tests/evalModules/__fixture/programs/emacs/default.nix new file mode 100644 index 0000000..44d130c --- /dev/null +++ b/tests/evalModules/__fixture/programs/emacs/default.nix @@ -0,0 +1,44 @@ +{ + /* # we can also use the following syntax to define a module + config = { + enable = true; + } + */ + + enable = true; + customAttr2 = config.programs.emacs.customAttr; + customList2 = cfg.customList ++ [ "b" ]; + options = lib.mkOption { + type = lib.types.submodule { + freeformType = lib.types.attrs; + options = { + enable = lib.mkEnableOption { + default = true; + description = "Whether to enable the VAST node."; + }; + customAttr = lib.mkOption { + type = lib.types.attrs; + default = { + a = "a"; + }; + description = "A custom attribute."; + }; + customAttr2 = lib.mkOption { + type = lib.types.attrs; + default = { }; + description = "A custom attribute."; + }; + customList = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = [ "a" ]; + description = "A custom list."; + }; + customList2 = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = [ ]; + description = "A custom list."; + }; + }; + }; + }; +} diff --git a/tests/evalModules/__fixture/programs/git/default.nix b/tests/evalModules/__fixture/programs/git/default.nix new file mode 100644 index 0000000..721cb87 --- /dev/null +++ b/tests/evalModules/__fixture/programs/git/default.nix @@ -0,0 +1,4 @@ +{ + imports = [ (loadSubmodule ./opt.nix) ]; + __profiles__.enable = true; +} diff --git a/tests/evalModules/__fixture/programs/git/opt.nix b/tests/evalModules/__fixture/programs/git/opt.nix new file mode 100644 index 0000000..9462c3a --- /dev/null +++ b/tests/evalModules/__fixture/programs/git/opt.nix @@ -0,0 +1,15 @@ +{ + config.programs.git.__profiles__.name = "John Doe"; + options = + with lib; + (mkModulePath { + __profiles__ = { + enable = mkEnableOption (lib.mdDoc "Whether to enable git profile"); + name = lib.mkOption { + type = types.str; + default = ""; + description = "Your name"; + }; + }; + }); +} diff --git a/tests/evalModules/__fixture/services/openssh.nix b/tests/evalModules/__fixture/services/openssh.nix new file mode 100644 index 0000000..12b6603 --- /dev/null +++ b/tests/evalModules/__fixture/services/openssh.nix @@ -0,0 +1,50 @@ +{ + lib, + config, + cfg, +}: +{ + enable = true; + enableCustom = cfg.enable; + customList = [ "a" ]; + customList2 = [ ]; + customList3 = [ ]; + customList4 = [ "mkMerge" ]; + + options = lib.mkOption { + type = lib.types.submodule { + freeformType = lib.types.attrs; + options = { + enableCustom = lib.mkEnableOption { + default = false; + description = "Whether to enable the custom node."; + }; + enable = lib.mkEnableOption { + default = true; + description = "Whether to enable the VAST node."; + }; + customList = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = [ "a" ]; + description = "A custom list."; + }; + customList2 = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = [ ]; + description = "A custom list."; + }; + + customList3 = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = [ ]; + description = "A custom list."; + }; + customList4 = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = [ ]; + description = "A custom list."; + }; + }; + }; + }; +} diff --git a/tests/evalModules/expr.nix b/tests/evalModules/expr.nix new file mode 100644 index 0000000..a934978 --- /dev/null +++ b/tests/evalModules/expr.nix @@ -0,0 +1,85 @@ +{ lib, inputs }: +let + inherit (inputs) POP dmerge nixlib; + inherit (POP.lib) extendPop; + inherit (lib.haumea) pops; + inherit (nixlib.lib) evalModules; + + A = + with inputs.haumea.lib; + pops.default.setInit { + src = ../..; + type = "default"; + }; + + B = + with inputs.haumea.lib; + A.addLoadExtender { + load.inputs = { + POP = inputs.POP; + lib = inputs.nixlib.lib; + inherit (inputs) dmerge; + }; + }; + + loadModules = + (B.addLoadExtender { + load = { + src = ./__fixture; + type = "nixosModules"; + }; + }).addExporters + [ + (extendPop pops.exporter ( + self: super: { + exports.test = self.outputs [ + ({ + value = + ( + { selfModule' }: + selfModule' (m: dmerge m { config.programs.git.__profiles__.enable = false; }) + ); + path = [ + "programs" + "git" + ]; + }) + ({ + value = + ( + { selfModule' }: + selfModule' ( + m: dmerge m { config.programs.git.__profiles__.name = "guangtao"; } + ) + ); + path = [ + "programs" + "git" + "opt" + ]; + }) + ]; + } + )) + ]; + + evaled = { + default = + (evalModules { + modules = [ + loadModules.layouts.default.programs.git + loadModules.layouts.default.programs.emacs + loadModules.layouts.default.services.openssh + ]; + }).config; + custom = + (evalModules { + modules = [ + loadModules.exports.test.programs.git + # loadModules.outputs.default.programs.git + ]; + }).config; + }; + inherit (builtins) deepSeq mapAttrs tryEval; +in +evaled diff --git a/tests/evalModules/format.nix b/tests/evalModules/format.nix new file mode 100644 index 0000000..f9e1770 --- /dev/null +++ b/tests/evalModules/format.nix @@ -0,0 +1 @@ +"pretty" diff --git a/tests/flake/__lock/flake.lock b/tests/flake/__lock/flake.lock new file mode 100644 index 0000000..d46c000 --- /dev/null +++ b/tests/flake/__lock/flake.lock @@ -0,0 +1,28 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1683211519, + "narHash": "sha256-/PpdA67EEsOQafiS3snVbQ0uCfu/ZmcB5mkGjrXlvmo=", + "owner": "gtrunsec", + "repo": "flake-compat", + "rev": "fe6baef74f390a1d63b22f0be33ac95a4101cca5", + "type": "github" + }, + "original": { + "owner": "gtrunsec", + "ref": "lockFile", + "repo": "flake-compat", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-compat": "flake-compat" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/tests/flake/__lock/flake.nix b/tests/flake/__lock/flake.nix new file mode 100644 index 0000000..65c3740 --- /dev/null +++ b/tests/flake/__lock/flake.nix @@ -0,0 +1,9 @@ +{ + inputs = { + flake-compat = { + url = "github:gtrunsec/flake-compat/lockFile"; + flake = false; + }; + }; + outputs = { self, ... }@inputs: { inherit inputs; }; +} diff --git a/tests/flake/expr.nix b/tests/flake/expr.nix new file mode 100644 index 0000000..e994048 --- /dev/null +++ b/tests/flake/expr.nix @@ -0,0 +1,58 @@ +{ + lib, + inputs, + flake, +}: +let + inherit (builtins) deepSeq mapAttrs tryEval; + + inherit (inputs) POP; + inherit (flake) pops; + exampleFlake = { + inherit inputs; + outputs = + inputs: + (((pops.default.setInitInputs inputs).addInputsExtenders [ + (POP.lib.extendPop pops.inputsExtender ( + self: super: { + inputs = { + inherit ((inputs.call-flake ../../examples/__nixpkgsFlake).inputs) nixpkgs; + nixlib.lib.func = self.initInputs.nixlib.lib.genAttrs; + }; + } + )) + ]).addExporters + [ + (POP.lib.extendPop pops.exporter ( + self: _: { + exports.packages.firefox = self.inputs.nixpkgs.legacyPackages.firefox; + } + )) + ] + ).outputsForSystems + [ + "x86_64-linux" + "x86_64-darwin" + ]; + }; + outputs = + inputs: + ( + (((pops.default.setInitInputs inputs).setSystem "x86_64-linux") + .addInputsExtenders + [ + (POP.lib.extendPop pops.inputsExtender ( + self: super: { + inputs = { + nixlib.lib.func = lib.isFunction; + }; + } + )) + ] + ) + ).outputs; +in +{ + exampleFlake = exampleFlake.outputs exampleFlake.inputs; + outputs = outputs ./__lock; +} diff --git a/tests/flake/format.nix b/tests/flake/format.nix new file mode 100644 index 0000000..f9e1770 --- /dev/null +++ b/tests/flake/format.nix @@ -0,0 +1 @@ +"pretty" diff --git a/tests/haumeaData/__data/data.nix b/tests/haumeaData/__data/data.nix new file mode 100644 index 0000000..ab1e5aa --- /dev/null +++ b/tests/haumeaData/__data/data.nix @@ -0,0 +1 @@ +with dmerge; merge { foo = "bar"; } { foo = "baz"; } diff --git a/tests/haumeaData/__data/treefmt.nix b/tests/haumeaData/__data/treefmt.nix new file mode 100644 index 0000000..06f6b92 --- /dev/null +++ b/tests/haumeaData/__data/treefmt.nix @@ -0,0 +1,9 @@ +{ + formatter.nix = { + command = "alejandra"; + excludes = [ ]; + }; + prettier = { + includes = [ "*.toml" ]; + }; +} diff --git a/tests/haumeaData/expr.nix b/tests/haumeaData/expr.nix new file mode 100644 index 0000000..18a0d86 --- /dev/null +++ b/tests/haumeaData/expr.nix @@ -0,0 +1,62 @@ +{ inputs, lib }: +with inputs.haumea.lib; +let + inherit (inputs) POP dmerge; + inherit (POP.lib) extendPop; + inherit (lib.haumea) pops; + + a = pops.default.setInit { + transformer = [ transformers.liftDefault ]; + inputs = { + lib = inputs.nixlib.lib; + }; + }; + + b = a.addLoadExtender { + load = { + inputs = { + dmerge = inputs.dmerge; + }; + }; + }; + + data = + ((b.addLoadExtender { load.src = ./__data; }).addLoadExtender ( + extendPop pops.loadExtender ( + self: super: { load.loader = [ (matchers.nix loaders.scoped) ]; } + ) + )).addExporters + [ + (extendPop pops.exporter ( + self: super: { + exports.customData = + with dmerge; + self.outputs { + treefmt.formatter.nix.excludes = append [ "data.nix" ]; + treefmt.formatter.prettier.includes = append [ "*.jsl" ]; + }; + } + )) + ]; + + inherit (builtins) deepSeq mapAttrs tryEval; +in +mapAttrs (_: x: tryEval (deepSeq x x)) { + outputs = { + default = data.outputs { }; + dmergeWithOutputs = data.outputs { + treefmt.formatter.nix.command = "nixfmt"; + treefmt.formatter.prettier.includes = with dmerge; append [ "*.dmergeOutputs" ]; + }; + funWithOutputs = data.outputs ( + x: + x + // { + dataExt = { + foo = "bar"; + }; + } + ); + }; + exports = data.exports; +} diff --git a/tests/haumeaData/format.nix b/tests/haumeaData/format.nix new file mode 100644 index 0000000..f9e1770 --- /dev/null +++ b/tests/haumeaData/format.nix @@ -0,0 +1 @@ +"pretty" diff --git a/tests/haumeaNixOSModules/expr.nix b/tests/haumeaNixOSModules/expr.nix new file mode 100644 index 0000000..fd7c6ed --- /dev/null +++ b/tests/haumeaNixOSModules/expr.nix @@ -0,0 +1,50 @@ +{ inputs, lib }: +let + inherit (inputs) POP dmerge; + inherit (POP.lib) extendPop; + inherit (lib.haumea) pops; + + A = + with inputs.haumea.lib; + pops.default.setInit { + src = ../..; + inputs = { + inherit lib; + }; + type = "nixosModules"; + }; + + B = + with inputs.haumea.lib; + A.addLoadExtender { + load.inputs = { + inherit (inputs) dmerge; + }; + }; + + nixosModules = + with inputs.haumea.lib; + ((B.addLoadExtender { + load = { + src = ../evalModules/__fixture; + type = "nixosModules"; + }; + }).addLoadExtender + ( + extendPop pops.loadExtender ( + self: super: { + load.inputs = { + POP = inputs.POP; + }; + } + ) + ) + ); + inherit (builtins) deepSeq mapAttrs tryEval; +in +mapAttrs (_: x: tryEval (deepSeq x x)) { + + outputs = nixosModules.outputs { }; + + exports = nixosModules.exports; +} diff --git a/tests/haumeaNixOSModules/format.nix b/tests/haumeaNixOSModules/format.nix new file mode 100644 index 0000000..f9e1770 --- /dev/null +++ b/tests/haumeaNixOSModules/format.nix @@ -0,0 +1 @@ +"pretty"