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

Package for nix #10

Open
IceDBorn opened this issue Sep 15, 2024 · 9 comments
Open

Package for nix #10

IceDBorn opened this issue Sep 15, 2024 · 9 comments

Comments

@IceDBorn
Copy link

No description provided.

@TheAlexDev23
Copy link
Owner

I've never used the nix package manager nor NixOS, so I've got 0 experience packaging for nix. If anyone does I'll be happy to accept any PRs but otherwise I don't think this will be a priority.

@mark-boute
Copy link

I'll give it a try, @TheAlexDev23 could you provide the Cargo.lock with releases?

TheAlexDev23 added a commit that referenced this issue Sep 21, 2024
@TheAlexDev23
Copy link
Owner

@mark-boute yeah sorry, I don't know why I had it excluded from vcs

@mark-boute
Copy link

Alright, I got stuck at setting up the systemctl service as it is not available. Leaving my attempt here for someone else to use:

{ lib,    
  libadwaita,
    # yad
  dbus,
  pkg-config,
  atk,
  xdotool,
  gtk3, 
  gtk4, 
  webkitgtk_4_1,
  fetchFromGitHub,
  rustPlatform,
  zsh
}:

rustPlatform.buildRustPackage rec {
  pname = "power-options-gtk";
  version = "591afd6f49ce79cfb5d2d2d1d43e10e64bf44a86";
  # use commit that added Cargo.lock instead of release

  src = fetchFromGitHub {
    owner = "TheAlexDev23";
    repo = "power-options";
    rev = version;
    hash = "sha256-gXSJej3Bl2ZnMl3vlSwaknR1yhlaEsRlGctR8abd+GY=";
  };

  cargoHash = "sha256-QCFtj+zcNJ5AvGq3tpi0BqUSjvDo8o/HA4Bs/3VrTZY=";

  buildInputs = [ 
    libadwaita
    # yad
    dbus
    xdotool
    atk 
    gtk3 
    gtk4 
    webkitgtk_4_1
  ];

  nativeBuildInputs = [ 
    zsh
    pkg-config
   ];

  cargoInstallHook = ''
    mkdir -p $out/bin
    cp target/release/power-daemon-mgr $out/bin/
    cp target/release/frontend-gtk $out/bin/power-options-gtk
    cp icon.png $out/share/icons/power-options.png
    cp install/power-options-gtk.desktop $out/share/applications/
  '';

  meta = {
    description = "A gtk frontend for Power Options, a blazingly fast power management solution.";
    homepage = "https://github.com/TheAlexDev23/power-options";
    license = lib.licenses.mit;
  };
}```

Only the `power-daemon-mgr` seems to be available in `/run/current-system/sw/bin/power-daemon-mgr`

@TheAlexDev23
Copy link
Owner

TheAlexDev23 commented Sep 21, 2024

@mark-boute The installation process requires the call to power-daemon-mgr generate-base-files to generate the files for systemd, acpi, dbus, etc. They are not available as files in the repo, mostly because they require some form of string interpolation to be properly generated.

Take a look at the AUR PKGBUILD, https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=power-options-daemon.

Tell me if this is not suitable for nix, and if I should think on alternative installation methods.

@mark-boute
Copy link

I figured and tried to run this imperatively. Where does it write to?
I think the main limiting factor is me not knowing how I turn this derivation into a systemd service.

@TheAlexDev23
Copy link
Owner

The generate-base-files command takes 2 parameters:

  • --program-path which indicates the final path where the power-daemon-mgr executable will be located
  • --path which will be treated as the root folder during installation.

It will generate the following files relative to --path

  • /usr/lib/udev/rules.d/85-power-daemon.rules
  • /etc/acpi/events/power-options
  • /usr/share/dbus-1/system.d/power-daemon.conf
  • /usr/lib/systemd/system/power-options.service

Is this what you were asking?

@mark-boute
Copy link

Right, thanks. I am currently looking into this again. giving one root for those files may not work in Nix, see: https://discourse.nixos.org/t/after-the-derivation-is-built-what-happens-to-files-in-out/24711
I am still pretty new to Nix so it's a learning experience for me too :)

@Arthur-Landel
Copy link

Arthur-Landel commented Nov 21, 2024

I managed to build it with the following (they need to be added with git, committing is not needed).
But I didn't find out, how to add the runtime dependencies.

About the systemd services, maybe this will help you:
https://search.nixos.org/options?channel=24.05&from=0&size=50&sort=relevance&type=packages&query=systemd.services

default.nix

{ pkgs ? import <nixpkgs> { } }:
let manifest = (pkgs.lib.importTOML ./crates/power-daemon/Cargo.toml).package;
in
pkgs.rustPlatform.buildRustPackage {
  pname = manifest.name;
  version = manifest.version;
  cargoLock.lockFile = ./Cargo.lock;
  src = pkgs.lib.cleanSource ./.;
  
  nativeBuildInputs = with pkgs; [
    pkg-config
  ];
  buildInputs = with pkgs; [
    libadwaita
    graphene
    glib
    gtk3
    gtk4
    webkitgtk_4_1
    xdotool
  ];
}

flake.nix

{
  description = "All-In-One blazingly fast Linux GUI Application for simple and advanced power
  management on any device";
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
  };
  outputs = { nixpkgs, ... }:
    let
      supportedSystems = [ "x86_64-linux" ];
      forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
      pkgsFor = nixpkgs.legacyPackages;
    in {
      packages = forAllSystems (system: {
        default = pkgsFor.${system}.callPackage ./. {};
      });
    };
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants