{ description = "My own sheet-organizer using rust and relm4 (and nix)"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; flake-utils.url = "github:numtide/flake-utils"; crane.url = "github:ipetkov/crane"; }; outputs = { self, nixpkgs, flake-utils, crane, ... }: let packageOutputs = flake-utils.lib.eachDefaultSystem ( system: let pkgs = nixpkgs.legacyPackages.${system}; craneLib = crane.mkLib pkgs; dbMigrationsFilter = path: _type: builtins.match ".*sql$" path != null; dbMigrationsOrCargoFilter = path: type: (dbMigrationsFilter path type) || (craneLib.filterCargoSources path type); dbMigrations = pkgs.lib.cleanSourceWith { src = craneLib.path ./db-migrations; # The original, unfiltered source filter = dbMigrationsFilter; }; # Common arguments can be set here to avoid repeating them later # Note: changes here will rebuild all dependency crates commonArgs = rec { strictDeps = true; # When this is not set, all dependency crates will be compiled again src = pkgs.lib.cleanSourceWith { src = craneLib.path ./.; # The original, unfiltered source filter = dbMigrationsOrCargoFilter; }; # Add icons.toml to $src when compiling dependencies (needed by relm4-icons) extraDummyScript = '' cp --no-preserve=mode,ownership ${./icons.toml} $out/icons.toml ''; nativeBuildInputs = with pkgs; [ pkg-config ]; buildInputs = with pkgs; [ gtk4 ] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ # Additional darwin specific inputs can be set here pkgs.libiconv ]; }; # Build *just* the cargo dependencies, so we can reuse # all of that work (e.g. via cachix) when running in CI cargoArtifacts = craneLib.buildDepsOnly (commonArgs); # Run clippy (and deny all warnings) on the crate source, # reusing the dependency artifacts (e.g. from build scripts or # proc-macros) from above. # # Note that this is done as a separate derivation so it # does not impact building just the crate by itself. myCrateClippy = craneLib.cargoClippy ( commonArgs // { # Again we apply some extra arguments only to this derivation # and not every where else. In this case we add some clippy flags inherit cargoArtifacts; cargoClippyExtraArgs = "--all-targets -- --deny warnings"; } ); # Build the actual crate itself, reusing the dependency # artifacts from above. myCrate = craneLib.buildPackage ( commonArgs // { inherit cargoArtifacts; } // { postInstall = '' mkdir -p $out/share/applications cp ${./sheet-organizer.desktop} $out/share/applications/sheet-organizer.desktop mkdir -p $out/share/icons cp ${./sheet-organizer.png} $out/share/icons/sheet-organizer.png ''; } ); # Also run the crate tests under cargo-tarpaulin so that we can keep # track of code coverage myCrateCoverage = craneLib.cargoTarpaulin (commonArgs // { inherit cargoArtifacts; }); in { packages.default = myCrate; checks = { inherit # Build the crate as part of `nix flake check` for convenience myCrate myCrateClippy myCrateCoverage ; }; } ); in packageOutputs; }