Initial commit.
Reqwest and tokio compile.
This commit is contained in:
commit
00c68d2a86
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
target
|
1156
Cargo.lock
generated
Normal file
1156
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
11
Cargo.toml
Normal file
11
Cargo.toml
Normal file
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "catscii"
|
||||
version = "0.1.0"
|
||||
authors = ["Amos Wenger <amos@fasterthanli.me>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
reqwest = { version = "0.11", features = ["json"] }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
|
||||
[dev-dependencies]
|
42
flake.lock
Normal file
42
flake.lock
Normal file
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
"nodes": {
|
||||
"import-cargo": {
|
||||
"locked": {
|
||||
"lastModified": 1594305518,
|
||||
"narHash": "sha256-frtArgN42rSaEcEOYWg8sVPMUK+Zgch3c+wejcpX3DY=",
|
||||
"owner": "edolstra",
|
||||
"repo": "import-cargo",
|
||||
"rev": "25d40be4a73d40a2572e0cc233b83253554f06c5",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "edolstra",
|
||||
"repo": "import-cargo",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1683928319,
|
||||
"narHash": "sha256-maz0DRKixJVcNRMiAMWlJniiF8IuQ+WbfmlJJ8D+jfM=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "9656e85a15a0fe67847ee8cdb99a20d8df499962",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"ref": "nixos-22.11",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"import-cargo": "import-cargo",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
131
flake.nix
Normal file
131
flake.nix
Normal file
|
@ -0,0 +1,131 @@
|
|||
{
|
||||
description = "A cat-printing web server including a NixOS module";
|
||||
|
||||
# Nixpkgs / NixOS version to use.
|
||||
inputs.nixpkgs.url = "nixpkgs/nixos-22.11";
|
||||
|
||||
inputs.import-cargo.url = github:edolstra/import-cargo;
|
||||
|
||||
outputs = { self, nixpkgs, import-cargo }:
|
||||
let
|
||||
|
||||
# to work with older version of flakes
|
||||
lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101";
|
||||
|
||||
# Generate a user-friendly version number.
|
||||
version = "${builtins.substring 0 8 lastModifiedDate}-${self.shortRev or "dirty"}";
|
||||
|
||||
# System types to support.
|
||||
supportedSystems = [ "x86_64-linux" ];
|
||||
|
||||
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
|
||||
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);
|
||||
|
||||
# Nixpkgs instantiated for supported system types.
|
||||
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; overlays = [ self.overlay ]; });
|
||||
|
||||
in {
|
||||
|
||||
# A Nixpkgs overlay.
|
||||
overlay = final: prev: {
|
||||
|
||||
catscii = with final; final.callPackage ({ inShell ? false }: stdenv.mkDerivation rec {
|
||||
name = "catscii-${version}";
|
||||
|
||||
# In 'nix develop', we don't need a copy of the source tree
|
||||
# in the Nix store.
|
||||
src = if inShell then null else ./.;
|
||||
|
||||
buildInputs =
|
||||
[ rustc
|
||||
cargo
|
||||
openssl
|
||||
pkg-config
|
||||
] ++ (if inShell then [
|
||||
# In 'nix develop', provide some developer tools.
|
||||
rust-analyzer
|
||||
rustfmt
|
||||
clippy
|
||||
] else [
|
||||
(import-cargo.builders.importCargo {
|
||||
lockFile = ./Cargo.lock;
|
||||
inherit pkgs;
|
||||
}).cargoHome
|
||||
]);
|
||||
|
||||
target = "--release";
|
||||
|
||||
buildPhase = "cargo build ${target} --frozen --offline";
|
||||
|
||||
doCheck = true;
|
||||
|
||||
checkPhase = "cargo test ${target} --frozen --offline";
|
||||
|
||||
installPhase =
|
||||
''
|
||||
mkdir -p $out
|
||||
cargo install --frozen --offline --path . --root $out
|
||||
rm $out/.crates.toml
|
||||
'';
|
||||
}) {};
|
||||
|
||||
};
|
||||
|
||||
# Provide some binary packages for selected system types.
|
||||
packages = forAllSystems (system:
|
||||
{
|
||||
inherit (nixpkgsFor.${system}) catscii;
|
||||
});
|
||||
|
||||
# The default package for 'nix build'. This makes sense if the
|
||||
# flake provides only one package or there is a clear "main"
|
||||
# package.
|
||||
defaultPackage = forAllSystems (system: self.packages.${system}.catscii);
|
||||
|
||||
# Provide a 'nix develop' environment for interactive hacking.
|
||||
devShell = forAllSystems (system: self.packages.${system}.catscii.override { inShell = true; });
|
||||
|
||||
# A NixOS module.
|
||||
nixosModules.catscii =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
nixpkgs.overlays = [ self.overlay ];
|
||||
|
||||
systemd.services.catscii = {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
serviceConfig.ExecStart = "${pkgs.catscii}/bin/catscii";
|
||||
};
|
||||
};
|
||||
|
||||
# Tests run by 'nix flake check' and by Hydra.
|
||||
checks = forAllSystems
|
||||
(system:
|
||||
with nixpkgsFor.${system};
|
||||
|
||||
{
|
||||
inherit (self.packages.${system}) catscii;
|
||||
|
||||
# A VM test of the NixOS module.
|
||||
vmTest =
|
||||
with import (nixpkgs + "/nixos/lib/testing-python.nix") {
|
||||
inherit system;
|
||||
};
|
||||
|
||||
makeTest {
|
||||
nodes = {
|
||||
client = { ... }: {
|
||||
imports = [ self.nixosModules.catscii ];
|
||||
};
|
||||
};
|
||||
|
||||
testScript =
|
||||
''
|
||||
start_all()
|
||||
client.wait_for_unit("multi-user.target")
|
||||
assert "Hello Nixers" in client.wait_until_succeeds("curl --fail http://localhost:8080/")
|
||||
'';
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
4
src/main.rs
Normal file
4
src/main.rs
Normal file
|
@ -0,0 +1,4 @@
|
|||
#[tokio::main]
|
||||
async fn main() {
|
||||
println!("Meow!");
|
||||
}
|
Loading…
Reference in a new issue