diff --git a/flake.lock b/flake.lock index a2f8ca7..afb94f9 100644 --- a/flake.lock +++ b/flake.lock @@ -21,11 +21,11 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1700710264, - "narHash": "sha256-7JSlj4iWgt3bsqmkPenIy1z+9f9oGuKEk9Lt6ebFyNg=", + "lastModified": 1700795494, + "narHash": "sha256-gzGLZSiOhf155FW7262kdHo2YDeugp3VuIFb4/GGng0=", "owner": "lnl7", "repo": "nix-darwin", - "rev": "6e0f4e58a622dd3a34b09f56fdcab9eddc641a67", + "rev": "4b9b83d5a92e8c1fbfd8eb27eda375908c11ec4d", "type": "github" }, "original": { @@ -189,11 +189,11 @@ "yorha-sound-theme": "yorha-sound-theme" }, "locked": { - "lastModified": 1700713615, - "narHash": "sha256-AtHCGDyk1PFJR5GdQtDq7mkAvDDZ28nF1vXCy7oi1j8=", + "lastModified": 1700807094, + "narHash": "sha256-wXF4QYDrGS8BbGlTy95JeLB6uUIzl1BwD6aO/AnRvCo=", "ref": "refs/heads/main", - "rev": "10cd771ad2dc465d91dd559e5e175d55816c608e", - "revCount": 7, + "rev": "4b150e1c9a33ff65d9fe8bb7f58900f4295ac3e3", + "revCount": 8, "type": "git", "url": "https://forgejo.invariantspace.com/macronova/nix-custom" }, @@ -359,11 +359,11 @@ }, "nixpkgs_6": { "locked": { - "lastModified": 1700390070, - "narHash": "sha256-de9KYi8rSJpqvBfNwscWdalIJXPo8NjdIZcEJum1mH0=", + "lastModified": 1700612854, + "narHash": "sha256-yrQ8osMD+vDLGFX7pcwsY/Qr5PUd6OmDMYJZzZi0+zc=", "owner": "nixos", "repo": "nixpkgs", - "rev": "e4ad989506ec7d71f7302cc3067abd82730a4beb", + "rev": "19cbff58383a4ae384dea4d1d0c823d72b49d614", "type": "github" }, "original": { @@ -375,11 +375,11 @@ }, "nixpkgs_7": { "locked": { - "lastModified": 1700390070, - "narHash": "sha256-de9KYi8rSJpqvBfNwscWdalIJXPo8NjdIZcEJum1mH0=", + "lastModified": 1700612854, + "narHash": "sha256-yrQ8osMD+vDLGFX7pcwsY/Qr5PUd6OmDMYJZzZi0+zc=", "owner": "nixos", "repo": "nixpkgs", - "rev": "e4ad989506ec7d71f7302cc3067abd82730a4beb", + "rev": "19cbff58383a4ae384dea4d1d0c823d72b49d614", "type": "github" }, "original": { @@ -504,11 +504,11 @@ "yorha-sound-theme": { "flake": false, "locked": { - "lastModified": 1700606560, - "narHash": "sha256-TiglZP8Je+SlL/5mrV4bugp0t0z2Zs2pKLRehlgR8y0=", + "lastModified": 1700807066, + "narHash": "sha256-kr0vdyHSjunGa3y0cTqRX6z1rRdLY6IcFeNRy213L2s=", "ref": "refs/heads/main", - "rev": "5ab3fff4c5c62c08ebdcf162817bfaaaeb57d559", - "revCount": 2, + "rev": "a1dad2f17c229ec9b98987614cce4de83eed73f9", + "revCount": 3, "type": "git", "url": "https://forgejo.invariantspace.com/macronova/yorha-sound-theme.git" }, diff --git a/template/rust/flake.nix b/template/rust/flake.nix index da24505..7eba7e7 100644 --- a/template/rust/flake.nix +++ b/template/rust/flake.nix @@ -1,16 +1,122 @@ { inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + crane.url = "github:ipetkov/crane"; flake-utils.url = "github:numtide/flake-utils"; fenix.url = "github:nix-community/fenix"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + advisory-db = { + flake = false; + url = "github:rustsec/advisory-db"; + }; }; - outputs = { self, fenix, flake-utils, nixpkgs }: + outputs = { self, crane, fenix, flake-utils, nixpkgs, advisory-db }: flake-utils.lib.eachDefaultSystem (system: - let pkgs = nixpkgs.legacyPackages.${system}; - in { - devShells.default = pkgs.mkShell { - packages = [ fenix.packages.${system}.complete.toolchain ]; + let + pkgs = nixpkgs.legacyPackages.${system}; + craneLib = crane.lib.${system}; + src = craneLib.cleanCargoSource (craneLib.path ./.); + + # Common arguments can be set here to avoid repeating them later + commonArgs = { + inherit src; + strictDeps = true; + buildInputs = [ + # Add additional build inputs here + ] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ + # Additional darwin specific inputs can be set here + pkgs.libiconv + ]; + + # Additional environment variables can be set directly + # MY_CUSTOM_VAR = "some value"; + }; + + craneLibLLvmTools = craneLib.overrideToolchain + (fenix.packages.${system}.complete.withComponents [ + "cargo" + "llvm-tools" + "rustc" + ]); + + # 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; + + # Build the actual crate itself, reusing the dependency + # artifacts from above. + crate = craneLib.buildPackage (commonArgs // { + inherit cargoArtifacts; + }); + in + { + checks = { + # Build the crate as part of `nix flake check` for convenience + inherit crate; + + # Run clippy (and deny all warnings) on the crate source, + # again, resuing the dependency artifacts from above. + # + # Note that this is done as a separate derivation so that + # we can block the CI if there are issues here, but not + # prevent downstream consumers from building our crate by itself. + clippy = craneLib.cargoClippy (commonArgs // { + inherit cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + }); + + doc = craneLib.cargoDoc (commonArgs // { + inherit cargoArtifacts; + }); + + # Check formatting + fmt = craneLib.cargoFmt { + inherit src; + }; + + # Audit dependencies + audit = craneLib.cargoAudit { + inherit src advisory-db; + }; + + # Audit licenses + deny = craneLib.cargoDeny { + inherit src; + }; + + # Run tests with cargo-nextest + # Consider setting `doCheck = false` on `my-crate` if you do not want + # the tests to run twice + nextest = craneLib.cargoNextest (commonArgs // { + inherit cargoArtifacts; + partitions = 1; + partitionType = "count"; + }); + }; + + packages = { + default = crate; + llvm-coverage = craneLibLLvmTools.cargoLlvmCov (commonArgs // { + inherit cargoArtifacts; + }); + }; + + apps.default = flake-utils.lib.mkApp { + drv = crate; + }; + + devShells.default = craneLib.devShell { + # Inherit inputs from checks. + # Enable after Cargo.toml and Cargo.lock are present + # checks = self.checks.${system}; + + # Additional dev-shell environment variables can be set directly + # MY_CUSTOM_DEVELOPMENT_VAR = "something else"; + + # Extra inputs can be added here; cargo and rustc are provided by default. + packages = [ + # pkgs.ripgrep + ]; }; }); } diff --git a/template/typst/flake.nix b/template/typst/flake.nix new file mode 100644 index 0000000..7225a26 --- /dev/null +++ b/template/typst/flake.nix @@ -0,0 +1,15 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, flake-utils, nixpkgs }: + flake-utils.lib.eachDefaultSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; + in { + devShells.default = pkgs.mkShell { + packages = with pkgs; [ typst ]; + }; + }); +}