-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
tiltfive: init at 1.3.2 #236695
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
base: master
Are you sure you want to change the base?
tiltfive: init at 1.3.2 #236695
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| { pkgs, lib, config, ... }: | ||
|
|
||
| with lib; | ||
| let | ||
| cfg = config.hardware.tiltfive; | ||
| in | ||
| { | ||
| options.hardware.tiltfive = { | ||
| enable = mkEnableOption (lib.mdDoc "tiltfive driver and service"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tilt Five |
||
|
|
||
| user = mkOption { | ||
| type = types.str; | ||
| default = "tiltfive"; | ||
| description = lib.mdDoc "User account under which the Tilt Five driver service will run."; | ||
| }; | ||
|
|
||
| group = mkOption { | ||
| type = types.str; | ||
| default = "tiltfive"; | ||
| description = lib.mdDoc "Group under which the Tilt Five driver service will run."; | ||
| }; | ||
|
|
||
| dataDirectory = mkOption { | ||
| type = types.path; | ||
| default = "/var/lib/tiltfive"; | ||
| description = lib.mdDoc '' | ||
| Directory where the Tilt Five service will store persistent data, eg. | ||
| settings. Make sure it is writable. | ||
| ''; | ||
| }; | ||
| }; | ||
|
|
||
| config = mkIf cfg.enable { | ||
| systemd.services.tiltfive = { | ||
| description = "Tilt Five Service"; | ||
| serviceConfig = { | ||
| Type = "simple"; | ||
| ExecStart = "${pkgs.tiltfive-driver}/bin/tiltfive-service"; | ||
| Restart = "always"; | ||
| RestartSec = 5; | ||
|
|
||
| User = cfg.user; | ||
| Group = cfg.group; | ||
|
|
||
| Environment = [ | ||
| # The service does not run with telemetry enabled by default, but it | ||
| # always attempts to create a telemetry database anyway. | ||
| # | ||
| # When not specified, the telemetry database defaults to being | ||
| # installation-relative, so in our case it attempts to create the | ||
| # telemetry database in the nix store. This will naturally fail. | ||
| # Setting this environment variable makes it use a different location | ||
| # for the database, leading to ugly startup errors. | ||
| "TILTFIVE_TELEMDB=${cfg.dataDirectory}/telemdb" | ||
|
|
||
| # Same deal for logs. | ||
| "TILTFIVE_LOG=${cfg.dataDirectory}/log" | ||
| ]; | ||
| }; | ||
| wantedBy = [ "multi-user.target" ]; | ||
| }; | ||
|
|
||
| # We don't use udev rules from the driver package as we want to be able to | ||
| # customize the group which has access to the tiltfive devices (ie. the | ||
| # group under which the driver service runs). | ||
| services.udev.extraRules = '' | ||
| # Tilt Five glasses | ||
| SUBSYSTEMS=="usb", ATTRS{idVendor}=="32f8", ATTRS{idProduct}=="9200", GROUP="${cfg.group}" | ||
|
|
||
| # Tilt Five glasses (wrong speed) | ||
| SUBSYSTEMS=="usb", ATTRS{idVendor}=="32f8", ATTRS{idProduct}=="2510", GROUP="${cfg.group}" | ||
|
|
||
| # Tilt Five glasses bootloader | ||
| SUBSYSTEMS=="usb", ATTRS{idVendor}=="32f8", ATTRS{idProduct}=="424c", GROUP="${cfg.group}" | ||
| ''; | ||
|
|
||
| users.users = mkIf (cfg.user == "tiltfive") { | ||
| tiltfive = { | ||
| group = cfg.group; | ||
| home = cfg.dataDirectory; | ||
| createHome = true; | ||
| isSystemUser = true; | ||
| }; | ||
| }; | ||
|
|
||
| users.groups = mkIf (cfg.user == "tiltfive") { | ||
| tiltfive = {}; | ||
| }; | ||
|
|
||
| environment.systemPackages = [ | ||
| pkgs.tiltfive-control-panel | ||
AndersonTorres marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ]; | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import ./make-test-python.nix ({ pkgs, lib, ... }: { | ||
| name = "tiltfive"; | ||
| meta.maintainers = with lib.maintainers; [ q3k ]; | ||
|
|
||
| nodes.machine = { nodes, ... }: | ||
| let user = nodes.machine.users.users.alice; | ||
| in { | ||
| imports = [ ./common/user-account.nix ./common/x11.nix ]; | ||
|
|
||
| hardware.tiltfive.enable = true; | ||
| nixpkgs.config.allowUnfree = true; | ||
|
|
||
| test-support.displayManager.auto.user = user.name; | ||
| environment.systemPackages = [ pkgs.xdotool ]; | ||
| }; | ||
|
|
||
| enableOCR = true; | ||
|
|
||
| testScript = { nodes, ... }: | ||
| let user = nodes.machine.users.users.alice; | ||
| in '' | ||
| machine.wait_for_x() | ||
| machine.wait_for_file("${user.home}/.Xauthority") | ||
| machine.succeed("xauth merge ${user.home}/.Xauthority") | ||
|
|
||
| # Start the control panel without the service running and expect error | ||
| # message. This ensures that this test exercises connectivity between the | ||
| # service and the control panel. | ||
| machine.execute("systemctl stop tiltfive") | ||
|
|
||
| machine.execute("su - alice -c tiltfive-control-panel >&2 &") | ||
| machine.wait_for_text("Service disconnected") | ||
| machine.screenshot("controlpanel1") | ||
|
|
||
| # Now start the service and expect the wizard to start up. | ||
| machine.execute("systemctl start tiltfive") | ||
| machine.wait_for_text("Gameboard not set") | ||
| machine.screenshot("controlpanel2") | ||
|
|
||
| # This is is the best we can do without emulating Tilt Five glasses :). | ||
| ''; | ||
| }) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,67 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| { stdenv | ||||||||||||||||||||||||||||||||||||||||||||||
| , lib | ||||||||||||||||||||||||||||||||||||||||||||||
| , autoPatchelfHook | ||||||||||||||||||||||||||||||||||||||||||||||
| , fetchurl | ||||||||||||||||||||||||||||||||||||||||||||||
| , nixosTests | ||||||||||||||||||||||||||||||||||||||||||||||
| , gtk3 | ||||||||||||||||||||||||||||||||||||||||||||||
| , glfw | ||||||||||||||||||||||||||||||||||||||||||||||
| }: | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| let srcs = import ./srcs.nix { inherit fetchurl; }; in | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
| stdenv.mkDerivation rec { | ||||||||||||||||||||||||||||||||||||||||||||||
| pname = "tiltfive-control-panel"; | ||||||||||||||||||||||||||||||||||||||||||||||
| version = srcs.version; | ||||||||||||||||||||||||||||||||||||||||||||||
| src = srcs.driver; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| buildInputs = [ | ||||||||||||||||||||||||||||||||||||||||||||||
| gtk3 glfw | ||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| nativeBuildInputs = [ | ||||||||||||||||||||||||||||||||||||||||||||||
| autoPatchelfHook | ||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| installPhase = '' | ||||||||||||||||||||||||||||||||||||||||||||||
q3k marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||
| runHook preInstall | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| cd tiltfive-control-panel_${version}_amd64/files/ | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| dest=$out/opt/tiltfive/control-panel | ||||||||||||||||||||||||||||||||||||||||||||||
| pushd opt/tiltfive/control-panel | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| mkdir -p $dest/data | ||||||||||||||||||||||||||||||||||||||||||||||
| cp -r data/* $dest/data/ | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| mkdir -p $dest/lib | ||||||||||||||||||||||||||||||||||||||||||||||
| install -Dm755 lib/* $dest/lib/ | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| install -Dm755 control_panel $dest/ | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| popd | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
| dest=$out/opt/tiltfive/control-panel | |
| pushd opt/tiltfive/control-panel | |
| mkdir -p $dest/data | |
| cp -r data/* $dest/data/ | |
| mkdir -p $dest/lib | |
| install -Dm755 lib/* $dest/lib/ | |
| install -Dm755 control_panel $dest/ | |
| popd | |
| dest=$out/opt/tiltfive/control-panel | |
| pushd opt/tiltfive/control-panel | |
| mkdir -p $dest/data $dest/lib | |
| cp -r data/* $dest/data/ | |
| install -Dm755 lib/* $dest/lib/ | |
| install -Dm755 control_panel $dest/ | |
| popd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I spersonally find the version with whitespace more readable. Is there a concrete style recommendation to avoid newlines in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope.
but using two white lines makes no sense
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not parameterize pname
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nixpkgs $ grep -r '{pname}.desktop' | wc -l
90
This seems to be a fairly common pattern in nixpkgs. Is there a concrete style recommendation against this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a fairly common pattern in nixpkgs.
That doesn't mean anything since there is lots of code which wasn't touched in a good amount of time and should be updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but what is the reason to not do this? I'll gladly change things around, but I'd prefer to know what is the reasoning behind this so that I can then explain the same thing to others :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pname could be changed with a prefix which does not break with rec but with finalAttrs. Also it increases code complexity and pname does not change often.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a fairly common pattern in nixpkgs. Is there a concrete style recommendation against this?
90 occurrences in a codebase of 80k+ packages? This is not "fairly common".
Right, but what is the reason to not do this?
- it creates a useless dependency link, making static debugging a little more difficult.
- sometimes
pnameis not perfectly parameterizable. E.g. the GitHub repository ofopenmsxisopenMSX/openMSX. What we should do? Pass it under a obfuscated combination of string splitting? - being effectively a constant, using
pnamemakes no real difference to understand the code. It is just harder to read and conveys nothing useful.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| { stdenv | ||
| , lib | ||
| , autoPatchelfHook | ||
| , fetchurl | ||
| , nixosTests | ||
|
|
||
| , glfw | ||
| , udev | ||
| }: | ||
|
|
||
| let srcs = import ./srcs.nix { inherit fetchurl; }; in | ||
| stdenv.mkDerivation { | ||
| pname = "tiltfive-driver"; | ||
| version = srcs.version; | ||
|
|
||
| srcs = srcs.driver; | ||
|
|
||
| buildInputs = [ | ||
| glfw | ||
| ]; | ||
|
|
||
| nativeBuildInputs = [ | ||
| autoPatchelfHook | ||
| ]; | ||
|
|
||
| runtimeDependencies = [ | ||
| udev | ||
| ]; | ||
|
|
||
| installPhase = '' | ||
| runHook preInstall | ||
|
|
||
| cd tiltfive-service_${srcs.version}_amd64/files/ | ||
|
|
||
| mkdir -p $out/bin | ||
| install -Dm755 opt/tiltfive/bin/* -t $out/bin/ | ||
|
|
||
| mkdir -p $out/var/opt/tiltfive/firmware/ | ||
| install -Dm644 var/opt/tiltfive/firmware/* -t $out/var/opt/tiltfive/firmware/ | ||
|
|
||
| cp opt/tiltfive/LICENSE* $out/ | ||
|
|
||
| runHook postInstall | ||
| ''; | ||
|
|
||
| passthru.tests.tiltfive = nixosTests.tiltfive; | ||
|
|
||
| meta = with lib; { | ||
| description = "Tilt Five™ Glasses driver / userspace service"; | ||
| homepage = "https://docs.tiltfive.com/index.html"; | ||
| # Non-redistributable. See: LICENSE.service.txt, 2.1.2. | ||
| license = with licenses; unfree; | ||
| sourceProvenance = with sourceTypes; [ binaryNativeCode ]; | ||
| maintainers = with maintainers; [ q3k ]; | ||
| platforms = [ "x86_64-linux" ]; | ||
| }; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,45 @@ | ||||||
| { stdenv | ||||||
| , lib | ||||||
| , autoPatchelfHook | ||||||
| , fetchurl | ||||||
| , glfw | ||||||
| }: | ||||||
|
|
||||||
| let srcs = import ./srcs.nix { inherit fetchurl; }; in | ||||||
| stdenv.mkDerivation { | ||||||
| pname = "tiltfive-sdk"; | ||||||
| version = srcs.version; | ||||||
|
|
||||||
| srcs = srcs.sdk; | ||||||
|
|
||||||
| buildInputs = [ | ||||||
| glfw | ||||||
| ]; | ||||||
|
|
||||||
| nativeBuildInputs = [ | ||||||
| autoPatchelfHook | ||||||
| ]; | ||||||
|
|
||||||
| installPhase = '' | ||||||
| runHook preInstall | ||||||
|
|
||||||
| mkdir -p $out | ||||||
|
|
||||||
| cp -rv * $out/ | ||||||
|
|
||||||
| chmod 755 $out/Native/lib/linux/x86_64/libTiltFiveNative.so | ||||||
| chmod 755 $out/Utils/Linux/gameboard_transform | ||||||
|
|
||||||
| runHook postInstall | ||||||
| ''; | ||||||
|
|
||||||
| meta = with lib; { | ||||||
| description = "Tilt Five™ Glasses SDK"; | ||||||
| homepage = "https://docs.tiltfive.com/index.html"; | ||||||
| # Non-redistributable. See: license_sdk_en.txt, 2.1.2. | ||||||
q3k marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| license = with licenses; unfree; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| sourceProvenance = with sourceTypes; [ binaryNativeCode ]; | ||||||
| maintainers = with maintainers; [ q3k ]; | ||||||
| platforms = [ "x86_64-linux" ]; | ||||||
| }; | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { fetchurl }: | ||
| rec { | ||
| version = "1.3.2"; | ||
|
|
||
| driver = fetchurl { | ||
| url = "https://files.tiltfive.com/tiltfive_driver_${version}_amd64.unpacked_debs.tar.xz"; | ||
| sha256 = "sha256-MWxKqFEM6Q3gf8ik6OZk2aSFe6piTGljPOLpstJh0vA="; | ||
| }; | ||
|
|
||
| sdk = fetchurl { | ||
| url = "https://files.tiltfive.com/tiltfive_sdk_${version}.tar.xz"; | ||
| sha256 = "sha256-LC3DxOOHulgYO266LdHfAS6kiOzcnG7fEON4SJkMQlU="; | ||
| }; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a bunch of
mkXXXcalls in there. Why is thiswith lib;a problem? Should it be nested somewhere deeper? Should I uselib.mkXXXexplicitly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
withis an anti-pattern too ingrained in old code. Indeed I am cleaning up this mess, and it is hard as hell.withworks in a similar manner of#include <>from C language, bringing to the scope of your code a whole bunch of things you are not using. This is not so harmful in Nix because it uses lazy evaluation, however it can be a pain for static analysis, and can be worse if you accidentally invokes a functionality from it.withworks in unexpected ways when used more than once.Yes.
Another less verbose alternative is to substitute from
with lib;toinherit (lib) mkXXX mkXXY mkXXZ . . .;(Usually @SuperSandro2000 prefers the explicit
lib.usage, but I have no strong opinions between the options above.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where you need to maintain a list of used functions which is also not that great.