From 079ba71bab201efe074f329d40755f4b9b00e5e8 Mon Sep 17 00:00:00 2001 From: Hao Date: Sun, 23 Jun 2024 20:23:29 +1000 Subject: [PATCH] fix: Move test to example --- .gitignore | 3 +- {nix => example}/cargo-doc-live/Cargo.lock | 2 +- example/cargo-doc-live/Cargo.toml | 2 + example/cargo-doc-live/flake.lock | 106 ++++++++++++++++++ example/cargo-doc-live/flake.nix | 44 ++++++++ {nix => example}/cargo-doc-live/src/main.rs | 0 .../default.nix => cargo-doc-live.nix} | 7 +- nix/cargo-doc-live/Cargo.toml | 2 - nix/cargo-doc-live/cargo-doc-live_test.nix | 18 --- nix/default.nix | 2 +- test/flake.nix | 1 - 11 files changed, 161 insertions(+), 26 deletions(-) rename {nix => example}/cargo-doc-live/Cargo.lock (89%) create mode 100644 example/cargo-doc-live/Cargo.toml create mode 100644 example/cargo-doc-live/flake.lock create mode 100644 example/cargo-doc-live/flake.nix rename {nix => example}/cargo-doc-live/src/main.rs (100%) rename nix/{cargo-doc-live/default.nix => cargo-doc-live.nix} (93%) delete mode 100644 nix/cargo-doc-live/Cargo.toml delete mode 100644 nix/cargo-doc-live/cargo-doc-live_test.nix diff --git a/.gitignore b/.gitignore index 5bfded21..b7fc8477 100644 --- a/.gitignore +++ b/.gitignore @@ -4,11 +4,10 @@ # created when `just run ` is used /test/data -/nix/cargo-doc-live/target - # created when `just run ex-*` is used /example/share-services/pgweb/data/ /example/simple/data/ /example/grafana-tempo/data/ +/example/cargo-doc-live/target /.pre-commit-config.yaml diff --git a/nix/cargo-doc-live/Cargo.lock b/example/cargo-doc-live/Cargo.lock similarity index 89% rename from nix/cargo-doc-live/Cargo.lock rename to example/cargo-doc-live/Cargo.lock index a56d7e2c..33b959e2 100644 --- a/nix/cargo-doc-live/Cargo.lock +++ b/example/cargo-doc-live/Cargo.lock @@ -3,5 +3,5 @@ version = 3 [[package]] -name = "simple" +name = "test" version = "0.0.0" diff --git a/example/cargo-doc-live/Cargo.toml b/example/cargo-doc-live/Cargo.toml new file mode 100644 index 00000000..40392766 --- /dev/null +++ b/example/cargo-doc-live/Cargo.toml @@ -0,0 +1,2 @@ +[package] +name = "test" diff --git a/example/cargo-doc-live/flake.lock b/example/cargo-doc-live/flake.lock new file mode 100644 index 00000000..e253a45b --- /dev/null +++ b/example/cargo-doc-live/flake.lock @@ -0,0 +1,106 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1717285511, + "narHash": "sha256-iKzJcpdXih14qYVcZ9QC9XuZYnPc6T8YImb6dX166kw=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "2a55567fcf15b1b1c7ed712a2c6fadaec7412ea8", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1719082008, + "narHash": "sha256-jHJSUH619zBQ6WdC21fFAlDxHErKVDJ5fpN0Hgx4sjs=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "9693852a2070b398ee123a329e68f0dab5526681", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1717284937, + "narHash": "sha256-lIbdfCsf8LMFloheeE6N31+BMIeixqyQWbSr2vk79EQ=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/eb9ceca17df2ea50a250b6b27f7bf6ab0186f198.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/eb9ceca17df2ea50a250b6b27f7bf6ab0186f198.tar.gz" + } + }, + "process-compose-flake": { + "locked": { + "lastModified": 1718031437, + "narHash": "sha256-+RrlkAVZx0QhyeHAGFJnjST+/7Dc3zsDU3zAKXoDXaI=", + "owner": "Platonic-Systems", + "repo": "process-compose-flake", + "rev": "9344fac44edced4c686721686a6ad904d067c546", + "type": "github" + }, + "original": { + "owner": "Platonic-Systems", + "repo": "process-compose-flake", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "process-compose-flake": "process-compose-flake", + "services-flake": "services-flake", + "systems": "systems" + } + }, + "services-flake": { + "locked": { + "lastModified": 1719102528, + "narHash": "sha256-wLoHpUJXVELcnFh7XgJ9m4q1Hu8WgGfrZQQHpS5eRcM=", + "owner": "juspay", + "repo": "services-flake", + "rev": "641937bc0f523405fbac4bb89c074de613dcee4d", + "type": "github" + }, + "original": { + "owner": "juspay", + "repo": "services-flake", + "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" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/example/cargo-doc-live/flake.nix b/example/cargo-doc-live/flake.nix new file mode 100644 index 00000000..069f73bb --- /dev/null +++ b/example/cargo-doc-live/flake.nix @@ -0,0 +1,44 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; + systems.url = "github:nix-systems/default"; + process-compose-flake.url = "github:Platonic-Systems/process-compose-flake"; + services-flake.url = "github:juspay/services-flake"; + }; + outputs = inputs: + inputs.flake-parts.lib.mkFlake { inherit inputs; } { + systems = import inputs.systems; + imports = [ + inputs.process-compose-flake.flakeModule + ]; + perSystem = { self', pkgs, lib, ... }: { + # `process-compose.foo` will add a flake package output called "foo". + # Therefore, this will add a default package that you can build using + # `nix build` and run using `nix run`. + process-compose."default" = { ... }: + { + imports = [ + inputs.services-flake.processComposeModules.default + ]; + + services.cargo-doc-live."cargo-doc-live1" = { + src = ./.; + enable = true; + port = 8009; + }; + + settings.processes.test = { + command = pkgs.writeShellApplication { + name = "cargo-doc-live-test"; + runtimeInputs = [ pkgs.curl ]; + text = '' + curl http://127.0.0.1:8009/test + ''; + }; + depends_on."cargo-doc-live1".condition = "process_healthy"; + }; + }; + }; + }; +} diff --git a/nix/cargo-doc-live/src/main.rs b/example/cargo-doc-live/src/main.rs similarity index 100% rename from nix/cargo-doc-live/src/main.rs rename to example/cargo-doc-live/src/main.rs diff --git a/nix/cargo-doc-live/default.nix b/nix/cargo-doc-live.nix similarity index 93% rename from nix/cargo-doc-live/default.nix rename to nix/cargo-doc-live.nix index dd474c98..e777902f 100644 --- a/nix/cargo-doc-live/default.nix +++ b/nix/cargo-doc-live.nix @@ -6,6 +6,11 @@ in options = { enable = lib.mkEnableOption name; + src = lib.mkOption { + type = types.path; + description = "The src of the cargo"; + }; + port = lib.mkOption { type = types.port; description = "The port for 'cargo doc'"; @@ -16,7 +21,7 @@ in type = types.str; description = "The crate to use when opening docs in browser"; default = builtins.replaceStrings [ "-" ] [ "_" ] - ((lib.trivial.importTOML ./Cargo.toml).package.name); + ((lib.trivial.importTOML "${config.src}/Cargo.toml").package.name); defaultText = "The crate name is derived from the Cargo.toml file"; }; diff --git a/nix/cargo-doc-live/Cargo.toml b/nix/cargo-doc-live/Cargo.toml deleted file mode 100644 index f6ae897e..00000000 --- a/nix/cargo-doc-live/Cargo.toml +++ /dev/null @@ -1,2 +0,0 @@ -[package] -name = "simple" diff --git a/nix/cargo-doc-live/cargo-doc-live_test.nix b/nix/cargo-doc-live/cargo-doc-live_test.nix deleted file mode 100644 index eb51c6a4..00000000 --- a/nix/cargo-doc-live/cargo-doc-live_test.nix +++ /dev/null @@ -1,18 +0,0 @@ -{ pkgs, ... }: { - services.cargo-doc-live."cargo-doc-live1" = { - enable = true; - crateName = "simple"; - }; - - settings.processes.test = - { - command = pkgs.writeShellApplication { - runtimeInputs = [ pkgs.curl ]; - text = '' - curl http://127.0.0.1:8008/simple - ''; - name = "cargo-doc-live-test"; - }; - depends_on."cargo-doc-live1".condition = "process_healthy"; - }; -} diff --git a/nix/default.nix b/nix/default.nix index 3828370d..45e89d24 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -22,6 +22,6 @@ in ./tempo.nix ./weaviate.nix ./searxng.nix - ./cargo-doc-live + ./cargo-doc-live.nix ]; } diff --git a/test/flake.nix b/test/flake.nix index fce64adf..1b8386f6 100644 --- a/test/flake.nix +++ b/test/flake.nix @@ -49,7 +49,6 @@ "${inputs.services-flake}/nix/cassandra_test.nix" "${inputs.services-flake}/nix/tempo_test.nix" "${inputs.services-flake}/nix/weaviate_test.nix" - "${inputs.services-flake}/nix/cargo-doc-live/cargo-doc-live_test.nix" ] ++ lib.optionals pkgs.stdenv.isLinux [ # Broken on Darwin: https://github.com/NixOS/nixpkgs/issues/316954 "${inputs.services-flake}/nix/grafana_test.nix"