Skip to content

Commit

Permalink
nix: logically split packaging to not be flake-dependent (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
itslychee authored Jun 7, 2024
1 parent b0a0835 commit 47f6c1e
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 51 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
result
.direnv
result
36 changes: 4 additions & 32 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,32 +1,4 @@
{
rustPlatform,
gtk4,
glib,
polkit,
pkg-config,
}: let
polkitAgentPath = "${polkit}/lib/polkit-1/polkit-agent-helper-1";
pname = "soteria";
version = "0.1.0";
in
rustPlatform.buildRustPackage rec {
inherit pname version;
POLKIT_AGENT_HELPER_PATH = polkitAgentPath;

nativeBuildInputs = [
pkg-config
];

buildInputs = [
gtk4
glib
polkit
];
inherit glib;

src = ./.;

cargoLock = {
lockFile = ./Cargo.lock;
};
}
{pkgs ? import <nixpkgs> {}}: rec {
soteria = pkgs.callPackage ./package.nix {};
default = soteria;
}
32 changes: 14 additions & 18 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,21 @@
nixpkgs,
}: let
supportedSystems = ["x86_64-linux"];
eachSystem = nixpkgs.lib.genAttrs supportedSystems;
eachSystem = f:
nixpkgs.lib.genAttrs supportedSystems
(system: f nixpkgs.legacyPackages.${system});
in {
packages = eachSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
soteria = pkgs.callPackage ./default.nix {};
default = self.packages.${system}.soteria;
packages = eachSystem (pkgs: import ./. {inherit pkgs;});
devShells = eachSystem (pkgs: {
default = pkgs.mkShell (let
soteria = self.packages.${pkgs.system}.default;
in {
inputsFrom = [soteria];
packages = builtins.attrValues {
inherit (pkgs) rust-analyzer rustfmt;
};
});
});

devShell = eachSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; in pkgs.mkShell {
packages = with pkgs; [
gtk4
glib
polkit
pkg-config
cargo
];
});

formatter = eachSystem (system: nixpkgs.legacyPackages.${system}.alejandra);
formatter = eachSystem (pkgs: pkgs.alejandra);
};
}
60 changes: 60 additions & 0 deletions package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
rustPlatform,
gtk4,
glib,
polkit,
lib,
pkg-config,
binutils,
}: let
inherit
(lib.fileset)
toSource
gitTracked
difference
unions
fileFilter
;
in
rustPlatform.buildRustPackage {
pname = "soteria";
version = "0.1.0";

nativeBuildInputs = [
pkg-config
binutils
];

buildInputs = [
gtk4
glib
polkit
];

# Takes advantage of nixpkgs manually editing PACKAGE_PREFIX by grabbing it from
# the binary itself.
# https://github.com/NixOS/nixpkgs/blob/9b5328b7f761a7bbdc0e332ac4cf076a3eedb89b/pkgs/development/libraries/polkit/default.nix#L142
# https://github.com/polkit-org/polkit/blob/d89c3604e2a86f4904566896c89e1e6b037a6f50/src/polkitagent/polkitagentsession.c#L599
preBuild = ''
export POLKIT_AGENT_HELPER_PATH="$(strings ${polkit.out}/lib/libpolkit-agent-1.so | grep "polkit-agent-helper-1")"
'';

src = toSource {
root = ./.;
fileset =
difference (gitTracked ./.)
(unions [
./README.md
(fileFilter (file: file.hasExt "nix") ./.)
]);
};

cargoLock.lockFile = ./Cargo.lock;
meta = {
mainProgram = "soteria";
description = "A Polkit authentication agent written in GTK designed to be used with any desktop environment";
homepage = "https://github.com/ImVaskel/soteria";
platforms = lib.platforms.linux;
license = lib.licenses.asl20;
};
}

0 comments on commit 47f6c1e

Please sign in to comment.