diff --git a/.gitignore b/.gitignore index 78a144f0..228b0b57 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ NECESSIST_LOCK necessist.db +result target diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..45fee247 --- /dev/null +++ b/flake.lock @@ -0,0 +1,48 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1796288735, + "narHash": "sha256-T8KUB70oTLD9fjeCP0yS2gNVD4FiVTParnFUtZy42oI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "dd3cfcafd3168dacca0c76edcb40f60247041ade", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-26.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1794646145, + "narHash": "sha256-rpqDyUM/d5fACYB8W+wKxxO57ICWjjalzb2X25oFFkY=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "5b87ee0513c29127a01ad06e9cb362ea5ce91e78", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..0d37f886 --- /dev/null +++ b/flake.nix @@ -0,0 +1,91 @@ +{ + description = "Necessist — find unnecessary code in tests"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.11"; + inputs.rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = + { + self, + nixpkgs, + rust-overlay, + }: + let + systems = [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" + ]; + forAllSystems = nixpkgs.lib.genAttrs systems; + in + { + packages = forAllSystems ( + system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ rust-overlay.overlays.default ]; + }; + toolchain = pkgs.rust-bin.stable.latest.minimal; + rustPlatform = pkgs.makeRustPlatform { + cargo = toolchain; + rustc = toolchain; + }; + manifest = builtins.fromTOML (builtins.readFile ./necessist/Cargo.toml); + workspace = builtins.fromTOML (builtins.readFile ./Cargo.toml); + workspacePackage = workspace.workspace.package; + name = manifest.package.name; + in + { + necessist = rustPlatform.buildRustPackage { + pname = name; + version = workspacePackage.version; + src = pkgs.nix-gitignore.gitignoreFilterSourcePure pkgs.lib.cleanSourceFilter [ + ./.gitignore + ] ./.; + + cargoLock.lockFile = ./Cargo.lock; + cargoBuildFlags = [ + "--package" + name + ]; + + nativeBuildInputs = [ pkgs.pkg-config ]; + buildInputs = [ + pkgs.libgit2 + pkgs.openssl + pkgs.sqlite + ]; + + # Integration tests require network access and external test frameworks. + doCheck = false; + doInstallCheck = true; + installCheckPhase = '' + runHook preInstallCheck + "$out/bin/${name}" --version + runHook postInstallCheck + ''; + + meta = { + description = manifest.package.description; + homepage = workspacePackage.repository; + license = + if workspacePackage.license == "AGPL-3.0" then + pkgs.lib.licenses.agpl3Only + else + pkgs.lib.meta.getLicenseFromSpdxId workspacePackage.license; + mainProgram = name; + platforms = systems; + }; + }; + default = self.packages.${system}.necessist; + } + ); + checks = forAllSystems (system: { + inherit (self.packages.${system}) necessist; + }); + }; +}