Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
Else Someone
cbce1ae3a2 default.nix: init
Move recipes from flake.nix:s `packages` to a `callPackage`-able scope.nix.
This way out-of-tree projects can reuse the `buildRustPackage`
definitions (e.g. the in-sync `cargoLock` hashes) without depending on
the unsupported flakes feature.
2026-03-21 02:03:02 +02:00
4 changed files with 87 additions and 25 deletions

22
default.nix Normal file
View file

@ -0,0 +1,22 @@
let
lockFile = builtins.fromJSON (builtins.readFile ./flake.lock);
flake-compat-node = lockFile.nodes.${lockFile.nodes.root.inputs.flake-compat};
flake-compat = builtins.fetchTarball {
inherit (flake-compat-node.locked) url;
sha256 = flake-compat-node.locked.narHash;
};
flake' = (
import flake-compat {
src = ./.;
}
);
flake = flake'.defaultNix;
in
{
useFlake ? true,
nixpkgs ? if useFlake then flake.inputs.nixpkgs else <nixpkgs>,
pkgs ? import nixpkgs { },
}:
pkgs.callPackage ./scope.nix { }

15
flake.lock generated
View file

@ -1,5 +1,19 @@
{
"nodes": {
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1751685974,
"narHash": "sha256-NKw96t+BgHIYzHUjkTK95FqYRVKB8DHpVhefWSz/kTw=",
"rev": "549f2762aebeff29a2e5ece7a7dc0f955281a1d1",
"type": "tarball",
"url": "https://git.lix.systems/api/v1/repos/lix-project/flake-compat/archive/549f2762aebeff29a2e5ece7a7dc0f955281a1d1.tar.gz?rev=549f2762aebeff29a2e5ece7a7dc0f955281a1d1"
},
"original": {
"type": "tarball",
"url": "https://git.lix.systems/lix-project/flake-compat/archive/main.tar.gz"
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": [
@ -38,6 +52,7 @@
},
"root": {
"inputs": {
"flake-compat": "flake-compat",
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs"
}

View file

@ -3,6 +3,10 @@
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
flake-compat = {
url = "https://git.lix.systems/lix-project/flake-compat/archive/main.tar.gz";
flake = false;
};
};
outputs =
@ -16,27 +20,7 @@
perSystem =
{ pkgs, ... }:
let
buildEnvVars = {
BIN_XDG_PERMISSION_STORE = "${pkgs.xdg-desktop-portal}/libexec/xdg-permission-store";
BIN_XDG_DOCUMENT_PORTAL = "${pkgs.xdg-desktop-portal}/libexec/xdg-document-portal";
BIN_VIRTIOFSD = "${pkgs.virtiofsd}/bin/virtiofsd";
};
rustPackage =
crate:
let
cargoToml = builtins.fromTOML (builtins.readFile ./${crate}/Cargo.toml);
in
pkgs.rustPlatform.buildRustPackage {
inherit (cargoToml.package) name version;
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
cargoLock.outputHashes = {
"busd-0.5.0" = "sha256-IZZ2MeEmUbzRrH6SUz0pnecMH4f8Mh54WdhI4q44YfI=";
};
buildAndTestSubdir = crate;
env = buildEnvVars;
};
scope = pkgs.callPackage ./scope.nix { };
in
{
devShells.default = pkgs.mkShell {
@ -46,11 +30,11 @@
rust-analyzer
clippy
];
env = buildEnvVars;
env = scope.buildEnvVars;
};
packages = {
inherit (scope) sidebus-agent sidebus-broker;
};
packages.sidebus-agent = rustPackage "sidebus-agent";
packages.sidebus-broker = rustPackage "sidebus-broker";
};
flake = {

41
scope.nix Normal file
View file

@ -0,0 +1,41 @@
{ lib, newScope }:
lib.makeScope newScope (self: {
forgetScope = lib.flip lib.removeAttrs [
"override"
"overrideDerivation"
"overrideScope"
"newScope"
"packages"
"forgetScope"
];
buildEnvVars = self.forgetScope (
self.callPackage (
{ xdg-desktop-portal, virtiofsd }:
{
BIN_XDG_PERMISSION_STORE = "${xdg-desktop-portal}/libexec/xdg-permission-store";
BIN_XDG_DOCUMENT_PORTAL = "${xdg-desktop-portal}/libexec/xdg-document-portal";
BIN_VIRTIOFSD = "${virtiofsd}/bin/virtiofsd";
}
) { }
);
rustPackage =
{
crate,
cargoToml ? builtins.fromTOML (builtins.readFile ./${crate}/Cargo.toml),
rustPlatform,
buildEnvVars,
}:
rustPlatform.buildRustPackage {
inherit (cargoToml.package) name version;
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
cargoLock.outputHashes = {
"busd-0.5.0" = "sha256-IZZ2MeEmUbzRrH6SUz0pnecMH4f8Mh54WdhI4q44YfI=";
};
buildAndTestSubdir = crate;
env = buildEnvVars;
};
sidebus-agent = self.callPackage self.rustPackage { crate = "sidebus-agent"; };
sidebus-broker = self.callPackage self.rustPackage { crate = "sidebus-broker"; };
})