diff options
| author | Max Audron <audron@cocaine.farm> | 2024-08-12 14:59:47 +0200 |
|---|---|---|
| committer | Max Audron <audron@cocaine.farm> | 2024-08-12 16:52:25 +0200 |
| commit | d212b916c3953d52e47b0a89890b6bf52dec7591 (patch) | |
| tree | 669208bb0ec4bb1ca0e94faea3866120fdc16688 | |
| parent | remove jsonnet lock file (diff) | |
add nix build and module
| -rw-r--r-- | .gitlab-ci.yml | 8 | ||||
| -rw-r--r-- | Cargo.lock | 2 | ||||
| -rw-r--r-- | flake.lock | 252 | ||||
| -rw-r--r-- | flake.nix | 75 | ||||
| -rw-r--r-- | nix/nixos-module.nix | 95 |
5 files changed, 427 insertions, 5 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 409afdf..68be8eb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,9 +1,9 @@ --- include: - - project: "cocainefarm/templates/ci" - file: "/rust.yaml" - - project: "cocainefarm/templates/ci" - file: "/tanka.base.yaml" + # - project: "cocainefarm/templates/ci" + # file: "/rust.yaml" + # - project: "cocainefarm/templates/ci" + # file: "/tanka.base.yaml" variables: RUST_RELEASE: "true" @@ -133,7 +133,7 @@ checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" [[package]] name = "catinator" -version = "1.6.4" +version = "1.6.5" dependencies = [ "anyhow", "async-trait", diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..bbf148c --- /dev/null +++ b/flake.lock @@ -0,0 +1,252 @@ +{ + "nodes": { + "crane": { + "flake": false, + "locked": { + "lastModified": 1699217310, + "narHash": "sha256-xpW3VFUG7yE6UE6Wl0dhqencuENSkV7qpnpe9I8VbPw=", + "owner": "ipetkov", + "repo": "crane", + "rev": "d535642bbe6f377077f7c23f0febb78b1463f449", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "ref": "v0.15.0", + "repo": "crane", + "type": "github" + } + }, + "dream2nix": { + "inputs": { + "nixpkgs": [ + "nci", + "nixpkgs" + ], + "purescript-overlay": "purescript-overlay", + "pyproject-nix": "pyproject-nix" + }, + "locked": { + "lastModified": 1722526955, + "narHash": "sha256-fFS8aDnfK9Qfm2FLnQ8pqWk8FzvFEv5LvTuZTZLREnc=", + "owner": "nix-community", + "repo": "dream2nix", + "rev": "3fd4c14d3683baac8d1f94286ae14fe160888b51", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "dream2nix", + "type": "github" + } + }, + "mk-naked-shell": { + "flake": false, + "locked": { + "lastModified": 1681286841, + "narHash": "sha256-3XlJrwlR0nBiREnuogoa5i1b4+w/XPe0z8bbrJASw0g=", + "owner": "yusdacra", + "repo": "mk-naked-shell", + "rev": "7612f828dd6f22b7fb332cc69440e839d7ffe6bd", + "type": "github" + }, + "original": { + "owner": "yusdacra", + "repo": "mk-naked-shell", + "type": "github" + } + }, + "nci": { + "inputs": { + "crane": "crane", + "dream2nix": "dream2nix", + "mk-naked-shell": "mk-naked-shell", + "nixpkgs": [ + "nixpkgs" + ], + "parts": "parts", + "rust-overlay": "rust-overlay", + "treefmt": "treefmt" + }, + "locked": { + "lastModified": 1723443288, + "narHash": "sha256-bP60+yYZsDttnQINxWVJHH3+kS4MkLBbJzwIL61knTY=", + "owner": "yusdacra", + "repo": "nix-cargo-integration", + "rev": "00702704ffd937a3cd2eafb80947a31f2c63cec5", + "type": "github" + }, + "original": { + "owner": "yusdacra", + "repo": "nix-cargo-integration", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1723282977, + "narHash": "sha256-oTK91aOlA/4IsjNAZGMEBz7Sq1zBS0Ltu4/nIQdYDOg=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "a781ff33ae258bbcfd4ed6e673860c3e923bf2cc", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "parts": { + "inputs": { + "nixpkgs-lib": [ + "nci", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1722555600, + "narHash": "sha256-XOQkdLafnb/p9ij77byFQjDf5m5QYl9b2REiVClC+x4=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "8471fe90ad337a8074e957b69ca4d0089218391d", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "parts_2": { + "inputs": { + "nixpkgs-lib": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1722555600, + "narHash": "sha256-XOQkdLafnb/p9ij77byFQjDf5m5QYl9b2REiVClC+x4=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "8471fe90ad337a8074e957b69ca4d0089218391d", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "purescript-overlay": { + "inputs": { + "nixpkgs": [ + "nci", + "dream2nix", + "nixpkgs" + ], + "slimlock": "slimlock" + }, + "locked": { + "lastModified": 1696022621, + "narHash": "sha256-eMjFmsj2G1E0Q5XiibUNgFjTiSz0GxIeSSzzVdoN730=", + "owner": "thomashoneyman", + "repo": "purescript-overlay", + "rev": "047c7933abd6da8aa239904422e22d190ce55ead", + "type": "github" + }, + "original": { + "owner": "thomashoneyman", + "repo": "purescript-overlay", + "type": "github" + } + }, + "pyproject-nix": { + "flake": false, + "locked": { + "lastModified": 1702448246, + "narHash": "sha256-hFg5s/hoJFv7tDpiGvEvXP0UfFvFEDgTdyHIjDVHu1I=", + "owner": "davhau", + "repo": "pyproject.nix", + "rev": "5a06a2697b228c04dd2f35659b4b659ca74f7aeb", + "type": "github" + }, + "original": { + "owner": "davhau", + "ref": "dream2nix", + "repo": "pyproject.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "nci": "nci", + "nixpkgs": "nixpkgs", + "parts": "parts_2" + } + }, + "rust-overlay": { + "flake": false, + "locked": { + "lastModified": 1723429325, + "narHash": "sha256-4x/32xTCd+xCwFoI/kKSiCr5LQA2ZlyTRYXKEni5HR8=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "65e3dc0fe079fe8df087cd38f1fe6836a0373aad", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "slimlock": { + "inputs": { + "nixpkgs": [ + "nci", + "dream2nix", + "purescript-overlay", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1688610262, + "narHash": "sha256-Wg0ViDotFWGWqKIQzyYCgayeH8s4U1OZcTiWTQYdAp4=", + "owner": "thomashoneyman", + "repo": "slimlock", + "rev": "b5c6cdcaf636ebbebd0a1f32520929394493f1a6", + "type": "github" + }, + "original": { + "owner": "thomashoneyman", + "repo": "slimlock", + "type": "github" + } + }, + "treefmt": { + "inputs": { + "nixpkgs": [ + "nci", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1723402464, + "narHash": "sha256-xjunKUFQs9D7u0TpVoXhrRYb4tbVkutRoFUHj0lEydE=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "c9f97032be6816fa234f24803b8ae79dc7753a91", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..1d0b640 --- /dev/null +++ b/flake.nix @@ -0,0 +1,75 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; + nci.url = "github:yusdacra/nix-cargo-integration"; + nci.inputs.nixpkgs.follows = "nixpkgs"; + parts.url = "github:hercules-ci/flake-parts"; + parts.inputs.nixpkgs-lib.follows = "nixpkgs"; + }; + + outputs = + inputs@{ self, parts, nci, ... }: + parts.lib.mkFlake { inherit inputs; } ({moduleWithSystem, withSystem, ...}: { + systems = [ + "x86_64-linux" + "aarch64-linux" + ]; + imports = [ nci.flakeModule ]; + + flake = { + # nixosModules.default = flake-parts-lib.importApply ./nix/nixos-module.nix { localFlake = self; inherit withSystem; }; + nixosModules.default = moduleWithSystem ( + perSystem@{ config }: # NOTE: only explicit params will be in perSystem + nixos@{ ... }: + { + services.catinator.package = perSystem.config.packages.default; + imports = [ ./nix/nixos-module.nix ]; + } + ); + }; + + perSystem = + { + pkgs, + config, + lib, + ... + }: + let + # shorthand for accessing this crate's outputs + # you can access crate outputs under `config.nci.outputs.<crate name>` (see documentation) + crateOutputs = config.nci.outputs."catinator"; + in + { + nci = { + projects."catinator".path = ./.; + crates."catinator" = + let + mkDerivation = { + nativeBuildInputs = [ pkgs.file.dev ]; + }; + in + { + drvConfig = { + inherit mkDerivation; + }; + depsDrvConfig = { + inherit mkDerivation; + }; + }; + + toolchainConfig = { + channel = "stable"; + targets = [ "x86_64-unknown-linux-musl" ]; + components = [ + "rustfmt" + "rust-src" + ]; + }; + }; + + devShells.default = crateOutputs.devShell; + packages.default = crateOutputs.packages.release; + }; + }); +} diff --git a/nix/nixos-module.nix b/nix/nixos-module.nix new file mode 100644 index 0000000..286d3bc --- /dev/null +++ b/nix/nixos-module.nix @@ -0,0 +1,95 @@ +{ lib, config, pkgs, ... }: + +let + cfg = config.services.catinator; + toml = pkgs.formats.toml { }; + configFile = toml.generate "config.toml" cfg.settings; +in + +with lib; +{ + options = { + services.catinator = { + package = mkOption { + defaultText = lib.literalMD "`packages.default` from the catinator flake"; + }; + + extraEnvironment = mkOption { + type = types.attrsOf types.str; + description = "Extra environment variables to pass to the Garage server."; + default = { }; + example = { RUST_BACKTRACE = "yes"; }; + }; + + environmentFile = mkOption { + type = types.nullOr types.path; + description = "File containing environment variables to be passed to the Garage server."; + default = null; + }; + + logLevel = mkOption { + type = types.enum ([ "error" "warn" "info" "debug" "trace" ]); + default = "info"; + example = "debug"; + }; + + settings = mkOption { + type = types.submodule { + freeformType = toml.type; + }; + }; + }; + }; + + config = { + services.catinator.settings = { + default = { + user = { + username = lib.mkDefault "catinator"; + realname = lib.mkDefault "moaw"; + }; + + server = { + hostname = lib.mkDefault ""; + port = lib.mkDefault 6697; + tls = lib.mkDefault true; + sasl = lib.mkDefault true; + }; + + settings = { + prefix = lib.mkDefault ":"; + }; + }; + + release = { + user = { + nickname = lib.mkDefault "\\__{^-_-^}"; + }; + + server = { + channels = lib.mkDefault ""; + }; + }; + }; + + systemd.services.catinator = { + description = "Catinator IRC Bot"; + after = [ "network.target" "network-online.target" ]; + wants = [ "network.target" "network-online.target" ]; + wantedBy = [ "multi-user.target" ]; + restartTriggers = [ configFile ] ++ (lib.optional (cfg.environmentFile != null) cfg.environmentFile); + serviceConfig = { + ExecStart = "${cfg.package}/bin/catinator"; + + DynamicUser = lib.mkDefault true; + ProtectHome = true; + NoNewPrivileges = true; + EnvironmentFile = lib.optional (cfg.environmentFile != null) cfg.environmentFile; + }; + environment = { + RUST_LOG = lib.mkDefault "catinator=${cfg.logLevel}"; + CATINATOR_CONFIG = configFile; + } // cfg.extraEnvironment; + }; + }; +} |
