From bd88cca04f1454d9640af545e9790f765292c2e0 Mon Sep 17 00:00:00 2001 From: guangtao Date: Fri, 6 Oct 2023 04:10:22 -0700 Subject: [PATCH] refactor: update tests --- .github/workflows/checks.yaml | 2 +- examples/nixos/pops/data.nix | 8 -- flake.nix | 15 +--- lib/{exporters => exporter}/pops.nix | 5 +- local/flake.lock | 79 ++++++++++++++++--- local/flake.nix | 15 +++- namaka.toml | 19 +---- nixos/nixosConfigurations/nixos.nix | 9 --- templates/nixos/flake.nix | 4 +- .../nix/lib/{exporters.nix => exporter.nix} | 2 +- tests/_snapshots/data | 2 + tests/_snapshots/nixos | 13 +++ .../__data => tests/data/__fixture}/env.toml | 0 .../data/__fixture}/personal.yaml | 0 tests/data/expr.nix | 10 +++ .../nixos/__fixture}/__lock/flake.lock | 0 .../nixos/__fixture}/__lock/flake.nix | 0 .../__fixture}/__nixosProfiles/bootstrap.nix | 0 .../nixos => tests/nixos/__fixture}/_test.nix | 0 .../nixos/__fixture}/layouts.nix | 33 +++++--- .../nixos/__fixture}/pops/homeModules.nix | 0 .../nixos/__fixture}/pops/homeProfiles.nix | 0 .../nixos/__fixture}/pops/inputs.nix | 2 +- .../nixos/__fixture}/pops/nixosModules.nix | 0 .../nixos/__fixture}/pops/nixosProfiles.nix | 0 .../__fixture}/pops/selfNixOSProfiles.nix | 0 .../nixos/__fixture}/pops/srvos.nix | 0 tests/nixos/_pops.nix | 12 +++ tests/nixos/expr.nix | 28 +++++++ tests/nixos/format.nix | 1 + 30 files changed, 184 insertions(+), 75 deletions(-) delete mode 100644 examples/nixos/pops/data.nix rename lib/{exporters => exporter}/pops.nix (94%) delete mode 100644 nixos/nixosConfigurations/nixos.nix rename templates/nixos/nix/lib/{exporters.nix => exporter.nix} (96%) create mode 100644 tests/_snapshots/data create mode 100644 tests/_snapshots/nixos rename {examples/__data => tests/data/__fixture}/env.toml (100%) rename {examples/__data => tests/data/__fixture}/personal.yaml (100%) create mode 100644 tests/data/expr.nix rename {examples/nixos => tests/nixos/__fixture}/__lock/flake.lock (100%) rename {examples/nixos => tests/nixos/__fixture}/__lock/flake.nix (100%) rename {examples/nixos => tests/nixos/__fixture}/__nixosProfiles/bootstrap.nix (100%) rename {examples/nixos => tests/nixos/__fixture}/_test.nix (100%) rename {examples/nixos => tests/nixos/__fixture}/layouts.nix (52%) rename {examples/nixos => tests/nixos/__fixture}/pops/homeModules.nix (100%) rename {examples/nixos => tests/nixos/__fixture}/pops/homeProfiles.nix (100%) rename {examples/nixos => tests/nixos/__fixture}/pops/inputs.nix (95%) rename {examples/nixos => tests/nixos/__fixture}/pops/nixosModules.nix (100%) rename {examples/nixos => tests/nixos/__fixture}/pops/nixosProfiles.nix (100%) rename {examples/nixos => tests/nixos/__fixture}/pops/selfNixOSProfiles.nix (100%) rename {examples/nixos => tests/nixos/__fixture}/pops/srvos.nix (100%) create mode 100644 tests/nixos/_pops.nix create mode 100644 tests/nixos/expr.nix create mode 100644 tests/nixos/format.nix diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml index 5b44c67..9278bc0 100644 --- a/.github/workflows/checks.yaml +++ b/.github/workflows/checks.yaml @@ -16,7 +16,7 @@ jobs: - uses: DeterminateSystems/magic-nix-cache-action@main - name: Build Example/nixos - run: nix -Lv build .#nixosConfigurations.nixos.config.system.build.toplevel --dry-run + run: nix -Lv build ./local#eval.nixos.expr.nixosConfiguration.config.system.build.toplevel --dry-run - name: Run Eval check run: nix -Lv eval ./local#checks --override-input namaka github:nix-community/namaka diff --git a/examples/nixos/pops/data.nix b/examples/nixos/pops/data.nix deleted file mode 100644 index 19c125b..0000000 --- a/examples/nixos/pops/data.nix +++ /dev/null @@ -1,8 +0,0 @@ -(omnibus.pops.loadData.addLoadExtender { - loader = with haumea; [ - (matchers.regex "^(.+)\\.(yaml|yml)$" ( - _: _: path: - super.inputs.outputs.std.lib.ops.readYAML path - )) - ]; -}) diff --git a/flake.nix b/flake.nix index 5a4c6a5..44eab61 100644 --- a/flake.nix +++ b/flake.nix @@ -32,19 +32,12 @@ inherit omnibus; }; }; - - nixosConfigurations = - (self.pops.exporters.addLoadExtender { - src = ./nixos/nixosConfigurations; - inputs = { - nixpkgs = omnibus.pops.loadInputs.outputs.nixpkgs; - exporters = self.pops.exporters.outputs.default; - }; - }).outputs.default; in { - inherit (lib.outputs.default.exporters) pops; - inherit nixosConfigurations lib; + pops = lib.outputs.default.exporter.pops // { + inherit lib; + }; + lib = lib.outputs.default; templates.default = { path = ./templates/nixos; diff --git a/lib/exporters/pops.nix b/lib/exporter/pops.nix similarity index 94% rename from lib/exporters/pops.nix rename to lib/exporter/pops.nix index d49f5a3..453b14e 100644 --- a/lib/exporters/pops.nix +++ b/lib/exporter/pops.nix @@ -4,7 +4,6 @@ self'.outPath + "/local/lock" ); loadData = flops.haumea.pops.default.setInit { - src = self'.outPath + "/examples/__data"; loader = with haumea; [ matchers.json matchers.toml @@ -72,9 +71,9 @@ }; }; - exporters = flops.haumea.pops.default.setInit { + exporter = flops.haumea.pops.default.setInit { loader = with haumea; loaders.scoped; - src = self'.outPath + "/examples"; + src = self'.outPath + "/tests/nixos/__fixture"; inputs = { self' = self; inherit diff --git a/local/flake.lock b/local/flake.lock index db326ed..6d4b2c8 100755 --- a/local/flake.lock +++ b/local/flake.lock @@ -85,7 +85,7 @@ }, "devshell": { "inputs": { - "nixpkgs": "nixpkgs", + "nixpkgs": "nixpkgs_2", "systems": "systems" }, "locked": { @@ -263,7 +263,7 @@ "POP": "POP", "call-flake": "call-flake_2", "dmerge": "dmerge", - "haumea": "haumea", + "haumea": "haumea_2", "nixlib": "nixlib_2", "yants": "yants" }, @@ -282,6 +282,28 @@ } }, "haumea": { + "inputs": { + "nixpkgs": [ + "namaka", + "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" + } + }, + "haumea_2": { "inputs": { "nixpkgs": [ "std-ext", @@ -303,7 +325,7 @@ "type": "github" } }, - "haumea_2": { + "haumea_3": { "inputs": { "nixpkgs": [ "std-ext", @@ -363,6 +385,25 @@ "type": "github" } }, + "namaka": { + "inputs": { + "haumea": "haumea", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1696528717, + "narHash": "sha256-y9iQPJuIhUHojV/5yiYV68a9DaRSbHxMR2QbSdNtb/I=", + "owner": "nix-community", + "repo": "namaka", + "rev": "30a62e16535c85aa2ada2929ab7998dc2d3e5a7b", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "namaka", + "type": "github" + } + }, "nixago": { "inputs": { "flake-utils": "flake-utils", @@ -519,6 +560,22 @@ } }, "nixpkgs": { + "locked": { + "lastModified": 1688590700, + "narHash": "sha256-ZF055rIUP89cVwiLpG5xkJzx00gEuuGFF60Bs/LM3wc=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "f292b4964cb71f9dfbbd30dc9f511d6165cd109b", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { "locked": { "lastModified": 1677383253, "narHash": "sha256-UfpzWfSxkfXHnb4boXZNaKsAcUrZT9Hw+tao1oZxd08=", @@ -534,7 +591,7 @@ "type": "github" } }, - "nixpkgs_2": { + "nixpkgs_3": { "locked": { "lastModified": 1660438583, "narHash": "sha256-rJUTYxFKlWUJI3njAwEc1pKAVooAViZGJvsgqfh/q/E=", @@ -549,7 +606,7 @@ "type": "github" } }, - "nixpkgs_3": { + "nixpkgs_4": { "locked": { "lastModified": 1692190437, "narHash": "sha256-yJUZzmzSmDYb9ONPnMQDru66RjZgGQZRvj3tQebkexk=", @@ -629,7 +686,11 @@ "root": { "inputs": { "call-flake": "call-flake", - "namaka": [], + "haumea": [ + "namaka", + "haumea" + ], + "namaka": "namaka", "nixpkgs": [ "std-ext", "nixpkgs" @@ -654,7 +715,7 @@ "devshell" ], "dmerge": "dmerge_2", - "haumea": "haumea_2", + "haumea": "haumea_3", "incl": "incl", "lib": "lib", "makes": [ @@ -708,7 +769,7 @@ "devshell": "devshell", "flops": "flops", "nixago": "nixago", - "nixpkgs": "nixpkgs_3", + "nixpkgs": "nixpkgs_4", "org-roam-book-template": [], "std": "std" }, @@ -743,7 +804,7 @@ }, "yants": { "inputs": { - "nixpkgs": "nixpkgs_2" + "nixpkgs": "nixpkgs_3" }, "locked": { "lastModified": 1686863218, diff --git a/local/flake.nix b/local/flake.nix index b61bc66..fc4d1d8 100755 --- a/local/flake.nix +++ b/local/flake.nix @@ -6,7 +6,8 @@ inputs.std-ext.url = "github:gtrunsec/std-ext"; inputs.std-ext.inputs.org-roam-book-template.follows = ""; inputs.call-flake.url = "github:divnix/call-flake"; - inputs.namaka.follows = ""; + inputs.namaka.url = "github:nix-community/namaka"; + inputs.haumea.follows = "namaka/haumea"; outputs = { std, self, ... }@inputs: @@ -32,12 +33,22 @@ ] ]; } { + eval = inputs.haumea.lib.load { + src = ../tests; + inputs = omnibus.inputs // { + omnibus = omnibus; + lib = inputs.nixpkgs.lib // builtins; + inputs' = inputs; + trace = true; + }; + }; checks = inputs.namaka.lib.load { src = ../tests; inputs = omnibus.inputs // { omnibus = omnibus; - lib = inputs.nixpkgs.lib // omnibus.lib; + lib = inputs.nixpkgs.lib // builtins; inputs' = inputs; + trace = false; }; }; }; diff --git a/namaka.toml b/namaka.toml index a95d85c..ed0382f 100644 --- a/namaka.toml +++ b/namaka.toml @@ -1,20 +1,5 @@ [check] -cmd = [ - "nix", - "flake", - "check", - "./local", - "--override-input", - "namaka", - "github:nix-community/namaka" -] +cmd = ["nix", "flake", "check", "./local"] [eval] -cmd = [ - "nix", - "eval", - "./local#checks", - "--override-input", - "namaka", - "github:nix-community/namaka" -] +cmd = ["nix", "eval", "./local#checks"] diff --git a/nixos/nixosConfigurations/nixos.nix b/nixos/nixosConfigurations/nixos.nix deleted file mode 100644 index 3ce39a0..0000000 --- a/nixos/nixosConfigurations/nixos.nix +++ /dev/null @@ -1,9 +0,0 @@ -let - exporter = exporters.nixos; - system = "x86_64-linux"; -in -nixpkgs.lib.nixosSystem { - inherit system; - pkgs = import nixpkgs { inherit system; }; - modules = lib.flatten [ exporter.layouts.nixosSuites ]; -} diff --git a/templates/nixos/flake.nix b/templates/nixos/flake.nix index 691840a..70cd86c 100644 --- a/templates/nixos/flake.nix +++ b/templates/nixos/flake.nix @@ -45,7 +45,7 @@ "aarch64-darwin" ]; pops = - (inputs.omnibus.pops.exporters.addLoadExtender { + (inputs.omnibus.pops.exporter.addLoadExtender { src = ./nix/lib; inputs = { self' = self; @@ -57,7 +57,7 @@ { inherit pops; lib = pops.outputs.default; - inherit (self.lib.exporters) + inherit (self.lib.exporter) darwinConfigurations nixosConfigurations packages diff --git a/templates/nixos/nix/lib/exporters.nix b/templates/nixos/nix/lib/exporter.nix similarity index 96% rename from templates/nixos/nix/lib/exporters.nix rename to templates/nixos/nix/lib/exporter.nix index e33e6ed..7a964ec 100644 --- a/templates/nixos/nix/lib/exporters.nix +++ b/templates/nixos/nix/lib/exporter.nix @@ -8,7 +8,7 @@ let in { hosts = - (inputs.omnibus.pops.exporters.addLoadExtender { + (inputs.omnibus.pops.exporter.addLoadExtender { src = self'.outPath + "/nixos/hosts"; inputs = inputs // { self'.lib = super; diff --git a/tests/_snapshots/data b/tests/_snapshots/data new file mode 100644 index 0000000..4bea755 --- /dev/null +++ b/tests/_snapshots/data @@ -0,0 +1,2 @@ +#json +{"env":{"nixos":{"maintainer":"gtrunsec","profile":"omnibus"}},"personal":{"ssh":{"public-key":"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDLxc7EBr1Qi4M65O1KjXZf4bOBZMQ6YeDSFYzKzFan7 Desktop-guangtao-03-02-2023"}}} \ No newline at end of file diff --git a/tests/_snapshots/nixos b/tests/_snapshots/nixos new file mode 100644 index 0000000..7795c18 --- /dev/null +++ b/tests/_snapshots/nixos @@ -0,0 +1,13 @@ +#pretty +{ + bootProfile = { + speedup = true; + systemd-boot = { + enable = true; + }; + systemd-initrd = { + enable = false; + }; + }; + customModuleBootTimeOut = 10; +} \ No newline at end of file diff --git a/examples/__data/env.toml b/tests/data/__fixture/env.toml similarity index 100% rename from examples/__data/env.toml rename to tests/data/__fixture/env.toml diff --git a/examples/__data/personal.yaml b/tests/data/__fixture/personal.yaml similarity index 100% rename from examples/__data/personal.yaml rename to tests/data/__fixture/personal.yaml diff --git a/tests/data/expr.nix b/tests/data/expr.nix new file mode 100644 index 0000000..918bfc2 --- /dev/null +++ b/tests/data/expr.nix @@ -0,0 +1,10 @@ +{ omnibus, inputs' }: +let + loadDataAll = + (omnibus.pops.lib.addLoadExtender { + inputs = { + nixpkgs = inputs'.nixpkgs.legacyPackages.x86_64-linux; + }; + }).outputs.default.loadDataAll; +in +(loadDataAll.addLoadExtender { src = ./__fixture; }).outputs.default diff --git a/examples/nixos/__lock/flake.lock b/tests/nixos/__fixture/__lock/flake.lock similarity index 100% rename from examples/nixos/__lock/flake.lock rename to tests/nixos/__fixture/__lock/flake.lock diff --git a/examples/nixos/__lock/flake.nix b/tests/nixos/__fixture/__lock/flake.nix similarity index 100% rename from examples/nixos/__lock/flake.nix rename to tests/nixos/__fixture/__lock/flake.nix diff --git a/examples/nixos/__nixosProfiles/bootstrap.nix b/tests/nixos/__fixture/__nixosProfiles/bootstrap.nix similarity index 100% rename from examples/nixos/__nixosProfiles/bootstrap.nix rename to tests/nixos/__fixture/__nixosProfiles/bootstrap.nix diff --git a/examples/nixos/_test.nix b/tests/nixos/__fixture/_test.nix similarity index 100% rename from examples/nixos/_test.nix rename to tests/nixos/__fixture/_test.nix diff --git a/examples/nixos/layouts.nix b/tests/nixos/__fixture/layouts.nix similarity index 52% rename from examples/nixos/layouts.nix rename to tests/nixos/__fixture/layouts.nix index 61d9b55..122ced6 100644 --- a/examples/nixos/layouts.nix +++ b/tests/nixos/__fixture/layouts.nix @@ -1,26 +1,27 @@ let - outputs = lib.mapAttrs (_: v: v.outputs) ( + exporter = lib.mapAttrs (_: v: v.outputs) ( lib.removeAttrs super.pops [ "inputs" ] ); in { - inherit outputs; - data = outputs.data.default; + system = "x86_64-linux"; + + inherit data exporter; nixosSuites = lib.flatten [ - outputs.selfNixOSProfiles.default.bootstrap + exporter.selfNixOSProfiles.default.bootstrap # self.nixosProfiles.default.presets.boot - outputs.nixosModules.default.programs.git + exporter.nixosModules.default.programs.git # outputs.nixosModules.default.hardware.bluetooth # load a suite profile from audio # (outputs.nixosProfiles.default.audio {}).default # # --custom profiles - outputs.nixosProfiles.customProfiles.presets.nix - outputs.nixosProfiles.customProfiles.presets.boot - outputs.srvos.default.common.nix + exporter.nixosProfiles.customProfiles.presets.nix + # exporter.nixosProfiles.customProfiles.presets.boot + exporter.srvos.default.common.nix (omnibus.lib.outputs.default.mkHome { @@ -37,10 +38,20 @@ in ]; homeSuites = [ - outputs.homeProfiles.customProfiles.presets.hyprland - outputs.homeProfiles.default.presets.bat + exporter.homeProfiles.customProfiles.presets.hyprland + exporter.homeProfiles.default.presets.bat # # The parent directory of "presets" is categorized as a list type of "suites" - (outputs.homeProfiles.default.shell { }).default + (exporter.homeProfiles.default.shell { }).default # super.pops.homeModules.outputs.default.wayland.windowManager.hyprland ]; + + nixosConfiguration = + module: + nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = lib.flatten [ + self.nixosSuites + module + ]; + }; } diff --git a/examples/nixos/pops/homeModules.nix b/tests/nixos/__fixture/pops/homeModules.nix similarity index 100% rename from examples/nixos/pops/homeModules.nix rename to tests/nixos/__fixture/pops/homeModules.nix diff --git a/examples/nixos/pops/homeProfiles.nix b/tests/nixos/__fixture/pops/homeProfiles.nix similarity index 100% rename from examples/nixos/pops/homeProfiles.nix rename to tests/nixos/__fixture/pops/homeProfiles.nix diff --git a/examples/nixos/pops/inputs.nix b/tests/nixos/__fixture/pops/inputs.nix similarity index 95% rename from examples/nixos/pops/inputs.nix rename to tests/nixos/__fixture/pops/inputs.nix index abfdbdb..8890358 100644 --- a/examples/nixos/pops/inputs.nix +++ b/tests/nixos/__fixture/pops/inputs.nix @@ -13,4 +13,4 @@ } ) )).setSystem - "x86_64-linux" + root.layouts.system diff --git a/examples/nixos/pops/nixosModules.nix b/tests/nixos/__fixture/pops/nixosModules.nix similarity index 100% rename from examples/nixos/pops/nixosModules.nix rename to tests/nixos/__fixture/pops/nixosModules.nix diff --git a/examples/nixos/pops/nixosProfiles.nix b/tests/nixos/__fixture/pops/nixosProfiles.nix similarity index 100% rename from examples/nixos/pops/nixosProfiles.nix rename to tests/nixos/__fixture/pops/nixosProfiles.nix diff --git a/examples/nixos/pops/selfNixOSProfiles.nix b/tests/nixos/__fixture/pops/selfNixOSProfiles.nix similarity index 100% rename from examples/nixos/pops/selfNixOSProfiles.nix rename to tests/nixos/__fixture/pops/selfNixOSProfiles.nix diff --git a/examples/nixos/pops/srvos.nix b/tests/nixos/__fixture/pops/srvos.nix similarity index 100% rename from examples/nixos/pops/srvos.nix rename to tests/nixos/__fixture/pops/srvos.nix diff --git a/tests/nixos/_pops.nix b/tests/nixos/_pops.nix new file mode 100644 index 0000000..cef2eca --- /dev/null +++ b/tests/nixos/_pops.nix @@ -0,0 +1,12 @@ +{ + omnibus, + root, + inputs', +}: +(omnibus.pops.exporter.addLoadExtender { + src = ./__fixture; + inputs = { + data = root.data; + nixpkgs = inputs'.nixpkgs; + }; +}) diff --git a/tests/nixos/expr.nix b/tests/nixos/expr.nix new file mode 100644 index 0000000..c4c9275 --- /dev/null +++ b/tests/nixos/expr.nix @@ -0,0 +1,28 @@ +{ + super, + trace, + lib, +}: +let + exporter = super.pops.outputs.default; +in +{ + bootProfile = + (exporter.layouts.nixosConfiguration [ + exporter.layouts.exporter.nixosProfiles.customProfiles.presets.boot + ]).config.boot.__profiles__; + + customModuleBootTimeOut = + (exporter.layouts.nixosConfiguration [ + exporter.layouts.exporter.nixosModules.customModules.boot + { + config.boot.__profiles__.speedup = true; + config.boot.__profiles__.systemd-boot.enable = true; + } + ]).config.boot.loader.timeout; +} +// lib.optionalAttrs trace { + nixosConfiguration = exporter.layouts.nixosConfiguration [ + exporter.layouts.exporter.nixosProfiles.customProfiles.presets.boot + ]; +} diff --git a/tests/nixos/format.nix b/tests/nixos/format.nix new file mode 100644 index 0000000..f9e1770 --- /dev/null +++ b/tests/nixos/format.nix @@ -0,0 +1 @@ +"pretty"