diff options
Diffstat (limited to 'flake.nix')
| -rw-r--r-- | flake.nix | 181 |
1 files changed, 19 insertions, 162 deletions
@@ -1,13 +1,27 @@ { description = "teawie moment"; + nixConfig = { + extra-substituters = [ + "https://getchoo.cachix.org" + ]; + extra-trusted-public-keys = [ + "getchoo.cachix.org-1:ftdbAUJVNaFonM0obRGgR5+nUmdLMM+AOvDOSx0z5tE=" + ]; + }; + inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - flake-utils.url = "github:numtide/flake-utils"; flake-compat = { url = "github:edolstra/flake-compat"; flake = false; }; + flake-parts = { + url = "github:hercules-ci/flake-parts"; + inputs.nixpkgs-lib.follows = "nixpkgs"; + }; + # this is just to avoid having multiple versions in flake.lock + flake-utils.url = "github:numtide/flake-utils"; crane = { url = "github:ipetkov/crane"; inputs.nixpkgs.follows = "nixpkgs"; @@ -27,165 +41,8 @@ }; }; - outputs = { - self, - nixpkgs, - flake-utils, - crane, - fenix, - pre-commit-hooks, - ... - }: let - supportedSystems = with flake-utils.lib.system; [ - x86_64-linux - x86_64-darwin - aarch64-linux - aarch64-darwin - ]; - - packageFn = craneLib: cargoArtifacts: pkgs: let - inherit (pkgs.lib) licenses maintainers platforms; - inherit (craneLib) buildPackage; - in { - teawiebot = buildPackage { - src = ./.; - inherit cargoArtifacts; - - meta = { - description = "funni bot"; - homepage = "https://github.com/getchoo/teawiebot"; - license = licenses.mit; - platforms = platforms.unix; - maintainers = with maintainers; [getchoo]; - }; - }; - }; - in - flake-utils.lib.eachSystem supportedSystems (system: let - pkgs = import nixpkgs { - inherit system; - overlays = [fenix.overlays.default]; - }; - - toolchain = with pkgs.fenix; - with stable; - combine [ - cargo - rustc - rustfmt - clippy - targets."x86_64-unknown-linux-musl".stable.rust-std - ]; - - craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; - - cargoArtifacts = craneLib.buildDepsOnly { - src = ./.; - }; - in { - packages = let - inherit (packageFn craneLib cargoArtifacts pkgs) teawiebot; - - teawiebot-smol = - teawiebot.overrideAttrs (_: { - # statically link musl, optimize for size - CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl"; - CARGO_BUILD_RUSTFLAGS = "-C lto=fat -C embed-bitcode=yes \ - -C target-feature=+crt-static -C opt-level=z -C strip=symbols -C codegen-units=1"; - CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER = let - inherit (pkgs.pkgsStatic.stdenv) cc; - in "${cc}/bin/${cc.targetPrefix}cc"; - }); - cmd = "${teawiebot-smol}/bin/teawiebot"; - in - { - inherit teawiebot teawiebot-smol; - container = let - inherit (pkgs.dockerTools) buildLayeredImage caCertificates; - in - buildLayeredImage { - name = "teawiebot"; - tag = "latest"; - contents = [caCertificates]; - config.Cmd = ["${cmd}"]; - }; - service = let - inherit (pkgs) cacert portableService; - service = pkgs.writeTextFile { - name = "teawiebot.service"; - text = '' - [Unit] - Description=portable service for teawiebot - - [Service] - DynamicUser=yes - ExecStart="${cmd}" - - [Install] - WantedBy=multi-user.target - ''; - }; - in - portableService { - inherit (teawiebot) pname; - inherit (teawiebot-smol) version; - description = "portable service for teawiebot!"; - units = [service]; - symlinks = [ - { - object = "${cacert}/etc/ssl"; - symlink = "/etc/ssl"; - } - ]; - }; - } - // {default = self.packages.${system}.teawiebot;}; - - checks = let - commonArgs = { - src = ./.; - }; - - inherit (craneLib) cargoClippy cargoFmt; - in { - inherit (self.packages.${system}) teawiebot; - - clippy = cargoClippy (commonArgs - // { - inherit cargoArtifacts; - cargoClippyExtraArgs = "--all-targets"; - }); - - fmt = cargoFmt commonArgs; - - pre-commit-check = pre-commit-hooks.lib.${system}.run { - src = ./.; - hooks = { - actionlint.enable = true; - alejandra.enable = true; - deadnix.enable = true; - statix.enable = true; - }; - }; - }; - - devShells = let - inherit (pkgs) mkShell; - inherit (self.checks.${system}.pre-commit-check) shellHook; - in { - default = mkShell { - inherit shellHook; - packages = with pkgs; [ - actionlint - alejandra - deadnix - statix - - toolchain - ]; - }; - }; - - formatter = pkgs.alejandra; - }); + outputs = inputs: + inputs.flake-parts.lib.mkFlake + {inherit inputs;} + {imports = [./parts];}; } |
