flake: Rewrite to use flake-parts and crane

This commit is contained in:
Erwin Boskma 2024-08-19 19:20:35 +02:00
parent fed01275fd
commit e37f6f6e47
Signed by: erwin
SSH key fingerprint: SHA256:/Wk1WZdLg+vQHs3in9qq7PsIp8SMzwGSk/RLZ5zPuZk
2 changed files with 126 additions and 85 deletions

View file

@ -1,41 +1,40 @@
{ {
"nodes": { "nodes": {
"flake-utils": { "crane": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"naersk": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
] ]
}, },
"locked": { "locked": {
"lastModified": 1721727458, "lastModified": 1724006180,
"narHash": "sha256-r/xppY958gmZ4oTfLiHN0ZGuQ+RSTijDblVgVLFi1mw=", "narHash": "sha256-PVxPj0Ga2fMYMtcT9ARCthF+4U71YkOT7ZjgD/vf1Aw=",
"owner": "nmattia", "owner": "ipetkov",
"repo": "naersk", "repo": "crane",
"rev": "3fb418eaf352498f6b6c30592e3beb63df42ef11", "rev": "7ce92819802bc583b7e82ebc08013a530f22209f",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nmattia", "owner": "ipetkov",
"ref": "master", "repo": "crane",
"repo": "naersk", "type": "github"
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1722555600,
"narHash": "sha256-XOQkdLafnb/p9ij77byFQjDf5m5QYl9b2REiVClC+x4=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "8471fe90ad337a8074e957b69ca4d0089218391d",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github" "type": "github"
} }
}, },
@ -55,10 +54,22 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs-lib": {
"locked": {
"lastModified": 1722555339,
"narHash": "sha256-uFf2QeW7eAHlYXuDktm9c25OxOyCoUOQmh5SZ9amE5Q=",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/a5d394176e64ab29c852d03346c1fc9b0b7d33eb.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/a5d394176e64ab29c852d03346c1fc9b0b7d33eb.tar.gz"
}
},
"root": { "root": {
"inputs": { "inputs": {
"flake-utils": "flake-utils", "crane": "crane",
"naersk": "naersk", "flake-parts": "flake-parts",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay" "rust-overlay": "rust-overlay"
} }
@ -82,21 +93,6 @@
"repo": "rust-overlay", "repo": "rust-overlay",
"type": "github" "type": "github"
} }
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

127
flake.nix
View file

@ -1,60 +1,105 @@
{ {
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils"; flake-parts.url = "github:hercules-ci/flake-parts";
naersk = { crane = {
url = "github:nmattia/naersk/master"; url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
rust-overlay = { rust-overlay = {
url = "github:oxalica/rust-overlay"; url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
}; };
}; };
outputs = { outputs =
self, { self, ... }@inputs:
nixpkgs, inputs.flake-parts.lib.mkFlake { inherit inputs; } {
flake-utils, systems = [ "x86_64-linux" ];
naersk,
rust-overlay,
}:
flake-utils.lib.eachDefaultSystem (system: let
overlays = [(import rust-overlay)];
pkgs = import nixpkgs {inherit system overlays;};
naersk-lib = pkgs.callPackage naersk {};
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; imports = [ inputs.flake-parts.flakeModules.easyOverlay ];
buildInputs = [ perSystem =
rustToolchain {
pkgs.libpulseaudio.dev pkgs,
]; system,
nativeBuildInputs = [ config,
pkgs.pkgconf ...
]; }:
in rec { let
packages.pamedia = naersk-lib.buildPackage { overlays = [ (import inputs.rust-overlay) ];
inherit buildInputs nativeBuildInputs;
root = ./.; rustToolchain = pkgs.rust-bin.stable.latest.default.override {
pname = "pamedia"; extensions = [
}; "rustfmt"
packages.default = packages.pamedia; "clippy"
];
};
defaultApp = flake-utils.lib.mkApp { crane-lib = (inputs.crane.mkLib pkgs).overrideToolchain rustToolchain;
drv = self.defaultPackage."${system}";
};
overlays = final: prev: { pname = "pamedia";
pamedia = packages.pamedia; version = "0.3.0";
};
devShell = with pkgs; src = crane-lib.cleanCargoSource ./.;
mkShell {
buildInputs = [cargo rustc rustfmt pre-commit rustPackages.clippy cargo-edit cargo-feature cargo-outdated rust-analyzer] ++ buildInputs; buildInputs = [
nativeBuildInputs = [libnotify] ++ nativeBuildInputs; rustToolchain
pkgs.libpulseaudio.dev
];
nativeBuildInputs = [ pkgs.pkg-config ];
cargoArtifacts = crane-lib.buildDepsOnly {
inherit
src
buildInputs
nativeBuildInputs
pname
version
;
};
pamedia = crane-lib.buildPackage {
inherit
cargoArtifacts
src
buildInputs
nativeBuildInputs
pname
version
;
};
in
{
_module.args.pkgs = import inputs.nixpkgs { inherit system overlays; };
packages = {
inherit pamedia;
};
packages.default = config.packages.pamedia;
overlayAttrs = {
inherit (config.packages) pamedia;
};
devShells.default =
with pkgs;
mkShell {
packages = [
cargo
rustc
rustfmt
pre-commit
rustPackages.clippy
cargo-edit
cargo-feature
rust-analyzer
libnotify
];
inputsFrom = [ config.packages.pamedia ];
};
}; };
}); };
} }