diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..8bbf5d6 --- /dev/null +++ b/default.nix @@ -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 , + pkgs ? import nixpkgs { }, +}: + +pkgs.callPackage ./scope.nix { } diff --git a/flake.lock b/flake.lock index 8445fa1..b8b89ac 100644 --- a/flake.lock +++ b/flake.lock @@ -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" } diff --git a/flake.nix b/flake.nix index c2050d0..90ec3e8 100644 --- a/flake.nix +++ b/flake.nix @@ -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 = { diff --git a/scope.nix b/scope.nix new file mode 100644 index 0000000..f41fc24 --- /dev/null +++ b/scope.nix @@ -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"; }; +})