Skip to content

Commit 4a55174

Browse files
authored
Update nix files (#1319)
* Format with `alejandra` and add it to all devShells * Use `lib.fileset` to get only the needed files for the build * Fix build inputs for Darwin * Make `wayland` and `x11` optional using the package args `with*` * Create a separate `terminfo` output[^1] * Fix nix file indentation to 2 instead of 4 * Remove `app`, `package` already has a `meta.mainProgram` attribute * Add an overlay that can be used to override the `rio` package using flake-part's easyOverlay module[^2] * Create separate package for `msrv`, `stable` and `nightly`, matching the different `devShells` available * Removed the `flake = false` attribute for `inputs.systems` * Create `legacyPackages.rio` containing four sub packages using different versions of the rust-toolchain: * `rio.msrv` - uses `./rust-toolchain.toml` * `rio.stable` - uses `rust-bin.stable` * `rio.nightly` - uses the latest nightly rust * `rio.default` - Same as `rio.msrv` * Added `/result` to get rid of the `nix build` output file[^3] [^1]: https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/by-name/ri/rio/package.nix [^2]: https://flake.parts/options/flake-parts-easyoverlay [^3]: A simpler version of #1233, that _just_ adds this one line
1 parent 8e6cfaa commit 4a55174

File tree

7 files changed

+126
-121
lines changed

7 files changed

+126
-121
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ insert_final_newline = true
1212
indent_style = space
1313
indent_size = 4
1414

15+
[*.nix]
16+
indent_size = 2
17+
1518
[*.scd]
1619
indent_style = tab
1720
indent_size = 4

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# required by nix
55
.direnv/
66
result/
7+
/result
78

89
target/
910
.DS_Store

.helix/languages.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[[language]]
2+
name = "nix"
3+
formatter = { command = "alejandra" }

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ keywords = ["graphics", "terminal", "application"]
2020
# Minimal stable rust version (MSRV)
2121
rust-version = "1.90.0"
2222
repository = "https://github.com/raphamorim/rio"
23-
homepage = "https://raphamorim.io/rio"
23+
homepage = "https://rioterm.com"
2424
documentation = "https://github.com/raphamorim/rio#readme"
2525
readme = "README.md"
2626

flake.lock

Lines changed: 12 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,68 +5,64 @@
55
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
66
flake-parts.url = "github:hercules-ci/flake-parts";
77
rust-overlay.url = "github:oxalica/rust-overlay";
8-
systems = {
9-
url = "github:nix-systems/default";
10-
flake = false;
11-
};
8+
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
9+
systems.url = "github:nix-systems/default";
1210
};
1311

1412
outputs = inputs @ {flake-parts, ...}:
1513
flake-parts.lib.mkFlake {inherit inputs;} {
16-
imports = [];
14+
imports = [flake-parts.flakeModules.easyOverlay];
1715

1816
systems = import inputs.systems;
1917

2018
perSystem = {
21-
config,
2219
self',
2320
inputs',
2421
pkgs,
2522
system,
2623
lib,
2724
...
2825
}: let
29-
mkRio = import ./pkgRio.nix;
30-
26+
# Defines a devshell using the `rust-toolchain`, allowing for
27+
# different versions of rust to be used.
3128
mkDevShell = rust-toolchain: let
3229
runtimeDeps = self'.packages.rio.runtimeDependencies;
33-
tools = self'.packages.rio.nativeBuildInputs ++ self'.packages.rio.buildInputs ++ [rust-toolchain];
30+
tools =
31+
self'.packages.rio.nativeBuildInputs ++ self'.packages.rio.buildInputs ++ [rust-toolchain];
3432
in
3533
pkgs.mkShell {
36-
packages =
37-
[
38-
# Derivations in `rust-toolchain` provide the toolchain,
39-
# which must be listed first to take precedence over nightly.
40-
rust-toolchain
41-
42-
# Use rustfmt, and other tools that require nightly features.
43-
(pkgs.rust-bin.selectLatestNightlyWith (toolchain:
44-
toolchain.minimal.override {
45-
extensions = ["rustfmt" "rust-analyzer"];
46-
}))
47-
]
48-
++ tools;
49-
LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath runtimeDeps}";
34+
packages = [self'.formatter] ++ tools;
35+
LD_LIBRARY_PATH = "${lib.makeLibraryPath runtimeDeps}";
5036
};
37+
toolchains = rec {
38+
msrv = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
39+
stable = pkgs.rust-bin.stable.latest.minimal;
40+
nightly = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.minimal);
41+
rio = msrv;
42+
default = rio;
43+
};
5144
in {
45+
formatter = pkgs.alejandra;
5246
_module.args.pkgs = import inputs.nixpkgs {
5347
inherit system;
5448
overlays = [(import inputs.rust-overlay)];
5549
};
5650

57-
formatter = pkgs.alejandra;
58-
packages.default = self'.packages.rio;
59-
devShells.default = self'.devShells.msrv;
60-
61-
apps.default = {
62-
type = "app";
63-
program = self'.packages.default;
64-
};
65-
packages.rio = pkgs.callPackage mkRio {rust-toolchain = pkgs.rust-bin.stable.latest.minimal;};
66-
67-
devShells.msrv = mkDevShell (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml);
68-
devShells.stable = mkDevShell pkgs.rust-bin.stable.latest.minimal;
69-
devShells.nightly = mkDevShell (pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.minimal));
51+
# Create overlay to override `rio` with this flake's default
52+
overlayAttrs = {inherit (self'.packages) rio;};
53+
packages =
54+
lib.mapAttrs' (
55+
k: v: {
56+
name =
57+
if builtins.elem k ["rio" "default"]
58+
then k
59+
else "rio-${k}";
60+
value = pkgs.callPackage ./pkgRio.nix {rust-toolchain = v;};
61+
}
62+
)
63+
toolchains;
64+
# Different devshells for different rust versions
65+
devShells = lib.mapAttrs (_: v: mkDevShell v) toolchains;
7066
};
7167
};
7268
}

pkgRio.nix

Lines changed: 74 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,120 @@
11
{
2+
# rust-overlay deps
23
rust-toolchain,
34
makeRustPlatform,
4-
stdenv,
5+
# Normal deps
56
lib,
6-
fontconfig,
7+
stdenv,
78
darwin,
9+
autoPatchelfHook,
10+
cmake,
11+
ncurses,
12+
pkg-config,
813
gcc-unwrapped,
14+
fontconfig,
915
libGL,
10-
libxkbcommon,
1116
vulkan-loader,
17+
libxkbcommon,
18+
withX11 ? !stdenv.isDarwin,
1219
libX11,
1320
libXcursor,
1421
libXi,
1522
libXrandr,
1623
libxcb,
17-
wayland,
18-
ncurses,
19-
pkg-config,
20-
cmake,
21-
autoPatchelfHook,
22-
withX11 ? !stdenv.isDarwin,
2324
withWayland ? !stdenv.isDarwin,
25+
wayland,
2426
...
2527
}: let
26-
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
28+
readTOML = f: builtins.fromTOML (builtins.readFile f);
29+
cargoToml = readTOML ./Cargo.toml;
30+
rioToml = readTOML ./frontends/rioterm/Cargo.toml;
2731
rustPlatform = makeRustPlatform {
2832
cargo = rust-toolchain;
2933
rustc = rust-toolchain;
3034
};
3135
rlinkLibs =
32-
if stdenv.isDarwin
33-
then [
34-
darwin.libobjc
35-
darwin.apple_sdk_11_0.frameworks.AppKit
36-
darwin.apple_sdk_11_0.frameworks.AVFoundation
37-
darwin.apple_sdk_11_0.frameworks.MetalKit
38-
darwin.apple_sdk_11_0.frameworks.Vision
36+
lib.optionals stdenv.isLinux [
37+
(lib.getLib gcc-unwrapped)
38+
fontconfig
39+
libGL
40+
libxkbcommon
41+
vulkan-loader
3942
]
40-
else
41-
[
42-
(lib.getLib gcc-unwrapped)
43-
fontconfig
44-
libGL
45-
libxkbcommon
46-
vulkan-loader
47-
]
48-
++ lib.optionals withX11 [
49-
libX11
50-
libXcursor
51-
libXi
52-
libXrandr
53-
libxcb
54-
]
55-
++ lib.optionals withWayland [
56-
wayland
57-
];
43+
++ lib.optionals withX11 [
44+
libX11
45+
libXcursor
46+
libXi
47+
libXrandr
48+
libxcb
49+
]
50+
++ lib.optionals withWayland [
51+
wayland
52+
];
53+
54+
inherit (lib.fileset) unions toSource;
5855
in
5956
rustPlatform.buildRustPackage {
6057
inherit (cargoToml.workspace.package) version;
6158
name = "rio";
62-
src = ./.;
59+
src = toSource {
60+
root = ./.;
61+
fileset = unions ([
62+
./Cargo.lock
63+
./Cargo.toml
64+
./misc # Extra desktop/terminfo files
65+
]
66+
++ (map (x: ./. + "/${x}") cargoToml.workspace.members));
67+
};
6368
cargoLock.lockFile = ./Cargo.lock;
6469

6570
cargoBuildFlags = "-p rioterm";
6671

67-
buildInputs = rlinkLibs;
72+
buildInputs = rlinkLibs ++ (lib.optionals stdenv.isDarwin [darwin.libutil]);
6873
runtimeDependencies = rlinkLibs;
6974

7075
nativeBuildInputs =
7176
[
77+
rustPlatform.bindgenHook
7278
ncurses
7379
]
7480
++ lib.optionals stdenv.isLinux [
75-
pkg-config
7681
cmake
82+
pkg-config
7783
autoPatchelfHook
7884
];
79-
80-
postInstall = ''
81-
install -D -m 644 misc/rio.desktop -t $out/share/applications
82-
install -D -m 644 misc/logo.svg \
83-
$out/share/icons/hicolor/scalable/apps/rio.svg
84-
85-
# Install terminfo files
86-
install -dm 755 "$out/share/terminfo/r/"
87-
tic -xe xterm-rio,rio,rio-direct -o "$out/share/terminfo" misc/rio.terminfo
88-
'' + lib.optionalString stdenv.hostPlatform.isDarwin ''
89-
mkdir $out/Applications/
90-
mv misc/osx/Rio.app/ $out/Applications/
91-
mkdir $out/Applications/Rio.app/Contents/MacOS/
92-
ln -s $out/bin/rio $out/Applications/Rio.app/Contents/MacOS/
93-
'';
9485

95-
86+
outputs = [
87+
"out"
88+
"terminfo"
89+
];
90+
91+
postInstall =
92+
''
93+
install -D -m 644 misc/rio.desktop -t \
94+
$out/share/applications
95+
install -D -m 644 misc/logo.svg \
96+
$out/share/icons/hicolor/scalable/apps/rio.svg
97+
98+
# Install terminfo files
99+
install -dm 755 "$terminfo/share/terminfo/r/"
100+
tic -xe xterm-rio,rio,rio-direct -o "$terminfo/share/terminfo" misc/rio.terminfo
101+
mkdir -p $out/nix-support
102+
echo "$terminfo" >> $out/nix-support/propagated-user-env-packages
103+
''
104+
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
105+
mkdir $out/Applications/
106+
mv misc/osx/Rio.app/ $out/Applications/
107+
mkdir $out/Applications/Rio.app/Contents/MacOS/
108+
ln -s $out/bin/rio $out/Applications/Rio.app/Contents/MacOS/
109+
'';
110+
96111
buildNoDefaultFeatures = true;
97-
buildFeatures = ["x11" "wayland"];
112+
buildFeatures = (lib.optionals withX11 ["x11"]) ++ (lib.optionals withWayland ["wayland"]);
113+
checkType = "debug";
98114
meta = {
99-
description = "A hardware-accelerated GPU terminal emulator focusing to run in desktops and browsers";
100-
homepage = "https://rioterm.com";
115+
description = rioToml.package.description;
116+
longDescription = rioToml.package.extended-description;
117+
homepage = cargoToml.workspace.package.homepage;
101118
license = lib.licenses.mit;
102119
platforms = lib.platforms.unix;
103120
changelog = "https://github.com/raphamorim/rio/blob/master/CHANGELOG.md";

0 commit comments

Comments
 (0)