Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix: clean up; generalize #189

Merged
merged 5 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/cargo-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ jobs:
- uses: cachix/install-nix-action@v26
- uses: DeterminateSystems/magic-nix-cache-action@main

- name: Install dependencies
run: nix develop -i
- uses: nicknovitski/nix-develop@v1

- uses: actions-rs/toolchain@v1
name: Install rust toolchain
Expand Down
48 changes: 24 additions & 24 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,6 @@
}: let
inherit (pkgs) callPackage;
in {
# provide the formatter for nix fmt
formatter = pkgs.alejandra;

devShells = {
default = pkgs.mkShell {
inputsFrom = builtins.attrValues self'.packages;
packages = with pkgs; [
rustc # rust compiler
gcc
cargo # rust package manager
clippy # opinionated rust formatter
];
};

nix = pkgs.mkShellNoCC {
packages = with pkgs; [
alejandra # nix formatter
rustfmt # rust formatter
statix # lints and suggestions
deadnix # clean up unused nix code
];
};
};

packages = let
lockFile = ./Cargo.lock;

Expand Down Expand Up @@ -91,6 +67,30 @@

# Set up an overlay from packages exposed by this flake
overlayAttrs = config.packages;

devShells = {
default = pkgs.mkShell {
inputsFrom = builtins.attrValues self'.packages;
packages = with pkgs; [
rustc # rust compiler
gcc
cargo # rust package manager
clippy # opinionated rust formatter
];
};

nix = pkgs.mkShellNoCC {
packages = with pkgs; [
alejandra # nix formatter
rustfmt # rust formatter
statix # lints and suggestions
deadnix # clean up unused nix code
];
};
};

# provide the formatter for nix fmt
formatter = pkgs.alejandra;
};

flake = {
Expand Down
47 changes: 22 additions & 25 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
inputs,
lib,
makeWrapper,
lockFile,
# Dependencies for Anyrun
makeWrapper,
glib,
rustPlatform,
atk,
Expand All @@ -17,25 +17,23 @@
# derivation. By default, we should not build
# any of the plugins.
dontBuildPlugins ? true,
lockFile,
...
}: let
inherit (builtins) fromTOML readFile;

cargoToml = fromTOML (readFile ../anyrun/Cargo.toml);
pname = cargoToml.package.name;
version = cargoToml.package.version;
in
rustPlatform.buildRustPackage {
inherit pname version;
src = ../.;
src = builtins.path {
path = lib.sources.cleanSource inputs.self;
name = "${pname}-${version}";
};

buildInputs = [
pkg-config
glib
atk
gtk3
librsvg
gtk-layer-shell
];
strictDeps = true;

cargoLock = {
inherit lockFile;
Expand All @@ -51,20 +49,30 @@ in
cargo
];

buildInputs = [
glib
atk
gtk3
librsvg
gtk-layer-shell
];

cargoBuildFlags =
if dontBuildPlugins
then ["-p ${pname}"]
else [];

doCheck = true;
CARGO_BUILD_INCREMENTAL = "false";
RUST_BACKTRACE = "full";
copyLibs = true;

buildAndTestSubdir =
if dontBuildPlugins
then pname
else null;

CARGO_BUILD_INCREMENTAL = "false";
RUST_BACKTRACE = "full";

postInstall = ''
wrapProgram $out/bin/anyrun \
--set GDK_PIXBUF_MODULE_FILE "$(echo ${librsvg.out}/lib/gdk-pixbuf-2.0/*/loaders.cache)" \
Expand All @@ -75,18 +83,7 @@ in
description = "A wayland native, highly customizable runner.";
homepage = "https://github.com/Kirottu/anyrun";
license = with lib.licenses; [gpl3];
maintainers = [
{
email = "[email protected]";
github = "n3oney";
githubId = 30625554;
name = "Michał Minarowski";
}
{
email = "[email protected]";
github = "NotAShelf";
}
];
mainProgram = "anyrun";
maintainers = with lib.maintainers; [NotAShelf n3oney];
};
}
43 changes: 28 additions & 15 deletions nix/plugins/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
inputs,
lib,
# Common dependencies for the plugin
glib,
makeWrapper,
rustPlatform,
Expand All @@ -8,45 +10,56 @@
gtk-layer-shell,
pkg-config,
librsvg,
inputs,
# Generic args
name,
lockFile,
extraInputs ? [], # allow appending buildInputs
...
}: let
cargoToml = builtins.fromTOML (builtins.readFile ../../plugins/${name}/Cargo.toml);
pname = cargoToml.package.name;
version = cargoToml.package.version;
in
rustPlatform.buildRustPackage {
pname = cargoToml.package.name;
version = cargoToml.package.version;
inherit pname version;

src = "${inputs.self}";
src = builtins.path {
path = lib.sources.cleanSource inputs.self;
name = "${pname}-${version}";
};
cargoLock = {
inherit lockFile;
};

buildInputs = [
glib
atk
gtk3
librsvg
gtk-layer-shell
];
strictDeps = true;

nativeBuildInputs = [
pkg-config
makeWrapper
];

buildInputs =
[
glib
atk
gtk3
librsvg
gtk-layer-shell
]
++ extraInputs;

doCheck = true;
CARGO_BUILD_INCREMENTAL = "false";
RUST_BACKTRACE = "full";
copyLibs = true;
cargoBuildFlags = ["-p ${name}"];
buildAndTestSubdir = "plugins/${name}";

meta = with lib; {
CARGO_BUILD_INCREMENTAL = "false";
RUST_BACKTRACE = "full";

meta = {
description = "The ${name} plugin for Anyrun";
homepage = "https://github.com/Kirottu/anyrun";
license = with licenses; [gpl3];
license = with lib.licenses; [gpl3];
maintainers = with lib.maintainers; [NotAShelf n3oney];
};
}
Loading