From d48ec1fb888d573b784feb3952452268f54ae538 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 13 Oct 2024 15:28:27 +0300 Subject: [PATCH 1/4] nix: clean up; generalize; enable parallel builds --- flake.nix | 48 ++++++++++++++++++++--------------------- nix/default.nix | 48 ++++++++++++++++++++--------------------- nix/plugins/default.nix | 44 ++++++++++++++++++++++++------------- 3 files changed, 76 insertions(+), 64 deletions(-) diff --git a/flake.nix b/flake.nix index 6efd6f7..82e52be 100644 --- a/flake.nix +++ b/flake.nix @@ -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; @@ -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 = { diff --git a/nix/default.nix b/nix/default.nix index 84de293..2b231dc 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,8 +1,8 @@ { + inputs, lib, - makeWrapper, - lockFile, # Dependencies for Anyrun + makeWrapper, glib, rustPlatform, atk, @@ -17,25 +17,24 @@ # 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 - ]; + enableParallelBuilding = true; + strictDeps = true; cargoLock = { inherit lockFile; @@ -51,20 +50,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)" \ @@ -75,18 +84,7 @@ in description = "A wayland native, highly customizable runner."; homepage = "https://github.com/Kirottu/anyrun"; license = with lib.licenses; [gpl3]; - maintainers = [ - { - email = "neo@neoney.dev"; - github = "n3oney"; - githubId = 30625554; - name = "MichaƂ Minarowski"; - } - { - email = "raf@notashelf.dev"; - github = "NotAShelf"; - } - ]; mainProgram = "anyrun"; + maintainers = with lib.maintainers; [NotAShelf n3oney]; }; } diff --git a/nix/plugins/default.nix b/nix/plugins/default.nix index cca1f64..b145819 100644 --- a/nix/plugins/default.nix +++ b/nix/plugins/default.nix @@ -1,5 +1,7 @@ { + inputs, lib, + # Common dependencies for the plugin glib, makeWrapper, rustPlatform, @@ -8,45 +10,57 @@ 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 - ]; + enableParallelBuilding = true; + 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]; }; } From e88f65ccf020b80f42ca0f4d7040ed33673324f3 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 13 Oct 2024 15:28:48 +0300 Subject: [PATCH 2/4] ci/cargo-build: make nix devshell impure --- .github/workflows/cargo-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cargo-build.yml b/.github/workflows/cargo-build.yml index 655807c..1fa4145 100644 --- a/.github/workflows/cargo-build.yml +++ b/.github/workflows/cargo-build.yml @@ -22,7 +22,7 @@ jobs: - uses: DeterminateSystems/magic-nix-cache-action@main - name: Install dependencies - run: nix develop -i + run: nix develop --impure - uses: actions-rs/toolchain@v1 name: Install rust toolchain From 50dea18ce3a65881805a0ab1a0740be69fcf8a93 Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Sun, 13 Oct 2024 23:15:54 +0300 Subject: [PATCH 3/4] CI: fix devshell loading --- .github/workflows/cargo-build.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/cargo-build.yml b/.github/workflows/cargo-build.yml index 1fa4145..782ae30 100644 --- a/.github/workflows/cargo-build.yml +++ b/.github/workflows/cargo-build.yml @@ -21,8 +21,7 @@ jobs: - uses: cachix/install-nix-action@v26 - uses: DeterminateSystems/magic-nix-cache-action@main - - name: Install dependencies - run: nix develop --impure + - uses: nicknovitski/nix-develop@v1 - uses: actions-rs/toolchain@v1 name: Install rust toolchain From bd8e62dd0a9552196a561d13d3ce729f87b2c578 Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Sun, 13 Oct 2024 23:18:40 +0300 Subject: [PATCH 4/4] Nix: remove redundant enableParallelBuilding --- nix/default.nix | 1 - nix/plugins/default.nix | 1 - 2 files changed, 2 deletions(-) diff --git a/nix/default.nix b/nix/default.nix index 2b231dc..b7e4849 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -33,7 +33,6 @@ in name = "${pname}-${version}"; }; - enableParallelBuilding = true; strictDeps = true; cargoLock = { diff --git a/nix/plugins/default.nix b/nix/plugins/default.nix index b145819..06143df 100644 --- a/nix/plugins/default.nix +++ b/nix/plugins/default.nix @@ -31,7 +31,6 @@ in inherit lockFile; }; - enableParallelBuilding = true; strictDeps = true; nativeBuildInputs = [