Skip to content

Commit

Permalink
build(nix): reuse NixOS package
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Sep 29, 2023
1 parent a77a9f6 commit b5781fa
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 128 deletions.
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
;
}
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.

0 comments on commit b5781fa

Please sign in to comment.