add a nix flake

This commit is contained in:
kalmenn 2026-02-02 13:01:35 +01:00
parent e85ac6a5e5
commit a30cf9a16f
Signed by: kalmenn
GPG key ID: F500055C44BC3834
2 changed files with 166 additions and 0 deletions

64
flake.lock generated Normal file
View file

@ -0,0 +1,64 @@
{
"nodes": {
"crane": {
"locked": {
"lastModified": 1769737823,
"narHash": "sha256-DrBaNpZ+sJ4stXm+0nBX7zqZT9t9P22zbk6m5YhQxS4=",
"owner": "ipetkov",
"repo": "crane",
"rev": "b2f45c3830aa96b7456a4c4bc327d04d7a43e1ba",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1769996383,
"narHash": "sha256-AnYjnFWgS49RlqX7LrC4uA+sCCDBj0Ry/WOJ5XWAsa0=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "57928607ea566b5db3ad13af0e57e921e6b12381",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1769900590,
"narHash": "sha256-I7Lmgj3owOTBGuauy9FL6qdpeK2umDoe07lM4V+PnyA=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "41e216c0ca66c83b12ab7a98cc326b5db01db646",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-25.11",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"crane": "crane",
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

102
flake.nix Normal file
View file

@ -0,0 +1,102 @@
{
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.
];
};
};
});
}