summaryrefslogtreecommitdiff
path: root/nix/dev
diff options
context:
space:
mode:
Diffstat (limited to 'nix/dev')
-rw-r--r--nix/dev/checks.nix27
-rw-r--r--nix/dev/docker.nix25
-rw-r--r--nix/dev/flake.lock145
-rw-r--r--nix/dev/flake.nix62
-rw-r--r--nix/dev/procfile.nix13
-rw-r--r--nix/dev/shell.nix45
-rw-r--r--nix/dev/static.nix39
-rw-r--r--nix/dev/treefmt.nix21
8 files changed, 377 insertions, 0 deletions
diff --git a/nix/dev/checks.nix b/nix/dev/checks.nix
new file mode 100644
index 0000000..1d65625
--- /dev/null
+++ b/nix/dev/checks.nix
@@ -0,0 +1,27 @@
+{
+ perSystem = {
+ lib,
+ pkgs,
+ ...
+ }: {
+ checks = {
+ actionlint = pkgs.runCommand "check-actionlint" {} ''
+ ${lib.getExe pkgs.actionlint} ${../../.github/workflows}/*
+ touch $out
+ '';
+
+ editorconfig = pkgs.runCommand "check-editorconfig" {} ''
+ cd ${../../.}
+ ${lib.getExe pkgs.editorconfig-checker} \
+ -exclude '.git' .
+
+ touch $out
+ '';
+
+ statix = pkgs.runCommand "check-statix" {} ''
+ ${lib.getExe pkgs.statix} check ${../../.}
+ touch $out
+ '';
+ };
+ };
+}
diff --git a/nix/dev/docker.nix b/nix/dev/docker.nix
new file mode 100644
index 0000000..b209015
--- /dev/null
+++ b/nix/dev/docker.nix
@@ -0,0 +1,25 @@
+{withSystem, ...}: {
+ perSystem = {
+ lib,
+ pkgs,
+ self',
+ ...
+ }: let
+ containerFor = arch:
+ pkgs.dockerTools.buildLayeredImage {
+ name = "teawiebot";
+ tag = "latest-${arch}";
+ contents = [pkgs.dockerTools.caCertificates];
+ config.Cmd = [
+ (lib.getExe self'.packages."teawiebot-static-${arch}")
+ ];
+
+ architecture = withSystem "${arch}-linux" ({pkgs, ...}: pkgs.pkgsStatic.go.GOARCH);
+ };
+ in {
+ packages = {
+ container-x86_64 = containerFor "x86_64";
+ container-aarch64 = containerFor "aarch64";
+ };
+ };
+}
diff --git a/nix/dev/flake.lock b/nix/dev/flake.lock
new file mode 100644
index 0000000..881402a
--- /dev/null
+++ b/nix/dev/flake.lock
@@ -0,0 +1,145 @@
+{
+ "nodes": {
+ "fenix": {
+ "inputs": {
+ "nixpkgs": [
+ "nixpkgs"
+ ],
+ "rust-analyzer-src": "rust-analyzer-src"
+ },
+ "locked": {
+ "lastModified": 1712384501,
+ "narHash": "sha256-AZmYmEnc1ZkSlxUJVUtGh9VFAqWPr+xtNIiBqD2eKfc=",
+ "owner": "nix-community",
+ "repo": "fenix",
+ "rev": "99c6241db5ca5363c05c8f4acbdf3a4e8fc42844",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nix-community",
+ "repo": "fenix",
+ "type": "github"
+ }
+ },
+ "flake-parts": {
+ "inputs": {
+ "nixpkgs-lib": [
+ "nixpkgs"
+ ]
+ },
+ "locked": {
+ "lastModified": 1712014858,
+ "narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=",
+ "owner": "hercules-ci",
+ "repo": "flake-parts",
+ "rev": "9126214d0a59633752a136528f5f3b9aa8565b7d",
+ "type": "github"
+ },
+ "original": {
+ "owner": "hercules-ci",
+ "repo": "flake-parts",
+ "type": "github"
+ }
+ },
+ "get-flake": {
+ "locked": {
+ "lastModified": 1694475786,
+ "narHash": "sha256-s5wDmPooMUNIAAsxxCMMh9g68AueGg63DYk2hVZJbc8=",
+ "owner": "ursi",
+ "repo": "get-flake",
+ "rev": "ac54750e3b95dab6ec0726d77f440efe6045bec1",
+ "type": "github"
+ },
+ "original": {
+ "owner": "ursi",
+ "repo": "get-flake",
+ "type": "github"
+ }
+ },
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1712512205,
+ "narHash": "sha256-CrKKps0h7FoagRcE2LT3h/72Z64D0Oh83UF1XZVhCLQ=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "3c1b6f75344e207a67536d834886ee9b4577ebe7",
+ "type": "github"
+ },
+ "original": {
+ "owner": "NixOS",
+ "ref": "nixpkgs-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "procfile-nix": {
+ "inputs": {
+ "nixpkgs": [
+ "nixpkgs"
+ ]
+ },
+ "locked": {
+ "lastModified": 1712476251,
+ "narHash": "sha256-o6L0IDUy5ri1ijXP6D132gYcSYT7JweNQr5P9DOozRM=",
+ "owner": "getchoo",
+ "repo": "procfile-nix",
+ "rev": "c3320b59670450b4d2b5cb01cdbd3e176a6d3232",
+ "type": "github"
+ },
+ "original": {
+ "owner": "getchoo",
+ "repo": "procfile-nix",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "fenix": "fenix",
+ "flake-parts": "flake-parts",
+ "get-flake": "get-flake",
+ "nixpkgs": "nixpkgs",
+ "procfile-nix": "procfile-nix",
+ "treefmt-nix": "treefmt-nix"
+ }
+ },
+ "rust-analyzer-src": {
+ "flake": false,
+ "locked": {
+ "lastModified": 1712156296,
+ "narHash": "sha256-St7ZQrkrr5lmQX9wC1ZJAFxL8W7alswnyZk9d1se3Us=",
+ "owner": "rust-lang",
+ "repo": "rust-analyzer",
+ "rev": "8e581ac348e223488622f4d3003cb2bd412bf27e",
+ "type": "github"
+ },
+ "original": {
+ "owner": "rust-lang",
+ "ref": "nightly",
+ "repo": "rust-analyzer",
+ "type": "github"
+ }
+ },
+ "treefmt-nix": {
+ "inputs": {
+ "nixpkgs": [
+ "nixpkgs"
+ ]
+ },
+ "locked": {
+ "lastModified": 1711963903,
+ "narHash": "sha256-N3QDhoaX+paWXHbEXZapqd1r95mdshxToGowtjtYkGI=",
+ "owner": "numtide",
+ "repo": "treefmt-nix",
+ "rev": "49dc4a92b02b8e68798abd99184f228243b6e3ac",
+ "type": "github"
+ },
+ "original": {
+ "owner": "numtide",
+ "repo": "treefmt-nix",
+ "type": "github"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/nix/dev/flake.nix b/nix/dev/flake.nix
new file mode 100644
index 0000000..1442839
--- /dev/null
+++ b/nix/dev/flake.nix
@@ -0,0 +1,62 @@
+{
+ inputs = {
+ nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
+
+ flake-parts = {
+ url = "github:hercules-ci/flake-parts";
+ inputs.nixpkgs-lib.follows = "nixpkgs";
+ };
+
+ fenix = {
+ url = "github:nix-community/fenix";
+ inputs.nixpkgs.follows = "nixpkgs";
+ };
+
+ get-flake.url = "github:ursi/get-flake";
+
+ treefmt-nix = {
+ url = "github:numtide/treefmt-nix";
+ inputs.nixpkgs.follows = "nixpkgs";
+ };
+
+ procfile-nix = {
+ url = "github:getchoo/procfile-nix";
+ inputs.nixpkgs.follows = "nixpkgs";
+ };
+ };
+
+ outputs = inputs:
+ inputs.flake-parts.lib.mkFlake {inherit inputs;} {
+ systems = [
+ "x86_64-linux"
+ "aarch64-linux"
+ "x86_64-darwin"
+ "aarch64-darwin"
+ ];
+
+ imports = [
+ # dev utils
+ ./checks.nix
+ ./procfile.nix
+ ./shell.nix
+ ./treefmt.nix
+
+ # special, private builds
+ ./docker.nix
+ ./static.nix
+
+ inputs.treefmt-nix.flakeModule
+ inputs.procfile-nix.flakeModule
+ ];
+
+ perSystem = {
+ lib,
+ system,
+ ...
+ }: {
+ _module.args = {
+ teawiebot' = lib.mapAttrs (lib.const (v: v.${system} or v)) (inputs.get-flake ../../.);
+ };
+ };
+ };
+}
diff --git a/nix/dev/procfile.nix b/nix/dev/procfile.nix
new file mode 100644
index 0000000..4b1c665
--- /dev/null
+++ b/nix/dev/procfile.nix
@@ -0,0 +1,13 @@
+{
+ perSystem = {
+ lib,
+ pkgs,
+ ...
+ }: {
+ procfiles.daemons = {
+ processes = {
+ redis = lib.getExe' pkgs.redis "redis-server";
+ };
+ };
+ };
+}
diff --git a/nix/dev/shell.nix b/nix/dev/shell.nix
new file mode 100644
index 0000000..c5589ef
--- /dev/null
+++ b/nix/dev/shell.nix
@@ -0,0 +1,45 @@
+{
+ perSystem = {
+ config,
+ pkgs,
+ self',
+ teawiebot',
+ ...
+ }: {
+ devShells = {
+ default = pkgs.mkShell {
+ packages = [
+ # rust tools
+ pkgs.clippy
+ pkgs.rustfmt
+ pkgs.rust-analyzer
+
+ # nix tools
+ pkgs.deadnix
+ pkgs.nil
+ pkgs.statix
+
+ # misc formatter/linters
+ pkgs.actionlint
+ self'.formatter
+
+ config.procfiles.daemons.package
+ ];
+
+ inputsFrom = [teawiebot'.packages.teawiebot];
+ RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}";
+ };
+
+ ci = pkgs.mkShell {
+ packages = [
+ pkgs.clippy
+ pkgs.rustfmt
+
+ self'.formatter
+ ];
+
+ inputsFrom = [teawiebot'.packages.teawiebot];
+ };
+ };
+ };
+}
diff --git a/nix/dev/static.nix b/nix/dev/static.nix
new file mode 100644
index 0000000..e8780f4
--- /dev/null
+++ b/nix/dev/static.nix
@@ -0,0 +1,39 @@
+{
+ perSystem = {
+ lib,
+ pkgs,
+ inputs',
+ teawiebot',
+ ...
+ }: let
+ crossTargets = with pkgs.pkgsCross; {
+ x86_64 = musl64.pkgsStatic;
+ aarch64 = aarch64-multiplatform.pkgsStatic;
+ };
+
+ rustStdFor = pkgs: inputs'.fenix.packages.targets.${pkgs.stdenv.hostPlatform.rust.rustcTarget}.stable.rust-std;
+ toolchain = with inputs'.fenix.packages;
+ combine (lib.flatten [
+ stable.cargo
+ stable.rustc
+ (map rustStdFor (lib.attrValues crossTargets))
+ ]);
+
+ rustPlatformFor = pkgs:
+ pkgs.makeRustPlatform (
+ lib.genAttrs ["cargo" "rustc"] (lib.const toolchain)
+ );
+ crossPlatforms = lib.mapAttrs (lib.const rustPlatformFor) crossTargets;
+
+ buildTeawieWith = rustPlatform:
+ teawiebot'.packages.teawiebot.override {
+ inherit rustPlatform;
+ optimizeSize = true;
+ };
+ in {
+ packages = {
+ teawiebot-static-x86_64 = buildTeawieWith crossPlatforms.x86_64;
+ teawiebot-static-aarch64 = buildTeawieWith crossPlatforms.aarch64;
+ };
+ };
+}
diff --git a/nix/dev/treefmt.nix b/nix/dev/treefmt.nix
new file mode 100644
index 0000000..5e1fd1f
--- /dev/null
+++ b/nix/dev/treefmt.nix
@@ -0,0 +1,21 @@
+{
+ perSystem = {
+ treefmt = {
+ projectRootFile = "flake.nix";
+
+ programs = {
+ alejandra.enable = true;
+ deadnix.enable = true;
+ rustfmt.enable = true;
+ };
+
+ settings.global = {
+ excludes = [
+ "./target"
+ "./flake.lock"
+ "./Cargo.lock"
+ ];
+ };
+ };
+ };
+}