diff options
Diffstat (limited to 'nix')
| -rw-r--r-- | nix/ci.nix | 23 | ||||
| -rw-r--r-- | nix/deployment/static.nix | 50 | ||||
| -rw-r--r-- | nix/derivation.nix | 43 | ||||
| -rw-r--r-- | nix/dev.nix | 71 | ||||
| -rw-r--r-- | nix/dev/checks.nix | 27 | ||||
| -rw-r--r-- | nix/dev/docker.nix (renamed from nix/deployment/default.nix) | 12 | ||||
| -rw-r--r-- | nix/dev/flake.lock | 145 | ||||
| -rw-r--r-- | nix/dev/flake.nix | 62 | ||||
| -rw-r--r-- | nix/dev/procfile.nix | 13 | ||||
| -rw-r--r-- | nix/dev/shell.nix | 45 | ||||
| -rw-r--r-- | nix/dev/static.nix | 39 | ||||
| -rw-r--r-- | nix/dev/treefmt.nix | 21 | ||||
| -rw-r--r-- | nix/module.nix (renamed from nix/deployment/module.nix) | 6 | ||||
| -rw-r--r-- | nix/packages.nix | 12 |
14 files changed, 377 insertions, 192 deletions
diff --git a/nix/ci.nix b/nix/ci.nix deleted file mode 100644 index 682f46f..0000000 --- a/nix/ci.nix +++ /dev/null @@ -1,23 +0,0 @@ -{ - perSystem = { - pkgs, - lib, - self', - ... - }: { - /* - require packages, checks, and devShells for ci to be considered a success - - also thanks DetSys for showing me i don't need to use runCommand, symlinkJoin, or linkFarm! - https://determinate.systems/posts/hydra-deployment-source-of-truth - */ - - packages.ciGate = pkgs.writeText "ci-gate" ( - lib.concatMapStringsSep "\n" (s: toString (lib.attrValues s)) [ - self'.checks - self'.devShells - (builtins.removeAttrs self'.packages ["default" "ciGate"]) - ] - ); - }; -} diff --git a/nix/deployment/static.nix b/nix/deployment/static.nix deleted file mode 100644 index dcdf0f3..0000000 --- a/nix/deployment/static.nix +++ /dev/null @@ -1,50 +0,0 @@ -{ - perSystem = { - lib, - pkgs, - inputs', - self', - ... - }: let - targets = with pkgs.pkgsCross; { - x86_64 = musl64.pkgsStatic; - aarch64 = aarch64-multiplatform.pkgsStatic; - }; - - toolchain = let - fenix = inputs'.fenix.packages; - in - with fenix; - combine ( - [minimal.cargo minimal.rustc] - ++ map ( - pkgs: - fenix.targets.${pkgs.stdenv.hostPlatform.config}.latest.rust-std - ) (lib.attrValues targets) - ); - - rustPlatforms = - lib.mapAttrs ( - lib.const (pkgs: - pkgs.makeRustPlatform ( - lib.genAttrs ["cargo" "rustc"] (lib.const toolchain) - )) - ) - targets; - - buildTeawieWith = rustPlatform: - self'.packages.teawiebot.override { - inherit rustPlatform; - lto = true; - optimizeSize = true; - }; - in { - packages = lib.optionalAttrs pkgs.stdenv.isLinux ( - lib.mapAttrs' ( - target: rustPlatform: - lib.nameValuePair "teawiebot-static-${target}" (buildTeawieWith rustPlatform) - ) - rustPlatforms - ); - }; -} diff --git a/nix/derivation.nix b/nix/derivation.nix index bb60706..fa4867a 100644 --- a/nix/derivation.nix +++ b/nix/derivation.nix @@ -4,7 +4,7 @@ rustPlatform, darwin, self, - lto ? false, + lto ? true, optimizeSize ? false, }: rustPlatform.buildRustPackage { @@ -21,7 +21,6 @@ rustPlatform.buildRustPackage { ../src ../Cargo.toml ../Cargo.lock - ../build.rs ]; }; @@ -33,30 +32,28 @@ rustPlatform.buildRustPackage { CoreFoundation Security SystemConfiguration + darwin.libiconv ]); - env = { - GIT_SHA = self.shortRev or self.dirtyShortRev or "unknown-dirty"; - CARGO_BUILD_RUSTFLAGS = lib.concatStringsSep " " ( - lib.optionals lto [ - "-C" - "lto=thin" - "-C" - "embed-bitcode=yes" - "-Zdylib-lto" - ] - ++ lib.optionals optimizeSize [ - "-C" - "codegen-units=1" - "-C" - "panic=abort" - "-C" - "strip=symbols" - "-C" - "opt-level=z" - ] + env = let + toRustFlags = lib.mapAttrs' ( + name: + lib.nameValuePair + "CARGO_BUILD_RELEASE_${lib.toUpper (builtins.replaceStrings ["-"] ["_"] name)}" ); - }; + in + { + GIT_SHA = self.shortRev or self.dirtyShortRev or "unknown-dirty"; + } + // lib.optionalAttrs lto (toRustFlags { + lto = "thin"; + }) + // lib.optionalAttrs optimizeSize (toRustFlags { + codegen-units = 1; + opt-level = "s"; + panic = "abort"; + strip = "symbols"; + }); meta = with lib; { mainProgram = "teawiebot"; diff --git a/nix/dev.nix b/nix/dev.nix deleted file mode 100644 index d9f15d4..0000000 --- a/nix/dev.nix +++ /dev/null @@ -1,71 +0,0 @@ -{ - perSystem = { - lib, - pkgs, - config, - self', - ... - }: let - enableAll = lib.flip lib.genAttrs (lib.const {enable = true;}); - in { - treefmt = { - projectRootFile = "flake.nix"; - - programs = enableAll [ - "alejandra" - "deadnix" - "prettier" - "rustfmt" - ]; - - settings.global = { - excludes = [ - "./target" - "./flake.lock" - "./Cargo.lock" - ]; - }; - }; - - pre-commit.settings = { - settings.treefmt.package = config.treefmt.build.wrapper; - - hooks = enableAll [ - "actionlint" - "nil" - "statix" - "treefmt" - ]; - }; - - procfiles.daemons.processes = { - redis = lib.getExe' pkgs.redis "redis-server"; - }; - - devShells = { - default = pkgs.mkShell { - packages = with pkgs; [ - # general - actionlint - nodePackages_latest.prettier - config.procfiles.daemons.package - - # rust - cargo - rustc - clippy - rustfmt - rust-analyzer - - # nix - self'.formatter - deadnix - nil - statix - ]; - - RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; - }; - }; - }; -} 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/deployment/default.nix b/nix/dev/docker.nix index 7fd379f..b209015 100644 --- a/nix/deployment/default.nix +++ b/nix/dev/docker.nix @@ -1,14 +1,4 @@ -{ - flake-parts-lib, - withSystem, - ... -}: { - imports = [./static.nix]; - - flake.nixosModules.default = flake-parts-lib.importApply ./module.nix { - inherit withSystem; - }; - +{withSystem, ...}: { perSystem = { lib, pkgs, 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" + ]; + }; + }; + }; +} diff --git a/nix/deployment/module.nix b/nix/module.nix index 09999f1..c129e68 100644 --- a/nix/deployment/module.nix +++ b/nix/module.nix @@ -1,4 +1,4 @@ -{withSystem, ...}: { +self: { config, lib, pkgs, @@ -19,11 +19,13 @@ optionals types ; + + inherit (pkgs.stdenv.hostPlatform) system; in { options.services.teawiebot = { enable = mkEnableOption "teawiebot"; package = mkPackageOption ( - withSystem pkgs.stdenv.hostPlatform.system ({self', ...}: self'.packages) + self.packages.${system} or (builtins.throw "${system} is not supported!") ) "teawiebot" {}; user = mkOption { diff --git a/nix/packages.nix b/nix/packages.nix deleted file mode 100644 index f8087f9..0000000 --- a/nix/packages.nix +++ /dev/null @@ -1,12 +0,0 @@ -{self, ...}: { - perSystem = { - pkgs, - self', - ... - }: { - packages = { - teawiebot = pkgs.callPackage ./derivation.nix {inherit self;}; - default = self'.packages.teawiebot; - }; - }; -} |
