improve rust template for ensuring package overriable
This commit is contained in:
parent
dc5dfddf74
commit
18bfe1ce9a
6 changed files with 100 additions and 38 deletions
|
|
@ -1,3 +1,3 @@
|
||||||
watch_file rust-toolchain.toml
|
watch_file rust-toolchain.toml nix/*.nix
|
||||||
|
|
||||||
use flake
|
use flake
|
||||||
|
|
|
||||||
24
templates/rust/flake.lock
generated
24
templates/rust/flake.lock
generated
|
|
@ -3,11 +3,11 @@
|
||||||
"advisory-db": {
|
"advisory-db": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1746689539,
|
"lastModified": 1747937073,
|
||||||
"narHash": "sha256-rVUs0CjpuO7FKVHecsuMaYiUr8iKscsgeo/b2XlnPmQ=",
|
"narHash": "sha256-52H8P6jAHEwRvg7rXr4Z7h1KHZivO8T1Z9tN6R0SWJg=",
|
||||||
"owner": "rustsec",
|
"owner": "rustsec",
|
||||||
"repo": "advisory-db",
|
"repo": "advisory-db",
|
||||||
"rev": "796d034fbcb1c5bc83c0d0912dc31eb4e34458bf",
|
"rev": "bccf313a98c034573ac4170e6271749113343d97",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -18,11 +18,11 @@
|
||||||
},
|
},
|
||||||
"crane": {
|
"crane": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1746291859,
|
"lastModified": 1748047550,
|
||||||
"narHash": "sha256-DdWJLA+D5tcmrRSg5Y7tp/qWaD05ATI4Z7h22gd1h7Q=",
|
"narHash": "sha256-t0qLLqb4C1rdtiY8IFRH5KIapTY/n3Lqt57AmxEv9mk=",
|
||||||
"owner": "ipetkov",
|
"owner": "ipetkov",
|
||||||
"repo": "crane",
|
"repo": "crane",
|
||||||
"rev": "dfd9a8dfd09db9aad544c4d3b6c47b12562544a5",
|
"rev": "b718a78696060df6280196a6f992d04c87a16aef",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -51,11 +51,11 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1746300365,
|
"lastModified": 1747958103,
|
||||||
"narHash": "sha256-thYTdWqCRipwPRxWiTiH1vusLuAy0okjOyzRx4hLWh4=",
|
"narHash": "sha256-qmmFCrfBwSHoWw7cVK4Aj+fns+c54EBP8cGqp/yK410=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "f21e4546e3ede7ae34d12a84602a22246b31f7e0",
|
"rev": "fe51d34885f7b5e3e7b59572796e1bcb427eccb1",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -81,11 +81,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1746326315,
|
"lastModified": 1748140821,
|
||||||
"narHash": "sha256-IDqSls/r6yBfdOBRSMQ/noTUoigmsKnTQ7TqpsBtN4Y=",
|
"narHash": "sha256-GZcjWLQtDifSYMd1ueLDmuVTcQQdD5mONIBTqABooOk=",
|
||||||
"owner": "oxalica",
|
"owner": "oxalica",
|
||||||
"repo": "rust-overlay",
|
"repo": "rust-overlay",
|
||||||
"rev": "dd280c436961ec5adccf0135efe5b66a23d84497",
|
"rev": "476b2ba7dc99ddbf70b1f45357dbbdbdbdfb4422",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
||||||
|
|
@ -31,12 +31,17 @@
|
||||||
inherit (pkgs) lib;
|
inherit (pkgs) lib;
|
||||||
pkgs = import nixpkgs {
|
pkgs = import nixpkgs {
|
||||||
inherit system;
|
inherit system;
|
||||||
overlays = [(import rust-overlay)];
|
overlays = [
|
||||||
|
(import rust-overlay)
|
||||||
|
(final: prev: {
|
||||||
|
lib = prev.lib // (import ./nix/lib.nix prev.lib);
|
||||||
|
})
|
||||||
|
];
|
||||||
};
|
};
|
||||||
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
|
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
|
||||||
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
|
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
|
||||||
srcFilters = path: type:
|
srcFilters = path: type:
|
||||||
builtins.any (suffix: lib.hasSuffix suffix path) [
|
builtins.any (lib.flip lib.hasSuffix path) [
|
||||||
".sql"
|
".sql"
|
||||||
".diff"
|
".diff"
|
||||||
".md"
|
".md"
|
||||||
|
|
@ -52,20 +57,15 @@
|
||||||
inherit src;
|
inherit src;
|
||||||
strictDeps = true;
|
strictDeps = true;
|
||||||
};
|
};
|
||||||
nativeBuildInputs = with pkgs; [];
|
nativeBuildInputs = [];
|
||||||
buildInputs =
|
buildInputs = [];
|
||||||
(with pkgs; [])
|
genInputs = lib.genInputsWith pkgs;
|
||||||
++ lib.optional pkgs.stdenv.buildPlatform.isDarwin (with pkgs; [
|
|
||||||
darwin.apple_sdk.frameworks.Security
|
|
||||||
]);
|
|
||||||
cargoArtifacts = craneLib.buildDepsOnly (basicArgs
|
|
||||||
// {
|
|
||||||
inherit buildInputs nativeBuildInputs;
|
|
||||||
});
|
|
||||||
commonArgs =
|
commonArgs =
|
||||||
basicArgs
|
basicArgs
|
||||||
// {
|
// {
|
||||||
inherit cargoArtifacts buildInputs nativeBuildInputs;
|
cargoArtifacts = self.packages.${system}.cargo-artifacts;
|
||||||
|
buildInputs = genInputs buildInputs;
|
||||||
|
nativeBuildInputs = genInputs nativeBuildInputs;
|
||||||
};
|
};
|
||||||
in {
|
in {
|
||||||
formatter = pkgs.alejandra;
|
formatter = pkgs.alejandra;
|
||||||
|
|
@ -93,18 +93,17 @@
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
packages = rec {
|
packages = let
|
||||||
rust-demo = craneLib.buildPackage (commonArgs
|
callPackage = lib.callPackageWith (pkgs // {inherit craneLib callPackage;});
|
||||||
// {
|
packageArgs = {
|
||||||
inherit
|
inherit lib basicArgs buildInputs nativeBuildInputs;
|
||||||
(craneLib.crateNameFromCargoToml {
|
};
|
||||||
cargoToml = "${toString src}/Cargo.toml";
|
importWithArgs = with lib; flip import packageArgs;
|
||||||
})
|
in rec {
|
||||||
pname
|
cargo-artifacts = callPackage (importWithArgs ./nix/cargo-artifacts.nix) {};
|
||||||
version
|
rust-demo = callPackage (importWithArgs ./nix/package.nix) {
|
||||||
;
|
cargoArtifacts = cargo-artifacts;
|
||||||
doCheck = false;
|
};
|
||||||
});
|
|
||||||
default = rust-demo;
|
default = rust-demo;
|
||||||
};
|
};
|
||||||
apps.default = flake-utils.lib.mkApp {
|
apps.default = flake-utils.lib.mkApp {
|
||||||
|
|
|
||||||
20
templates/rust/nix/cargo-artifacts.nix
Normal file
20
templates/rust/nix/cargo-artifacts.nix
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
basicArgs,
|
||||||
|
buildInputs,
|
||||||
|
nativeBuildInputs,
|
||||||
|
}: let
|
||||||
|
f = {
|
||||||
|
craneLib,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
} @ args: let
|
||||||
|
genInputs = lib.genInputsWith args;
|
||||||
|
in
|
||||||
|
craneLib.buildDepsOnly (basicArgs
|
||||||
|
// {
|
||||||
|
buildInputs = genInputs buildInputs;
|
||||||
|
nativeBuildInputs = genInputs nativeBuildInputs;
|
||||||
|
});
|
||||||
|
in
|
||||||
|
with lib; setFunctionArgs f ((functionArgs f) // (genFunctionArgs (buildInputs ++ nativeBuildInputs)))
|
||||||
13
templates/rust/nix/lib.nix
Normal file
13
templates/rust/nix/lib.nix
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
flip,
|
||||||
|
pipe,
|
||||||
|
splitString,
|
||||||
|
head,
|
||||||
|
listToAttrs,
|
||||||
|
nameValuePair,
|
||||||
|
getAttrFromPath,
|
||||||
|
...
|
||||||
|
}: {
|
||||||
|
genFunctionArgs = flip pipe [(map (flip pipe [(splitString ".") head (flip nameValuePair false)])) listToAttrs];
|
||||||
|
genInputsWith = pkgs: map (flip pipe [(splitString ".") (flip getAttrFromPath pkgs)]);
|
||||||
|
}
|
||||||
30
templates/rust/nix/package.nix
Normal file
30
templates/rust/nix/package.nix
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
basicArgs,
|
||||||
|
buildInputs,
|
||||||
|
nativeBuildInputs,
|
||||||
|
}: let
|
||||||
|
f = {
|
||||||
|
craneLib,
|
||||||
|
lib,
|
||||||
|
cargoArtifacts,
|
||||||
|
...
|
||||||
|
} @ args: let
|
||||||
|
genInputs = lib.genInputsWith args;
|
||||||
|
in
|
||||||
|
craneLib.buildPackage (basicArgs
|
||||||
|
// {
|
||||||
|
inherit
|
||||||
|
(craneLib.crateNameFromCargoToml {
|
||||||
|
cargoToml = "${toString basicArgs.src}/Cargo.toml";
|
||||||
|
})
|
||||||
|
pname
|
||||||
|
version
|
||||||
|
;
|
||||||
|
inherit cargoArtifacts;
|
||||||
|
buildInputs = genInputs buildInputs;
|
||||||
|
nativeBuildInputs = genInputs nativeBuildInputs;
|
||||||
|
doCheck = false;
|
||||||
|
});
|
||||||
|
in
|
||||||
|
with lib; setFunctionArgs f ((functionArgs f) // (genFunctionArgs (buildInputs ++ nativeBuildInputs)))
|
||||||
Loading…
Add table
Add a link
Reference in a new issue