Update to use crane

This commit is contained in:
lelgenio 2023-02-08 21:34:16 -03:00
parent afe472b3e3
commit 19ece99761
3 changed files with 230 additions and 33 deletions

View file

@ -1,22 +1,138 @@
{ {
"nodes": { "nodes": {
"nixpkgs": { "advisory-db": {
"flake": false,
"locked": { "locked": {
"lastModified": 1673800717, "lastModified": 1675868798,
"narHash": "sha256-SFHraUqLSu5cC6IxTprex/nTsI81ZQAtDvlBvGDWfnA=", "narHash": "sha256-ghS+rNMYKidm9HQtRQQ1SRs30SXRR11s73GjtXfyWG4=",
"path": "/nix/store/d6vlzbp9x6ixk1d1gr7if0f2ji6s8q4v-source", "owner": "rustsec",
"rev": "2f9fd351ec37f5d479556cd48be4ca340da59b8f", "repo": "advisory-db",
"type": "path" "rev": "b485cf4db1e37d03433c505c7675c2656f59874a",
"type": "github"
}, },
"original": { "original": {
"id": "nixpkgs", "owner": "rustsec",
"type": "indirect" "repo": "advisory-db",
"type": "github"
}
},
"crane": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"nixpkgs": [
"nixpkgs"
],
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1675814591,
"narHash": "sha256-RuO67fK41LFbKmcE3m1BoIAfFOcrpAlk0jGso/kWK1c=",
"owner": "ipetkov",
"repo": "crane",
"rev": "972ef2af69c4b25ec6c8583f55f7b07c956c811c",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1673956053,
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1675698036,
"narHash": "sha256-BgsQkQewdlQi8gapJN4phpxkI/FCE/2sORBaFcYbp/A=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "1046c7b92e908a1202c0f1ba3fc21d19e1cf1b62",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
} }
}, },
"root": { "root": {
"inputs": { "inputs": {
"advisory-db": "advisory-db",
"crane": "crane",
"flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
} }
},
"rust-overlay": {
"inputs": {
"flake-utils": [
"crane",
"flake-utils"
],
"nixpkgs": [
"crane",
"nixpkgs"
]
},
"locked": {
"lastModified": 1675391458,
"narHash": "sha256-ukDKZw922BnK5ohL9LhwtaDAdCsJL7L6ScNEyF1lO9w=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "383a4acfd11d778d5c2efcf28376cbd845eeaedf",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

121
flake.nix
View file

@ -1,29 +1,110 @@
{ {
description = "Pick emojis using dmenu"; description = "Build a cargo project";
inputs = { };
outputs = { self, nixpkgs, ... }: inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
};
outputs = { self, nixpkgs, crane, flake-utils, advisory-db, ... }:
flake-utils.lib.eachDefaultSystem (system:
let let
system = "x86_64-linux"; pkgs = import nixpkgs {
pkgs = nixpkgs.legacyPackages.${system}; inherit system;
definition = { pkgs, languages ? [ ] }:
pkgs.rustPlatform.buildRustPackage {
pname = "demoji";
version = "0.1";
src = pkgs.lib.cleanSource ./.;
cargoLock.lockFile = ./Cargo.lock;
cargoBuildFlags = if languages == [ ] then "--all-features" else "--features ${pkgs.lib.concatStringSep "," languages}";
}; };
outputs = with pkgs; { inherit (pkgs) lib;
packages.${system} = {
default = self.packages.${system}.demoji; craneLib = crane.lib.${system};
demoji = pkgs.callPackage definition { }; src = craneLib.cleanCargoSource ./.;
buildInputs = [
# Add additional build inputs here
];
# Build *just* the cargo dependencies, so we can reuse
# all of that work (e.g. via cachix) when running in CI
cargoArtifacts = craneLib.buildDepsOnly {
inherit src buildInputs;
}; };
devShells.${system}.default = # Build the actual crate itself, reusing the dependency
mkShell { nativeBuildInputs = [ xorg.libxcb ]; }; # artifacts from above.
my-crate = craneLib.buildPackage {
inherit cargoArtifacts src buildInputs;
};
in
{
checks = {
# Build the crate as part of `nix flake check` for convenience
inherit my-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.
my-crate-clippy = craneLib.cargoClippy {
inherit cargoArtifacts src buildInputs;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}; };
in outputs; my-crate-doc = craneLib.cargoDoc {
inherit cargoArtifacts src buildInputs;
};
# Check formatting
my-crate-fmt = craneLib.cargoFmt {
inherit src;
};
# Audit dependencies
my-crate-audit = craneLib.cargoAudit {
inherit src advisory-db;
};
# Run tests with cargo-nextest
# Consider setting `doCheck = false` on `my-crate` if you do not want
# the tests to run twice
my-crate-nextest = craneLib.cargoNextest {
inherit cargoArtifacts src buildInputs;
partitions = 1;
partitionType = "count";
};
} // lib.optionalAttrs (system == "x86_64-linux") {
# NB: cargo-tarpaulin only supports x86_64 systems
# Check code coverage (note: this will not upload coverage anywhere)
my-crate-coverage = craneLib.cargoTarpaulin {
inherit cargoArtifacts src;
};
};
packages.default = my-crate;
apps.default = flake-utils.lib.mkApp {
drv = my-crate;
};
devShells.default = pkgs.mkShell {
inputsFrom = builtins.attrValues self.checks;
# Extra inputs can be added here
nativeBuildInputs = with pkgs; [
cargo
rustc
];
};
});
} }

View file

@ -2,7 +2,7 @@ use std::{io::Write, time::Duration};
use arboard::SetExtLinux; use arboard::SetExtLinux;
use clap::Parser; use clap::Parser;
use emoji; use emoji::lookup_by_glyph::iter_emoji;
/// Simple program to list all emojis /// Simple program to list all emojis
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
@ -39,7 +39,7 @@ fn main() {
} }
} }
fn pick_emoji_dmenu(c: &Vec<String>, args: &Args) -> char { fn pick_emoji_dmenu(c: &[String], args: &Args) -> char {
let child_stdout = if args.copy { let child_stdout = if args.copy {
std::process::Stdio::piped() std::process::Stdio::piped()
} else { } else {
@ -76,12 +76,12 @@ fn send_to_clipboard(out: String) {
let mut clip = arboard::Clipboard::new().unwrap(); let mut clip = arboard::Clipboard::new().unwrap();
clip.set().wait().text(out.clone()).unwrap(); clip.set().wait().text(out).unwrap();
} }
} }
fn write_emojis_to_stdout(args: &Args, mut out: impl Write) { fn write_emojis_to_stdout(args: &Args, mut out: impl Write) {
for emoji in emoji::lookup_by_glyph::iter_emoji() { for emoji in iter_emoji() {
let native_description = emoji_description(emoji, &args.lang); let native_description = emoji_description(emoji, &args.lang);
let fallback_description = emoji_description(emoji, "en"); let fallback_description = emoji_description(emoji, "en");
let basic_description = emoji.name.to_string(); let basic_description = emoji.name.to_string();