From de77c3f1bb6ecf1b3ac39bd79a69c62a7d8f728f Mon Sep 17 00:00:00 2001 From: Peter Esselius Date: Sun, 14 Jul 2024 20:59:42 +0200 Subject: [PATCH] wip --- .github/workflows/ci.yaml | 66 ++++++++++++++++++++++ dag.py | 44 +++++++++++++++ flake.nix | 4 +- {tests => nixos-tests}/monitoring-auth.nix | 6 +- 4 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/ci.yaml create mode 100644 dag.py rename {tests => nixos-tests}/monitoring-auth.nix (98%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..8e4eae8 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,66 @@ +name: CI + +on: + pull_request: + branches: + - main + +jobs: + generate-matrix: + name: Generate job matrices + runs-on: ubuntu-latest + outputs: + darwin-configurations: ${{ steps.x.outputs.matrix }} + darwin-modules: ${{ steps.x.outputs.matrix }} + home-configurations: ${{ steps.x.outputs.matrix }} + home-modules: ${{ steps.x.outputs.matrix }} + nixos-configurations: ${{ steps.x.outputs.matrix }} + nixos-modules: ${{ steps.x.outputs.matrix }} + nixos-tests: ${{ steps.x.outputs.matrix }} + steps: + - name: Get changes + id: changed-files + uses: tj-actions/changed-files@v44 + with: + dir_names_max_depth: 1 + dir_names: true + matrix: true + + # nix + + # - name: Generate matrix | Infrastructure + # id: neo-infrastructure + # uses: hellofresh/action-changed-files@v3 + # with: + # pattern: infrastructure/(?P[^/]+) + # default-patterns: | + # terraform-modules + # deploy.sh + + # - name: Generate matrix | Library + # id: neo-library + # uses: hellofresh/action-changed-files@v3 + # with: + # pattern: library/(?P(?!common)[^/]+) + # default-patterns: | + # library/common + + # infrastructure: + # runs-on: ubuntu-latest + # needs: [ generate-matrix ] # don't forget this! + # strategy: + # matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix-infrastructure) }} + # if: ${{ fromJson(needs.generate-matrix.outputs.matrix-infrastructure).include[0] }} # skip if the matrix is empty! + # steps: + # - name: Deploy infrastructure + # run: echo "Deploying ${{ matrix.environment }}" + + # build: + # runs-on: ubuntu-latest + # needs: [ generate-matrix ] + # strategy: + # matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix-build) }} + # if: ${{ fromJson(needs.generate-matrix.outputs.matrix-build).include[0] }} + # steps: + # - name: Building library + # run: echo "Building ${{ matrix.lib }}" diff --git a/dag.py b/dag.py new file mode 100644 index 0000000..e926f3f --- /dev/null +++ b/dag.py @@ -0,0 +1,44 @@ +import os +import re + +import networkx as nx + +moduleSystems = ["darwin", "home", "nixos"] +moduleTypes = ["configurations", "modules", "tests"] +ezModulePattern = re.compile(r"ezModules.([a-zA-Z-1-9]+)") +inputsModulePattern = re.compile(r"[^-]inputs.([a-zA-Z-1-9]+)") + +G = nx.Graph() + +for ms in moduleSystems: + for mt in moduleTypes: + folder = f"{ms}-{mt}" + + if os.path.exists(folder): + for fd in os.scandir(folder): + module = folder + "/" + fd.name.removesuffix(".nix") + + if mt == "configurations": + defaultModule = f"{ms}-modules/default" + G.add_edge(module, defaultModule) + + if fd.name.endswith(".nix"): + with open(fd, encoding="utf-8") as f: + data = f.read() + for match in re.finditer(ezModulePattern, data): + dep = f"{ms}-modules/{match.group(1)}" + G.add_edge(module, dep) + + for match in re.finditer(inputsModulePattern, data): + dep = f"inputs/{match.group(1)}" + G.add_edge(module, dep) + else: + for sub_fd in os.scandir(fd.path): + with open(sub_fd, encoding="utf-8") as f: + data = f.read() + for match in re.finditer(ezModulePattern, data): + dep = f"{ms}-modules/{match.group(1)}" + G.add_edge(module, dep) + +print(G.nodes) +print(nx.shortest_path(G, "darwin-configurations/Fox", "inputs/nixpkgs-unstable")) diff --git a/flake.nix b/flake.nix index 25b47a8..bc79f97 100644 --- a/flake.nix +++ b/flake.nix @@ -47,10 +47,10 @@ }; perSystem = { pkgs, ... }: { nixosTests = { - path = ./tests; + path = ./nixos-tests; args = { inherit inputs; - myModules = self.nixosModules; + ezModules = self.nixosModules; }; env = { PLAYWRIGHT_BROWSERS_PATH = pkgs.playwright-driver.browsers; diff --git a/tests/monitoring-auth.nix b/nixos-tests/monitoring-auth.nix similarity index 98% rename from tests/monitoring-auth.nix rename to nixos-tests/monitoring-auth.nix index c3fe893..6413560 100644 --- a/tests/monitoring-auth.nix +++ b/nixos-tests/monitoring-auth.nix @@ -1,4 +1,4 @@ -{ myModules, inputs, ... }: +{ ezModules, inputs, ... }: { name = "monitoring-auth"; @@ -13,8 +13,8 @@ imports = [ inputs.authentik-nix.nixosModules.default - myModules.authentik-blueprints - myModules.profiles + ezModules.authentik-blueprints + ezModules.profiles ]; networking.firewall.enable = false;