Skip to content

Commit 702fbc7

Browse files
committed
flake.nix: refactor, greatly improve
1 parent da2d87b commit 702fbc7

File tree

1 file changed

+54
-45
lines changed

1 file changed

+54
-45
lines changed

flake.nix

Lines changed: 54 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,42 @@
22
description = "Compositor for the COSMIC desktop environment";
33

44
inputs = {
5-
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
5+
# <https://github.com/nix-systems/default-linux>
6+
systems.url = "github:nix-systems/default-linux";
67

7-
parts.url = "github:hercules-ci/flake-parts";
8-
parts.inputs.nixpkgs-lib.follows = "nixpkgs";
8+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
99

1010
crane.url = "github:ipetkov/crane";
1111

12-
rust.url = "github:oxalica/rust-overlay";
13-
rust.inputs.nixpkgs.follows = "nixpkgs";
14-
15-
nix-filter.url = "github:numtide/nix-filter";
12+
rust-overlay.url = "github:oxalica/rust-overlay";
13+
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
1614
};
1715

1816
outputs = inputs @ {
1917
self,
20-
nixpkgs,
21-
parts,
2218
crane,
23-
rust,
24-
nix-filter,
2519
...
26-
}:
27-
parts.lib.mkFlake {inherit inputs;} {
28-
systems = [
29-
"aarch64-linux"
30-
"x86_64-linux"
31-
];
32-
33-
perSystem = {
34-
self',
35-
lib,
36-
system,
37-
...
38-
}: let
39-
pkgs = nixpkgs.legacyPackages.${system}.extend rust.overlays.default;
40-
rust-toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
41-
craneLib = (crane.mkLib pkgs).overrideToolchain rust-toolchain;
20+
}: let
21+
inherit (inputs.nixpkgs) lib;
22+
23+
fs = lib.fileset;
24+
eachSystem = lib.genAttrs (import inputs.systems);
25+
pkgsFor = eachSystem (system:
26+
import inputs.nixpkgs {
27+
localSystem.system = system;
28+
overlays = [(import inputs.rust-overlay)];
29+
});
30+
in {
31+
packages =
32+
lib.mapAttrs (system: pkgs: let
33+
craneLib = crane.mkLib pkgs;
4234
craneArgs = {
4335
pname = "cosmic-comp";
4436
version = self.rev or "dirty";
4537

46-
src = nix-filter.lib.filter {
38+
src = fs.toSource {
4739
root = ./.;
48-
include = [
40+
fileset = fs.unions [
4941
./src
5042
./i18n.toml
5143
./Cargo.toml
@@ -89,24 +81,41 @@
8981
};
9082

9183
cargoArtifacts = craneLib.buildDepsOnly craneArgs;
92-
cosmic-comp = craneLib.buildPackage (craneArgs // {inherit cargoArtifacts;});
9384
in {
94-
apps.cosmic-comp = {
95-
type = "app";
96-
program = lib.getExe self'.packages.default;
97-
};
98-
99-
checks.cosmic-comp = cosmic-comp;
100-
packages.default = cosmic-comp;
85+
cosmic-comp = craneLib.buildPackage (craneArgs // {inherit cargoArtifacts;});
10186

102-
devShells.default = craneLib.devShell {
103-
LD_LIBRARY_PATH = lib.makeLibraryPath (
104-
__concatMap (d: d.runtimeDependencies) (__attrValues self'.checks)
105-
);
87+
default = self.packages.${system}.cosmic-comp;
88+
})
89+
pkgsFor;
10690

107-
# include build inputs
108-
inputsFrom = [cosmic-comp];
109-
};
91+
apps = eachSystem (system: {
92+
cosmic-comp = {
93+
type = "app";
94+
program = lib.getExe self.packages.${system}.default;
11095
};
111-
};
96+
97+
default = self.apps.${system}.cosmic-comp;
98+
});
99+
100+
checks = eachSystem (system: {
101+
inherit (self.packages.${system}) cosmic-comp;
102+
});
103+
104+
devShells =
105+
lib.mapAttrs (
106+
system: pkgs: let
107+
craneLib = crane.mkLib pkgs;
108+
in {
109+
default = craneLib.devShell {
110+
LD_LIBRARY_PATH = lib.makeLibraryPath (
111+
builtins.concatMap (d: d.runtimeDependencies) (builtins.attrValues self.checks.${system})
112+
);
113+
114+
# include build inputs
115+
inputsFrom = [self.packages.${system}.cosmic-comp];
116+
};
117+
}
118+
)
119+
pkgsFor;
120+
};
112121
}

0 commit comments

Comments
 (0)