Simplified flake definition

This commit is contained in:
Erwin Boskma 2021-11-20 17:37:14 +01:00
parent 48298b3190
commit 553d4d8760
Signed by: erwin
GPG key ID: 270B20D17394F7E5
5 changed files with 66 additions and 116 deletions

2
.gitignore vendored
View file

@ -1 +1,3 @@
/target /target
.direnv
result

View file

@ -1,51 +1,7 @@
# (import ( (import (
# fetchTarball { fetchTarball {
# url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
# sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; } sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; }
# ) { ) {
# src = ./.; src = ./.;
# }).defaultNix }).defaultNix
{ lib
, naersk
, stdenv
, clangStdenv
, hostPlatform
, targetPlatform
, pkg-config
, libiconv
, rustfmt
, cargo
, rustc
, openssl
}:
let cargoToml = (builtins.fromTOML (builtins.readFile ./Cargo.toml));
in
naersk.lib."${targetPlatform.system}".buildPackage rec {
src = ./.;
buildInputs = [
rustfmt
pkg-config
cargo
rustc
libiconv
openssl
];
checkInputs = [ cargo rustc ];
doCheck = true;
CARGO_BUILD_INCREMENTAL = "false";
RUST_BACKTRACE = "full";
copyLibs = true;
name = cargoToml.package.name;
version = cargoToml.package.version;
meta = with lib; {
description = cargoToml.package.description;
homepage = cargoToml.package.homepage;
license = with licenses; [ mit ];
maintainers = with maintainers; [ ];
};
}

View file

@ -51,7 +51,23 @@
"root": { "root": {
"inputs": { "inputs": {
"naersk": "naersk", "naersk": "naersk",
"nixpkgs": "nixpkgs_2" "nixpkgs": "nixpkgs_2",
"utils": "utils"
}
},
"utils": {
"locked": {
"lastModified": 1637014545,
"narHash": "sha256-26IZAc5yzlD9FlDT54io1oqG/bBoyka+FJk5guaX4x4=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "bba5dcc8e0b20ab664967ad83d24d64cb64ec4f4",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
} }
} }
}, },

View file

@ -3,74 +3,43 @@
inputs = { inputs = {
naersk.url = "github:nmattia/naersk/master"; naersk.url = "github:nmattia/naersk/master";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
}; };
outputs = { self, nixpkgs, naersk }: outputs = { self, nixpkgs, utils, naersk }:
let utils.lib.eachDefaultSystem (system:
cargoToml = (builtins.fromTOML (builtins.readFile ./Cargo.toml)); let
supportedSystems = [ "x86_64-linux" "aarch64-linux" ]; pkgs = import nixpkgs { inherit system; };
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system); naersk-lib = pkgs.callPackage naersk { };
in in
{ rec {
overlay = final: prev: { overlay = final: prev: {
"${cargoToml.package.name}" = final.callPackage ./. { inherit naersk; }; ha-now-playing = final.callPackage ./.;
};
packages = forAllSystems (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
self.overlay
];
};
in
{
"${cargoToml.package.name}" = pkgs."${cargoToml.package.name}";
});
defaultPackage = forAllSystems (system: (import nixpkgs {
inherit system;
overlays = [ self.overlay ];
})."${cargoToml.package.name}");
checks = forAllSystems (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlay ];
};
in
{
format = pkgs.runCommand "check-format"
{
buildInputs = with pkgs; [ rustfmt cargo ];
} ''
${pkgs.rustfmt}/bin/cargo-fmt fmt --manifest-path ${./.}/Cargo.toml -- --check
${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt --check ${./.}
touch $out
'';
"${cargoToml.package.name}" = pkgs."${cargoToml.package.name}";
}
);
devShell = forAllSystems (system:
let pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlay ];
}; };
in
pkgs.mkShell { packages.ha-now-playing = naersk-lib.buildPackage {
inputsFrom = with pkgs; [ pname = "ha-now-playing";
pkgs."${cargoToml.package.name}" root = ./.;
buildInputs = with pkgs;[
openssl
]; ];
buildInputs = with pkgs; [ nativeBuildInputs = with pkgs; [
rustfmt pkg-config
nixpkgs-fmt
]; ];
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib"; };
} defaultPackage = packages.ha-now-playing;
);
}; apps.ha-now-playing = utils.lib.mkApp {
drv = self.defaultPackage."${system}";
};
defaultApp = apps.ha-now-playing;
devShell = with pkgs; mkShell {
buildInputs = [ cargo rustc rustfmt pre-commit rustPackages.clippy ];
RUST_SRC_PATH = rustPlatform.rustLibSrc;
};
});
} }

7
shell.nix Normal file
View file

@ -0,0 +1,7 @@
(import (
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; }
) {
src = ./.;
}).shellNix