diff options
| author | seth <[email protected]> | 2024-07-06 04:10:27 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-07-06 04:10:27 -0400 |
| commit | cdb32dbd1810fbafc3b80bf6693e0f8dcf81b2c2 (patch) | |
| tree | 6e580008869ef4cd64f619f8740712c42e5d50b1 | |
| parent | c61a7b372a1ec99ec8d490c7f96df3a25a5c2281 (diff) | |
tree-wide: start using treefmt (#17)
* nix: alejandra -> nixfmt
* nix: simplify flake
* nix: drop flake-checks
* tree-wide: start using treefmt
| -rw-r--r-- | .editorconfig | 13 | ||||
| -rw-r--r-- | .github/workflows/ci.yaml | 8 | ||||
| -rw-r--r-- | flake.lock | 39 | ||||
| -rw-r--r-- | flake.nix | 191 | ||||
| -rw-r--r-- | nix/module.nix | 25 | ||||
| -rw-r--r-- | nix/package.nix | 22 | ||||
| -rw-r--r-- | nix/static.nix | 46 | ||||
| -rw-r--r-- | treefmt.nix | 12 |
8 files changed, 181 insertions, 175 deletions
diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index e24cebd..0000000 --- a/.editorconfig +++ /dev/null @@ -1,13 +0,0 @@ -# http://editorconfig.org -root = true - -[*] -charset = utf-8 -end_of_line = lf -indent_style = tab -insert_final_newline = true -trim_trailing_whitespace = true - -[*.{lock,nix,yml,yaml}] -indent_style = space -indent_size = 2 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 34ced56..53b4268 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -38,8 +38,8 @@ jobs: run: | cargo build --locked --release - format-and-lint: - name: Format and lint + treefmt: + name: Treefmt runs-on: ubuntu-latest @@ -50,13 +50,13 @@ jobs: - name: Install Nix uses: DeterminateSystems/nix-installer-action@v12 - - name: Run checks + - name: Run check run: | nix flake check --print-build-logs --show-trace release-gate: name: CI Release gate - needs: [build, format-and-lint] + needs: [build, treefmt] runs-on: ubuntu-latest @@ -21,21 +21,6 @@ "type": "github" } }, - "flake-checks": { - "locked": { - "lastModified": 1716193450, - "narHash": "sha256-wIbyIQRoLAfGe2v8W7LM6zEZ9Oy0jKuUX0HMUCLQJsM=", - "owner": "getchoo", - "repo": "flake-checks", - "rev": "842c3f225677aa55e44b94342f19c8f3e6f2be06", - "type": "github" - }, - "original": { - "owner": "getchoo", - "repo": "flake-checks", - "type": "github" - } - }, "nixpkgs": { "locked": { "lastModified": 1719468428, @@ -55,8 +40,28 @@ "root": { "inputs": { "fenix": "fenix", - "flake-checks": "flake-checks", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "treefmt-nix": "treefmt-nix" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1719887753, + "narHash": "sha256-p0B2r98UtZzRDM5miGRafL4h7TwGRC4DII+XXHDHqek=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "bdb6355009562d8f9313d9460c0d3860f525bc6c", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" } } }, @@ -12,116 +12,107 @@ }; }; - flake-checks.url = "github:getchoo/flake-checks"; + treefmt-nix = { + url = "github:numtide/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; - outputs = { - self, - nixpkgs, - fenix, - flake-checks, - }: let - systems = [ - "x86_64-linux" - "aarch64-linux" - "x86_64-darwin" - "aarch64-darwin" - ]; - - forAllSystems = function: nixpkgs.lib.genAttrs systems (system: function nixpkgs.legacyPackages.${system}); - in { - checks = forAllSystems ({ - lib, - pkgs, - ... - }: { - inherit - (flake-checks.lib.mkChecks { - inherit pkgs; - root = lib.fileset.toSource { - root = ./.; - fileset = lib.fileset.gitTracked ./.; + outputs = + { + self, + nixpkgs, + fenix, + treefmt-nix, + }: + let + inherit (nixpkgs) lib; + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + + forAllSystems = lib.genAttrs systems; + nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system}); + treefmtFor = forAllSystems (system: treefmt-nix.lib.evalModule nixpkgsFor.${system} ./treefmt.nix); + in + { + checks = forAllSystems (system: { + treefmt = treefmtFor.${system}.config.build.check self; + }); + + devShells = forAllSystems ( + system: + let + pkgs = nixpkgsFor.${system}; + inputsFrom = [ self.packages.${system}.nixpkgs-tracker-bot ]; + in + { + default = pkgs.mkShell { + inherit inputsFrom; + RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}"; + + packages = [ + pkgs.clippy + pkgs.rustfmt + pkgs.rust-analyzer + + self.formatter.${system} + ]; }; - }) - actionlint - deadnix - rustfmt - statix - ; - }); - - devShells = forAllSystems ({ - pkgs, - system, - ... - }: let - inputsFrom = [self.packages.${system}.nixpkgs-tracker-bot]; - in { - default = pkgs.mkShell { - inherit inputsFrom; - RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}"; - - packages = [ - pkgs.clippy - pkgs.rustfmt - pkgs.rust-analyzer - - pkgs.actionlint - pkgs.deadnix - pkgs.nil - pkgs.statix - - self.formatter.${system} - ]; - }; - ci = pkgs.mkShell { - inherit inputsFrom; - packages = [ - pkgs.clippy - pkgs.rustfmt - ]; - }; - }); + ci = pkgs.mkShell { + inherit inputsFrom; + packages = [ + pkgs.clippy + pkgs.rustfmt + ]; + }; + } + ); - formatter = forAllSystems (pkgs: pkgs.alejandra); + formatter = forAllSystems (system: treefmtFor.${system}.config.build.wrapper); - nixosModules.default = import ./nix/module.nix self; + nixosModules.default = import ./nix/module.nix self; - packages = forAllSystems ({ - lib, - pkgs, - system, - ... - }: let - packages = self.packages.${system}; + packages = forAllSystems ( + system: + let + pkgs = nixpkgsFor.${system}; + packages = self.packages.${system}; - mkStaticWith = pkgs.callPackage ./nix/static.nix { - inherit (packages) nixpkgs-tracker-bot; - fenix = fenix.packages.${system}; - }; + mkStaticWith = pkgs.callPackage ./nix/static.nix { + inherit (packages) nixpkgs-tracker-bot; + fenix = fenix.packages.${system}; + }; - containerWith = nixpkgs-tracker-bot: let - arch = nixpkgs-tracker-bot.stdenv.hostPlatform.ubootArch; - in - pkgs.dockerTools.buildLayeredImage { - name = "nixpkgs-tracker-bot"; - tag = "latest-${arch}"; - config.Cmd = [(lib.getExe nixpkgs-tracker-bot)]; - architecture = arch; - }; - in { - nixpkgs-tracker-bot = pkgs.callPackage ./nix/package.nix { - version = self.shortRev or self.dirtyShortRev or "unknown"; - }; + containerWith = + nixpkgs-tracker-bot: + let + arch = nixpkgs-tracker-bot.stdenv.hostPlatform.ubootArch; + in + pkgs.dockerTools.buildLayeredImage { + name = "nixpkgs-tracker-bot"; + tag = "latest-${arch}"; + config.Cmd = [ (lib.getExe nixpkgs-tracker-bot) ]; + architecture = arch; + }; + in + { + nixpkgs-tracker-bot = pkgs.callPackage ./nix/package.nix { + version = self.shortRev or self.dirtyShortRev or "unknown"; + }; - default = packages.nixpkgs-tracker-bot; + default = packages.nixpkgs-tracker-bot; - static-x86_64 = mkStaticWith {arch = "x86_64";}; - static-arm64 = mkStaticWith {arch = "aarch64";}; + static-x86_64 = mkStaticWith { arch = "x86_64"; }; + static-arm64 = mkStaticWith { arch = "aarch64"; }; - container-x86_64 = containerWith packages.static-x86_64; - container-arm64 = containerWith packages.static-arm64; - }); - }; + container-x86_64 = containerWith packages.static-x86_64; + container-arm64 = containerWith packages.static-arm64; + } + ); + }; } diff --git a/nix/module.nix b/nix/module.nix index 3d23ead..3ad3929 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -1,13 +1,14 @@ -self: { +self: +{ config, lib, pkgs, ... -}: let +}: +let cfg = config.services.nixpkgs-tracker-bot; - inherit - (lib) + inherit (lib) getExe literalExpression mkEnableOption @@ -18,12 +19,12 @@ self: { ; inherit (pkgs.stdenv.hostPlatform) system; -in { +in +{ options.services.nixpkgs-tracker-bot = { enable = mkEnableOption "nixpkgs-tracker-bot"; - package = mkPackageOption ( - self.packages.${system} or (throw "${system} is not supported!") - ) "nixpkgs-tracker-bot" {}; + package = mkPackageOption (self.packages.${system} or (throw "${system} is not supported!") + ) "nixpkgs-tracker-bot" { }; environmentFile = mkOption { description = '' @@ -40,8 +41,8 @@ in { config = mkIf cfg.enable { systemd.services.nixpkgs-tracker-bot = { enable = true; - wantedBy = ["multi-user.target"]; - after = ["network.target"]; + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; script = '' ${getExe cfg.package} @@ -82,9 +83,7 @@ in { RestrictRealtime = true; RestrictSUIDSGID = true; SystemCallArchitectures = "native"; - SystemCallFilter = [ - "@system-service" - ]; + SystemCallFilter = [ "@system-service" ]; UMask = "0077"; }; }; diff --git a/nix/package.nix b/nix/package.nix index 778fa27..261e785 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -22,16 +22,18 @@ rustPlatform.buildRustPackage { cargoLock.lockFile = ../Cargo.lock; - nativeBuildInputs = [pkg-config]; - buildInputs = [openssl]; + nativeBuildInputs = [ pkg-config ]; + buildInputs = [ openssl ]; - env = let - toRustFlags = lib.mapAttrs' ( - name: - lib.nameValuePair - "CARGO_BUILD_RELEASE_${lib.toUpper (builtins.replaceStrings ["-"] ["_"] name)}" - ); - in + env = + let + toRustFlags = lib.mapAttrs' ( + name: + lib.nameValuePair "CARGO_BUILD_RELEASE_${ + lib.toUpper (builtins.replaceStrings [ "-" ] [ "_" ] name) + }" + ); + in lib.optionalAttrs lto (toRustFlags { lto = "thin"; }) @@ -47,6 +49,6 @@ rustPlatform.buildRustPackage { homepage = "https://github.com/getchoo/nixpkgs-tracker-bot"; mainProgram = "nixpkgs-tracker-bot"; license = lib.licenses.mit; - maintainers = [lib.maintainers.getchoo]; + maintainers = [ lib.maintainers.getchoo ]; }; } diff --git a/nix/static.nix b/nix/static.nix index c5e3c57..86a1cc3 100644 --- a/nix/static.nix +++ b/nix/static.nix @@ -3,33 +3,43 @@ fenix, pkgsCross, nixpkgs-tracker-bot, -}: let +}: +let crossPkgsFor = with pkgsCross; { x86_64 = musl64.pkgsStatic; aarch64 = aarch64-multiplatform; }; - rustcTargetFor = lib.mapAttrs (lib.const (pkgs: pkgs.stdenv.hostPlatform.rust.rustcTarget)) crossPkgsFor; - rustStdFor = lib.mapAttrs (lib.const (rustcTarget: fenix.targets.${rustcTarget}.stable.rust-std)) rustcTargetFor; + rustcTargetFor = lib.mapAttrs (lib.const ( + pkgs: pkgs.stdenv.hostPlatform.rust.rustcTarget + )) crossPkgsFor; + rustStdFor = lib.mapAttrs (lib.const ( + rustcTarget: fenix.targets.${rustcTarget}.stable.rust-std + )) rustcTargetFor; - toolchain = with fenix; + toolchain = + with fenix; combine ( - [stable.cargo stable.rustc] + [ + stable.cargo + stable.rustc + ] ++ lib.attrValues rustStdFor ); - crossPlatformFor = - lib.mapAttrs ( - lib.const (pkgs: - pkgs.makeRustPlatform ( - lib.genAttrs ["cargo" "rustc"] (lib.const toolchain) - )) + crossPlatformFor = lib.mapAttrs (lib.const ( + pkgs: + pkgs.makeRustPlatform ( + lib.genAttrs [ + "cargo" + "rustc" + ] (lib.const toolchain) ) - crossPkgsFor; + )) crossPkgsFor; in - {arch}: - nixpkgs-tracker-bot.override { - rustPlatform = crossPlatformFor.${arch}; - inherit (crossPkgsFor.${arch}) openssl; - optimizeSize = true; - } +{ arch }: +nixpkgs-tracker-bot.override { + rustPlatform = crossPlatformFor.${arch}; + inherit (crossPkgsFor.${arch}) openssl; + optimizeSize = true; +} diff --git a/treefmt.nix b/treefmt.nix new file mode 100644 index 0000000..f3dcaac --- /dev/null +++ b/treefmt.nix @@ -0,0 +1,12 @@ +{ + projectRootFile = ".git/config"; + + # TODO: add actionlint + # https://github.com/numtide/treefmt-nix/pull/146 + programs = { + deadnix.enable = true; + nixfmt-rfc-style.enable = true; + rustfmt.enable = true; + statix.enable = true; + }; +} |
