Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build!(nix): reuse NixOS package #24

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/nix-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
attribute:
- .#devShells.x86_64-linux.default
- .#packages.x86_64-linux.tuxedo-rs
- .#packages.x86_64-linux.tailor_gui
- .#packages.x86_64-linux.tailor-gui
- .#checks.x86_64-linux.formatting
steps:
- uses: actions/checkout@v3
Expand Down
32 changes: 8 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ Since I have limited access to hardware, please consider adding your device(s) t

## Installation

Currently, tuxedo-rs isn't available from package archives so you have to install it from source.
[![Packaging status](https://repology.org/badge/vertical-allrepos/tuxedo-rs.svg)](https://repology.org/project/tuxedo-rs/versions)

Currently, tuxedo-rs isn't available from other package archives so you have to install it from source.

### Tuxedo driver modules

Expand Down Expand Up @@ -136,33 +138,15 @@ cargo install --path tailor_cli
tailor --help
```

### On NixOS
### NixOS

To install tailor-rs on NixOS, with flakes enabled, add
the following to your flake.nix:
tuxedo-rs can be [enabled on NixOS with the following options](https://search.nixos.org/options?channel=unstable&from=0&size=50&sort=relevance&type=packages&query=tuxedo-rs):

```nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
tuxedo-rs.url = "github:AaronErhardt/tuxedo-rs";
}

outputs = {
nixpkgs,
tuxedo-rs,
...
} : {
nixosConfigurations.myConfiguration = nixpkgs.lib.nixosSystem {
modules = [
tuxedo-rs.nixosModules.default
];

services.tuxedo-rs = {
enable = true;
tailor_gui.enable = true;
};
};
hardware.tuxedo-rs = {
enable = true;
tailor-gui.enable = true;
};
}
```
Expand Down
50 changes: 34 additions & 16 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 4 additions & 9 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@
"x86_64-linux"
];

overlay = import ./nix/overlay.nix {
inherit
self
nixpkgs
;
};
overlay = import ./nix/overlay.nix {inherit self;};
in
flake-utils.lib.eachSystem supportedSystems (system: let
pkgs = import nixpkgs {
Expand All @@ -55,7 +50,7 @@
name = "tuxedo-rs-devShell";
buildInputs =
(with pkgs;
with pkgs.rustPlatform.rust; [
with pkgs.rustPlatform; [
cargo
rustc
meson
Expand Down Expand Up @@ -85,7 +80,7 @@
inherit
(pkgs)
tuxedo-rs
tailor_gui
tailor-gui
;
};

Expand All @@ -94,7 +89,7 @@
inherit
(pkgs)
tuxedo-rs
tailor_gui
tailor-gui
;
};
})
Expand Down
9 changes: 5 additions & 4 deletions nix/module.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# TODO: Remove this after NixOS 23.11 release
{
config,
lib,
Expand All @@ -8,12 +9,12 @@ with lib; let
cfg = config.services.tuxedo-rs;
in {
options = {
services.tuxedo-rs = {
hardware.tuxedo-rs = {
enable = mkEnableOption ''
Rust utilities for interacting with hardware from TUXEDO Computers.
'';

tailor_gui.enable = mkEnableOption ''
tailor-gui.enable = mkEnableOption ''
Alternative to Tuxedo Control Center, written in Rust.
'';
};
Expand Down Expand Up @@ -44,8 +45,8 @@ in {

environment.systemPackages = [pkgs.tuxedo-rs];
}
(mkIf cfg.tailor_gui.enable {
environment.systemPackages = [pkgs.tailor_gui];
(mkIf cfg.tailor-gui.enable {
environment.systemPackages = [pkgs.tailor-gui];
})
]);
}
89 changes: 15 additions & 74 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
@@ -1,84 +1,25 @@
{
self,
nixpkgs,
}: final: prev:
with final.pkgs.stdenv; let
# XXX: The nixos-22.11 rustPlatform is too old to build this.
#TODO: We should use final.pkgs.rustPlatform when NixOS 23.05 has been released.
pkgs = import nixpkgs {inherit (final.pkgs) system;};
rustPlatform = pkgs.rustPlatform;
{self}: final: prev: let
pkgs = prev;
lib = final.lib;

tuxedo-rs = with pkgs.lib; let
tuxedo-rs = pkgs.tuxedo-rs.overrideAttrs (oa: {
src = self;
in
rustPlatform.buildRustPackage {
pname = "tuxedo-rs";
inherit ((importTOML "${src}/tailord/Cargo.toml").package) version;

inherit src;

doCheck = false;

cargoLock = {
lockFile = self + "/Cargo.lock";
};

postInstall = ''
mkdir -p $out/share/dbus-1/system.d
cp ${self}/tailord/com.tux.Tailor.conf $out/share/dbus-1/system.d
'';

meta = with final.lib; {
description = "Daemon handling fan, keyboard and general HW support for Tuxedo laptops (part of tuxedo-rs)";
homepage = "https://github.com/AaronErhardt/tuxedo-rs";
license = licenses.gpl2Only;
};
};

tailor_gui = with pkgs.lib; let
src = builtins.path {
path = self + "/tailor_gui";
name = "tailor_gui";
version = ((lib.importTOML "${self}/tailord/Cargo.toml").package).version;
cargoDeps = pkgs.rustPlatform.importCargoLock {
lockFile = self + "/Cargo.lock";
};
in
mkDerivation {
name = "tailor_gui";
});

inherit ((importTOML (src + "/Cargo.toml")).package) version;

inherit src;

cargoDeps = rustPlatform.importCargoLock {
lockFile = self + "/tailor_gui/Cargo.lock";
};

nativeBuildInputs = with rustPlatform;
[
rust.cargo
rust.rustc
cargoSetupHook
]
++ (with pkgs; [
pkg-config
desktop-file-utils
appstream-glib
makeWrapper
]);

buildInputs = with pkgs; [
meson
ninja
libadwaita
gtk4
];

postFixup = ''
wrapProgram $out/bin/tailor_gui --set XDG_DATA_DIRS "$out/share/gsettings-schemas/tailor_gui"
'';
tailor-gui = pkgs.tailor-gui.overrideAttrs (oa: {
src = self;
version = ((lib.importTOML "${self}/tailor_gui/Cargo.toml").package).version;
cargoDeps = pkgs.rustPlatform.importCargoLock {
lockFile = self + "/tailor_gui/Cargo.lock";
};
});
in {
inherit
tuxedo-rs
tailor_gui
tailor-gui
;
}
12 changes: 3 additions & 9 deletions tailor_cli/src/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ pub(crate) async fn handle(cmd: ProfileCommand) -> Result<()> {
println!("{}\n{}", active_profile_str, inactive_profiles.join("\n"));
}
ProfileCommand::Set { name } => {
connection
.set_active_global_profile_name(&name)
.await?;
connection
.reload()
.await?;
connection.set_active_global_profile_name(&name).await?;
connection.reload().await?;
}
ProfileCommand::Cycle { verbose, notify } => {
let active_profile = connection.get_active_global_profile_name().await?;
Expand All @@ -43,9 +39,7 @@ pub(crate) async fn handle(cmd: ProfileCommand) -> Result<()> {
connection
.set_active_global_profile_name(next_profile_name)
.await?;
connection
.reload()
.await?;
connection.reload().await?;
if verbose {
println!("{}", profile_updated_msg)
}
Expand Down
2 changes: 1 addition & 1 deletion tailor_gui/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.