git-identity/flake.nix
2026-02-02 13:01:35 +01:00

102 lines
2.8 KiB
Nix

{
description = "manages multiple identities (e.g. personal, work, university, ...) in git repos for you";
inputs = {
crane.url = "github:ipetkov/crane";
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
};
outputs = inputs @ { self, crane, ... }:
inputs.flake-parts.lib.mkFlake { inherit inputs; } ({ lib, ... }: {
systems = [ "x86_64-linux" "aarch64-linux" ];
perSystem = { pkgs, self', system, ... }: let
buildInputs = with pkgs; [
gpgme
pkg-config
];
nativeBuildInputs = with pkgs; [
pkg-config
];
crateSrc = lib.cleanSourceWith {
src = self.outPath;
filter = name: type: builtins.all (f: f name type) [
lib.sources.cleanSourceFilter
(name: type: !(builtins.elem (builtins.baseNameOf name) [ "flake.nix" "flake.lock" ]))
];
};
craneArgs = {
src = crateSrc;
strictDeps = true;
inherit buildInputs nativeBuildInputs;
};
craneLib = crane.mkLib pkgs;
# Build the dependencies with different parameters
cargoArtifacts = craneLib.buildDepsOnly craneArgs;
cargoTOML = builtins.fromTOML (builtins.readFile ./Cargo.toml);
in {
packages.xtask = (craneLib.buildPackage ( craneArgs // {
inherit cargoArtifacts;
cargoExtraArgs = "--package xtask";
meta = {
licences = with lib.licences; [mit asl20];
platforms = [ system ];
mainProgram = "xtask";
};
}));
packages.default = (craneLib.buildPackage ( craneArgs // {
inherit cargoArtifacts;
nativeBuildInputs = craneArgs.nativeBuildInputs ++ [ self'.packages.xtask ];
postInstall = let
manDir = "$out/share/man/man1";
in ''
mkdir -p "${manDir}"
xtask manpage "${manDir}"
find "${manDir}" -type f -exec gzip {} \;
'';
meta = {
licences = with lib.licences; [mit asl20];
platforms = [ system ];
mainProgram = cargoTOML.package.name;
}
// lib.optionalAttrs (lib.attrsets.hasAttrByPath ["package" "description"] cargoTOML) {
inherit (cargoTOML.package) description;
};
}));
apps.default = {
type = "app";
program = let pkg = self'.packages.default; in "${pkg}/bin/${pkg.pname}";
};
devShells.default = craneLib.devShell {
checks = self'.checks;
inherit buildInputs nativeBuildInputs;
packages = with pkgs; [
# Cargo and rustc are provided by default.
];
};
};
});
}