flake.nix: improve

used https://github.com/nix-community/comma/blob/master/flake.nix as a
base
This commit is contained in:
Artturin 2022-11-27 20:22:18 +02:00
parent e351b88257
commit 7419804f9f
2 changed files with 63 additions and 141 deletions

View File

@ -1,27 +1,10 @@
{
"nodes": {
"fenix": {
"inputs": {
"nixpkgs": "nixpkgs",
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1665384826,
"narHash": "sha256-TV0Dc/Gd+TPtJQhv30/aF01IJVHpWDc2zCmsH70+IDI=",
"owner": "nix-community",
"repo": "fenix",
"rev": "40b9fa9acfa71caa304de9a2d07a937023b68143",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"naersk": {
"inputs": {
"nixpkgs": "nixpkgs_2"
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1662220400,
@ -33,86 +16,41 @@
},
"original": {
"owner": "nix-community",
"ref": "master",
"repo": "naersk",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1665259268,
"narHash": "sha256-ONFhHBLv5nZKhwV/F2GOH16197PbvpyWhoO0AOyktkU=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "c5924154f000e6306030300592f4282949b2db6c",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1665296151,
"narHash": "sha256-uOB0oxqxN9K7XGF1hcnY+PQnlQJ+3bP2vCn/+Ru/bbc=",
"lastModified": 1669535121,
"narHash": "sha256-koZLM7oWVGrjyHnYDo7/w5qlmUn9UZUKSFNfmIjueE8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "14ccaaedd95a488dd7ae142757884d8e125b3363",
"rev": "b45ec953794bb07922f0468152ad1ebaf8a084b3",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_3": {
"locked": {
"lastModified": 1665296151,
"narHash": "sha256-uOB0oxqxN9K7XGF1hcnY+PQnlQJ+3bP2vCn/+Ru/bbc=",
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"rev": "14ccaaedd95a488dd7ae142757884d8e125b3363",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"fenix": "fenix",
"naersk": "naersk",
"nixpkgs": "nixpkgs_3",
"nixpkgs": "nixpkgs",
"utils": "utils"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1665247575,
"narHash": "sha256-Ssoxr1ggoPsvFBsCWNQTleYLOTqx6hFKFvktzGDC51A=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "61504c8d951c566eb03037dcb300c96f4bd9a8b6",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
},
"utils": {
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
},
"original": {

118
flake.nix
View File

@ -1,78 +1,62 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
naersk.url = "github:nix-community/naersk";
fenix.url = "github:nix-community/fenix";
naersk = {
url = "github:nix-community/naersk/master";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, utils, naersk, fenix }:
utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages."${system}";
rust = fenix.packages.${system}.stable.withComponents [
"cargo"
"rustc"
"rust-src" # just for rust-analyzer
"clippy"
];
# Override the version used in naersk
naersk-lib = naersk.lib."${system}".override {
cargo = rust;
rustc = rust;
};
in rec {
# `nix build`
packages.deadnix = naersk-lib.buildPackage {
pname = "deadnix";
src = ./.;
doCheck = true;
cargoTestCommands = x:
x ++ [
# clippy
''cargo clippy --all --all-features --tests -- \
-D clippy::pedantic \
-D warnings \
-A clippy::module-name-repetitions \
-A clippy::too-many-lines \
-A clippy::cast-possible-wrap \
-A clippy::cast-possible-truncation \
-A clippy::nonminimal_bool''
];
meta.description = "Scan Nix files for dead code";
};
packages.default = packages.deadnix;
checks = packages;
hydraJobs =
outputs = { self, nixpkgs, utils, naersk }:
let
inherit (nixpkgs) lib;
deadnixLambda = pkgs:
let
hydraSystems = [
"x86_64-linux"
"aarch64-linux"
];
naersk-lib = pkgs.callPackage naersk { };
in
if builtins.elem system hydraSystems
then builtins.mapAttrs (_: nixpkgs.lib.hydraJob) checks
else {};
naersk-lib.buildPackage {
pname = "deadnix";
root = ./.;
checkInputs = [ pkgs.rustPackages.clippy ];
doCheck = true;
cargoTestCommands = x:
x ++ [
''cargo clippy --all --all-features --tests -- \
-D clippy::pedantic \
-D warnings \
-A clippy::module-name-repetitions \
-A clippy::too-many-lines \
-A clippy::cast-possible-wrap \
-A clippy::cast-possible-truncation \
-A clippy::nonminimal_bool''
];
meta.description = "Scan Nix files for dead code";
};
in
utils.lib.eachDefaultSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
packages = {
default = self.packages."${system}".deadnix;
deadnix = deadnixLambda pkgs;
};
# `nix run`
apps.deadnix = utils.lib.mkApp {
drv = packages.deadnix;
};
apps.default = apps.deadnix;
apps.default = utils.lib.mkApp {
drv = self.packages."${system}".default;
};
# `nix develop`
devShells.default = pkgs.mkShell {
nativeBuildInputs = [
fenix.packages.${system}.rust-analyzer
] ++
(with packages.default; nativeBuildInputs ++ buildInputs);
};
}) // {
overlays.default = final: prev: {
inherit (self.packages.${prev.system})
deadnix
;
};
devShells.default = with pkgs; mkShell {
nativeBuildInputs = [ cargo rustc rustfmt rustPackages.clippy rust-analyzer ];
RUST_SRC_PATH = rustPlatform.rustLibSrc;
};
})
// {
overlays.default = (_: prev: {
deadnix = deadnixLambda prev;
});
};
}