🏡 index : ~doyle/titanirc.git

author Jordan Doyle <jordan@doyle.la> 2023-01-07 23:08:01.0 +00:00:00
committer Jordan Doyle <jordan@doyle.la> 2023-01-07 23:11:26.0 +00:00:00
commit
fb2e694c2f8aad2ba8e15905e247570f63537d06 [patch]
tree
7a0f5d9fbab2173b557ffc2b9664fbb795477475
parent
f43a9c0034fe8d9b8dda490eae6b8139251f73ba
download
fb2e694c2f8aad2ba8e15905e247570f63537d06.tar.gz

Add flake.nix



Diff

 .cargo/audit.toml |   9 ++++-
 .gitignore        |   1 +-
 README.md         |   8 +++-
 flake.lock        | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 flake.nix         | 107 ++++++++++++++++++++++++++++++++++++++++++-
 src/client.rs     |   1 +-
 6 files changed, 266 insertions(+)

diff --git a/.cargo/audit.toml b/.cargo/audit.toml
new file mode 100644
index 0000000..dcb6baf
--- /dev/null
+++ b/.cargo/audit.toml
@@ -0,0 +1,9 @@
[advisories]
# advisory IDs to ignore e.g. ["RUSTSEC-2019-0001", ...]
ignore = [
    # potential segfault when using `chrono::Local::now()`, which we don't use
    "RUSTSEC-2020-0159",
    # similar to `RUSTSEC-2020-0159` but in the `time` crate. we don't use local times,
    # preferring UTC everywhere so we're unaffected by this
    "RUSTSEC-2020-0071"
]
diff --git a/.gitignore b/.gitignore
index c403c34..d3e5a9a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
/target
.idea/
/result
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..e39e1b1
--- /dev/null
+++ b/README.md
@@ -0,0 +1,8 @@
# titanircd

A modern take on an IRC server, built from the ground up in Rust
against the [IRCv3 spec].

All clients require authentication, and bouncers are built-in.

[IRCv3 spec]: https://modern.ircdocs.horse/
\ No newline at end of file
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 0000000..32cdb95
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,140 @@
{
  "nodes": {
    "advisory-db": {
      "flake": false,
      "locked": {
        "lastModified": 1672138084,
        "narHash": "sha256-x+q6lNmmzr+y/XBRy0fg9oYDqg0r/zQ+8Uiikx4osh8=",
        "owner": "rustsec",
        "repo": "advisory-db",
        "rev": "6d5b76eb3be175fd2101b83140df15673531bb7b",
        "type": "github"
      },
      "original": {
        "owner": "rustsec",
        "repo": "advisory-db",
        "type": "github"
      }
    },
    "crane": {
      "inputs": {
        "flake-compat": "flake-compat",
        "flake-utils": "flake-utils",
        "nixpkgs": [
          "nixpkgs"
        ],
        "rust-overlay": "rust-overlay"
      },
      "locked": {
        "lastModified": 1673056065,
        "narHash": "sha256-a68tMDTDqdAauxq377ALl4Uwm6oh9MeoY2WbTYRWZoo=",
        "owner": "ipetkov",
        "repo": "crane",
        "rev": "0144134311767fcee80213321f079a8ffa0b9cc1",
        "type": "github"
      },
      "original": {
        "owner": "ipetkov",
        "repo": "crane",
        "type": "github"
      }
    },
    "flake-compat": {
      "flake": false,
      "locked": {
        "lastModified": 1668681692,
        "narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=",
        "owner": "edolstra",
        "repo": "flake-compat",
        "rev": "009399224d5e398d03b22badca40a37ac85412a1",
        "type": "github"
      },
      "original": {
        "owner": "edolstra",
        "repo": "flake-compat",
        "type": "github"
      }
    },
    "flake-utils": {
      "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"
      }
    },
    "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"
      }
    },
    "nixpkgs": {
      "locked": {
        "lastModified": 1672997035,
        "narHash": "sha256-DNaNjsGMRYefBTAxFIrVOB2ok477cj1FTpqnu/mKRf4=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "f1ffcf798e93b169321106a4aef79526a2b4bd0a",
        "type": "github"
      },
      "original": {
        "owner": "NixOS",
        "ref": "nixpkgs-unstable",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
    "root": {
      "inputs": {
        "advisory-db": "advisory-db",
        "crane": "crane",
        "flake-utils": "flake-utils_2",
        "nixpkgs": "nixpkgs"
      }
    },
    "rust-overlay": {
      "inputs": {
        "flake-utils": [
          "crane",
          "flake-utils"
        ],
        "nixpkgs": [
          "crane",
          "nixpkgs"
        ]
      },
      "locked": {
        "lastModified": 1672712534,
        "narHash": "sha256-8S0DdMPcbITnlOu0uA81mTo3hgX84wK8S9wS34HEFY4=",
        "owner": "oxalica",
        "repo": "rust-overlay",
        "rev": "69fb7bf0a8c40e6c4c197fa1816773774c8ac59f",
        "type": "github"
      },
      "original": {
        "owner": "oxalica",
        "repo": "rust-overlay",
        "type": "github"
      }
    }
  },
  "root": "root",
  "version": 7
}
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..b1e5b92
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,107 @@
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

    crane = {
      url = "github:ipetkov/crane";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    flake-utils.url = "github:numtide/flake-utils";

    advisory-db = {
      url = "github:rustsec/advisory-db";
      flake = false;
    };
  };

  outputs = { self, nixpkgs, crane, flake-utils, advisory-db, ... }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          inherit system;
        };

        inherit (pkgs) lib;

        craneLib = crane.lib.${system};
        src = craneLib.cleanCargoSource ./.;

        buildInputs = [
        ] ++ lib.optionals pkgs.stdenv.isDarwin [
          pkgs.libiconv
        ];

        # Build *just* the cargo dependencies, so we can reuse
        # all of that work (e.g. via cachix) when running in CI
        cargoArtifacts = craneLib.buildDepsOnly {
          inherit src buildInputs;
        };

        # Build the actual crate itself, reusing the dependency
        # artifacts from above.
        titanircd = craneLib.buildPackage {
          inherit cargoArtifacts src buildInputs;
        };
      in
      {
        checks = {
          # Build the crate as part of `nix flake check` for convenience
          inherit titanircd;

          # Run clippy (and deny all warnings) on the crate source,
          # again, resuing the dependency artifacts from above.
          #
          # Note that this is done as a separate derivation so that
          # we can block the CI if there are issues here, but not
          # prevent downstream consumers from building our crate by itself.
          titanircd-clippy = craneLib.cargoClippy {
            inherit cargoArtifacts src buildInputs;
            cargoClippyExtraArgs = "--all-targets -- --deny warnings";
          };

          titanircd-doc = craneLib.cargoDoc {
            inherit cargoArtifacts src buildInputs;
          };

          # Check formatting
          titanircd-fmt = craneLib.cargoFmt {
            inherit src;
          };

          # Audit dependencies
          titanircd-audit = craneLib.cargoAudit {
            inherit src advisory-db;
          };

          # Run tests with cargo-nextest
          titanircd-nextest = craneLib.cargoNextest {
            inherit cargoArtifacts src buildInputs;
            partitions = 1;
            partitionType = "count";
          };
        } // lib.optionalAttrs (system == "x86_64-linux") {
          # NB: cargo-tarpaulin only supports x86_64 systems
          # Check code coverage (note: this will not upload coverage anywhere)
          titanircd-coverage = craneLib.cargoTarpaulin {
            inherit cargoArtifacts src;
          };
        };

        packages.default = titanircd;

        apps.default = flake-utils.lib.mkApp {
          drv = titanircd;
        };

        devShells.default = pkgs.mkShell {
          inputsFrom = builtins.attrValues self.checks;

          # Extra inputs can be added here
          nativeBuildInputs = with pkgs; [
            cargo
            rustc
          ];
        };
      });
}
diff --git a/src/client.rs b/src/client.rs
index 20451da..14924fe 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -504,6 +504,7 @@ impl StreamHandler<Result<irc_proto::Message, ProtocolError>> for Client {
    }
}

#[must_use]
pub fn parse_channel_name_list(s: &str) -> Vec<String> {
    s.split(',')
        .filter(|v| !v.is_empty())