flake reorg

This commit is contained in:
Robin Appelman 2024-09-29 14:27:05 +02:00
commit a9356910c9
9 changed files with 174 additions and 294 deletions

View file

@ -1,63 +1,28 @@
name: "Build" on: [push, pull_request]
on:
pull_request: name: CI
push:
jobs: jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v26
- uses: icewind1991/attic-action@v1
with:
name: ci
instance: https://cache.icewind.me
authToken: '${{ secrets.ATTIC_TOKEN }}'
- run: nix build .#check
clippy:
runs-on: ubuntu-latest
needs: check
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v26
- uses: icewind1991/attic-action@v1
with:
name: ci
instance: https://cache.icewind.me
authToken: '${{ secrets.ATTIC_TOKEN }}'
- run: nix build .#clippy
msrv:
runs-on: ubuntu-latest
needs: check
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v26
- uses: icewind1991/attic-action@v1
with:
name: ci
instance: https://cache.icewind.me
authToken: '${{ secrets.ATTIC_TOKEN }}'
- run: nix build .#msrv
matrix: matrix:
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }} check-matrix: ${{ steps.set-matrix.outputs.check-matrix }}
cross-matrix: ${{ steps.set-matrix.outputs.cross-matrix }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: cachix/install-nix-action@v26 - uses: cachix/install-nix-action@v27
- id: set-matrix - id: set-matrix
run: echo "matrix={\"target\":$(nix eval --json ".#targets.x86_64-linux")}" | tee $GITHUB_OUTPUT run: |
echo "check-matrix={\"check\":$(nix eval --json '.#checks.x86_64-linux' --apply 'builtins.attrNames')}" | tee -a $GITHUB_OUTPUT
echo "cross-matrix={\"include\":$(nix eval --json '.#lib.crossMatrix')}" | tee -a $GITHUB_OUTPUT
build: checks:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [check, matrix] needs: [matrix]
strategy: strategy:
fail-fast: false fail-fast: false
matrix: ${{fromJson(needs.matrix.outputs.matrix)}} matrix: ${{fromJson(needs.matrix.outputs.check-matrix)}}
name: ${{ matrix.check }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: cachix/install-nix-action@v26 - uses: cachix/install-nix-action@v26
@ -65,9 +30,25 @@ jobs:
with: with:
name: ci name: ci
instance: https://cache.icewind.me instance: https://cache.icewind.me
authToken: '${{ secrets.ATTIC_TOKEN }}' authToken: "${{ secrets.ATTIC_TOKEN }}"
- run: nix build .#checks.x86_64-linux.${{ matrix.check }}
build:
runs-on: ubuntu-latest
needs: [matrix, checks]
strategy:
fail-fast: false
matrix: ${{fromJson(needs.matrix.outputs.cross-matrix)}}
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v27
- uses: icewind1991/attic-action@v1
with:
name: ci
instance: https://cache.icewind.me
authToken: "${{ secrets.ATTIC_TOKEN }}"
- run: nix build .#${{ matrix.target }} - run: nix build .#${{ matrix.target }}
- uses: actions/upload-artifact@v4 - uses: actions/upload-artifact@v4
with: with:
name: palantir-${{ matrix.target }} name: palantir-${{ matrix.target }}
path: result/bin/* path: result/bin/palantir${{ matrix.binary-suffix }}

View file

@ -4,36 +4,40 @@ on:
release: release:
types: [created] types: [created]
permissions:
contents: write
jobs: jobs:
matrix: matrix:
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }} cross-matrix: ${{ steps.set-matrix.outputs.cross-matrix }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: cachix/install-nix-action@v26 - uses: cachix/install-nix-action@v27
- id: set-matrix - id: set-matrix
run: echo "matrix=$(nix eval --json ".#releaseMatrix.x86_64-linux")" | tee $GITHUB_OUTPUT run: |
echo "cross-matrix={\"include\":$(nix eval --json '.#lib.crossMatrix')}" | tee -a $GITHUB_OUTPUT
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: matrix needs: [matrix]
strategy: strategy:
matrix: ${{fromJson(needs.matrix.outputs.matrix)}} fail-fast: false
matrix: ${{fromJson(needs.matrix.outputs.cross-matrix)}}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: cachix/install-nix-action@v26 - uses: cachix/install-nix-action@v27
- uses: icewind1991/attic-action@v1 - uses: icewind1991/attic-action@v1
with: with:
name: ci name: ci
instance: https://cache.icewind.me instance: https://cache.icewind.me
authToken: '${{ secrets.ATTIC_TOKEN }}' authToken: "${{ secrets.ATTIC_TOKEN }}"
- run: nix build .#${{ matrix.target }} - run: nix build .#${{ matrix.target }}
- name: Upload binary to release - name: Upload binary to release
uses: svenstaro/upload-release-action@v2 uses: svenstaro/upload-release-action@v2
with: with:
repo_token: ${{ secrets.GITHUB_TOKEN }} repo_token: ${{ secrets.GITHUB_TOKEN }}
file: result/bin/${{ matrix.artifact_name }} file: result/bin/palantir${{ matrix.binary-suffix }}
asset_name: ${{ matrix.asset_name }} asset_name: palantir-${{ matrix.target }}${{ matrix.binary-suffix }}
tag: ${{ github.ref }} tag: ${{ github.ref }}

View file

@ -33,6 +33,7 @@ In order to get the power monitoring output you'll need to give the `palantir` u
``` ```
- Create `/etc/udev/rules.d/99-powermonitoring.rules` with - Create `/etc/udev/rules.d/99-powermonitoring.rules` with
```udev ```udev
SUBSYSTEM=="powercap", ACTION=="add", RUN+="/bin/chgrp -R powermonitoring /sys%p", RUN+="/bin/chmod -R g=u /sys%p" SUBSYSTEM=="powercap", ACTION=="add", RUN+="/bin/chgrp -R powermonitoring /sys%p", RUN+="/bin/chmod -R g=u /sys%p"
SUBSYSTEM=="powercap", ACTION=="change", ENV{TRIGGER}!="none", RUN+="/bin/chgrp -R powermonitoring /sys%p", RUN+="/bin/chmod -R g=u /sys%p" SUBSYSTEM=="powercap", ACTION=="change", ENV{TRIGGER}!="none", RUN+="/bin/chgrp -R powermonitoring /sys%p", RUN+="/bin/chmod -R g=u /sys%p"

118
flake.lock generated
View file

@ -1,87 +1,98 @@
{ {
"nodes": { "nodes": {
"cross-naersk": { "crane": {
"inputs": {
"naersk": [
"naersk"
],
"nixpkgs": [
"nixpkgs"
]
},
"locked": { "locked": {
"lastModified": 1705943642, "lastModified": 1727060013,
"narHash": "sha256-M/n8k0Ato/WGmNJjtIUQGoooVBXL1ahSveiCK772Dk8=", "narHash": "sha256-/fC5YlJy4IoAW9GhkJiwyzk0K/gQd9Qi4rRcoweyG9E=",
"owner": "icewind1991", "owner": "ipetkov",
"repo": "cross-naersk", "repo": "crane",
"rev": "db45d5a45b69d7d246bc748a54cd3cbbd9c47e74", "rev": "6b40cc876c929bfe1e3a24bf538ce3b5622646ba",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "icewind1991", "owner": "ipetkov",
"repo": "cross-naersk", "repo": "crane",
"type": "github" "type": "github"
} }
}, },
"naersk": { "flakelight": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
] ]
}, },
"locked": { "locked": {
"lastModified": 1698420672, "lastModified": 1727095190,
"narHash": "sha256-/TdeHMPRjjdJub7p7+w55vyABrsJlt5QkznPYy55vKA=", "narHash": "sha256-eZfUxkPefTP5fknpr2/X+snNysEj830Ft1IaW7VafFE=",
"owner": "nix-community", "owner": "nix-community",
"repo": "naersk", "repo": "flakelight",
"rev": "aeb58d5e8faead8980a807c840232697982d47b9", "rev": "9e0f7e360688187ed3d7d8b033028e0d3473aa2c",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nix-community", "owner": "nix-community",
"repo": "naersk", "repo": "flakelight",
"type": "github"
}
},
"mill-scale": {
"inputs": {
"crane": "crane",
"flakelight": [
"flakelight"
],
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1727557122,
"narHash": "sha256-jNL88qVyF3SwxVTZDsoVTAZ4RTLLMdO/6nGmCzn+BYs=",
"owner": "icewind1991",
"repo": "mill-scale",
"rev": "4cd19c5267db4f42f7e08a78cf157108499f19bc",
"type": "github"
},
"original": {
"owner": "icewind1991",
"repo": "mill-scale",
"type": "github" "type": "github"
} }
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1712437997, "lastModified": 1727540905,
"narHash": "sha256-g0whLLwRvgO2FsyhY8fNk+TWenS3jg5UdlWL4uqgFeo=", "narHash": "sha256-40J9tW7Y794J7Uw4GwcAKlMxlX2xISBl6IBigo83ih8=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "e38d7cb66ea4f7a0eb6681920615dfcc30fc2920", "rev": "fbca5e745367ae7632731639de5c21f29c8744ed",
"type": "github" "type": "github"
}, },
"original": { "original": {
"id": "nixpkgs", "id": "nixpkgs",
"ref": "nixos-23.11", "ref": "nixos-24.05",
"type": "indirect" "type": "indirect"
} }
}, },
"root": { "root": {
"inputs": { "inputs": {
"cross-naersk": "cross-naersk", "flakelight": "flakelight",
"naersk": "naersk", "mill-scale": "mill-scale",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs"
"rust-overlay": "rust-overlay",
"utils": "utils"
} }
}, },
"rust-overlay": { "rust-overlay": {
"inputs": { "inputs": {
"flake-utils": [
"utils"
],
"nixpkgs": [ "nixpkgs": [
"mill-scale",
"flakelight",
"nixpkgs" "nixpkgs"
] ]
}, },
"locked": { "locked": {
"lastModified": 1712542394, "lastModified": 1727058553,
"narHash": "sha256-UZebDBECRSrJqw4K+LxZ6qFdYnScu6q1XCwqtsu1cas=", "narHash": "sha256-tY/UU3Qk5gP/J0uUM4DZ6wo4arNLGAVqLKBotILykfQ=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "ece8bdb3c3b58def25f204b9a1261dee55d7c9c0", "rev": "edc5b0f896170f07bd39ad59d6186fcc7859bbb2",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -89,39 +100,6 @@
"repo": "rust-overlay", "repo": "rust-overlay",
"type": "github" "type": "github"
} }
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

131
flake.nix
View file

@ -1,39 +1,19 @@
{ {
inputs = { inputs = {
nixpkgs.url = "nixpkgs/nixos-23.11"; nixpkgs.url = "nixpkgs/nixos-24.05";
utils.url = "github:numtide/flake-utils"; flakelight = {
naersk.url = "github:nix-community/naersk"; url = "github:nix-community/flakelight";
naersk.inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
rust-overlay.inputs.flake-utils.follows = "utils";
cross-naersk.url = "github:icewind1991/cross-naersk";
cross-naersk.inputs.nixpkgs.follows = "nixpkgs";
cross-naersk.inputs.naersk.follows = "naersk";
}; };
mill-scale = {
outputs = { url = "github:icewind1991/mill-scale";
self, inputs.flakelight.follows = "flakelight";
nixpkgs,
utils,
naersk,
rust-overlay,
cross-naersk,
}:
utils.lib.eachDefaultSystem (system: let
overlays = [
(import rust-overlay)
(import ./overlay.nix)
];
pkgs = import nixpkgs {
inherit system overlays;
}; };
inherit (pkgs) lib rust-bin callPackage; };
inherit (builtins) fromTOML readFile map replaceStrings; outputs = { mill-scale, ... }: mill-scale ./. {
packages.palantir = import ./package.nix;
hostTarget = pkgs.hostPlatform.config; crossTargets = [
targets = [
hostTarget
"x86_64-pc-windows-gnu" "x86_64-pc-windows-gnu"
"x86_64-unknown-linux-musl" "x86_64-unknown-linux-musl"
"i686-unknown-linux-musl" "i686-unknown-linux-musl"
@ -41,92 +21,19 @@
"aarch64-unknown-linux-musl" "aarch64-unknown-linux-musl"
]; ];
releaseTargets = lib.lists.remove hostTarget targets; nixosModules = { outputs, ... }: {
default =
artifactForTarget = target: "palantir${cross-naersk'.execSufficForTarget target}"; { pkgs
assetNameForTarget = target: "palantir-${replaceStrings ["-unknown" "-gnu" "-musl" "abihf" "-pc"] ["" "" "" "" ""] target}${cross-naersk'.execSufficForTarget target}"; , config
, lib
cross-naersk' = callPackage cross-naersk {inherit naersk;}; , ...
src = lib.sources.sourceByRegex (lib.cleanSource ./.) ["Cargo.*" "(src|benches)(/.*)?"];
msrv = (fromTOML (readFile ./Cargo.toml)).package.rust-version;
toolchain = rust-bin.stable.latest.default;
msrvToolchain = rust-bin.stable."${msrv}".default;
nearskOpt = {
pname = "palantir";
root = src;
postInstall = pkgs.palantir.postInstall;
};
buildTarget = target: (cross-naersk'.buildPackage target) nearskOpt;
hostNaersk = cross-naersk'.hostNaersk;
msrvNaersk = callPackage naersk {
rustc = msrvToolchain;
cargo = msrvToolchain;
};
in rec {
packages =
nixpkgs.lib.attrsets.genAttrs targets buildTarget
// rec {
palantir = pkgs.palantir;
check = hostNaersk.buildPackage (nearskOpt
// {
mode = "check";
});
clippy = hostNaersk.buildPackage (nearskOpt
// {
mode = "clippy";
});
msrv = msrvNaersk.buildPackage (nearskOpt
// {
mode = "check";
});
default = palantir;
};
apps = rec {
palantir = utils.lib.mkApp {
drv = packages.palantir;
};
default = palantir;
};
inherit targets;
releaseMatrix = {
include =
builtins.map (target: {
inherit target;
artifact_name = artifactForTarget target;
asset_name = assetNameForTarget target;
})
releaseTargets;
};
# `nix develop`
devShells.default = cross-naersk'.mkShell targets {
nativeBuildInputs = with pkgs; [
toolchain
bacon
cargo-msrv
cargo-edit
];
};
})
// {
overlays.default = import ./overlay.nix;
nixosModules.default = {
pkgs,
config,
lib,
...
}: { }: {
imports = [ ./module.nix ]; imports = [ ./module.nix ];
config = lib.mkIf config.services.palantir.enable { config = lib.mkIf config.services.palantir.enable {
nixpkgs.overlays = [self.overlays.default]; nixpkgs.overlays = [ outputs.overlays.default ];
services.palantir.package = lib.mkDefault pkgs.palantir; services.palantir.package = lib.mkDefault pkgs.palantir;
}; };
}; };
}; };
};
} }

View file

@ -1,12 +1,12 @@
{ { config
config, , lib
lib, , pkgs
pkgs, , ...
...
}: }:
with lib; let with lib; let
cfg = config.services.palantir; cfg = config.services.palantir;
in { in
{
options.services.palantir = { options.services.palantir = {
enable = mkEnableOption "Enables the palantir service"; enable = mkEnableOption "Enables the palantir service";

View file

@ -1,9 +1,10 @@
{ { stdenv
stdenv, , rustPlatform
rustPlatform, , coreutils
coreutils, , lib
lib, ,
}: let }:
let
inherit (lib.sources) sourceByRegex; inherit (lib.sources) sourceByRegex;
inherit (builtins) fromTOML readFile; inherit (builtins) fromTOML readFile;
src = sourceByRegex ./. [ "Cargo.*" "(src|benches)(/.*)?" ]; src = sourceByRegex ./. [ "Cargo.*" "(src|benches)(/.*)?" ];

View file

@ -155,14 +155,22 @@ fn get_sensor(sensors: &[Sensor], ty: &str, name: &str) -> Option<f32> {
} }
pub fn update_power() { pub fn update_power() {
let Ok(com_con) = COMLibrary::new() else {return;}; let Ok(com_con) = COMLibrary::new() else {
return;
};
if let Ok(wmi_con) = WMIConnection::with_namespace_path("ROOT\\LibreHardwareMonitor", com_con) { if let Ok(wmi_con) = WMIConnection::with_namespace_path("ROOT\\LibreHardwareMonitor", com_con) {
loop { loop {
if let Some(elapsed) = get_power_elapsed() { if let Some(elapsed) = get_power_elapsed() {
let Ok(sensors) = wmi_con.query::<Sensor>() else {return;}; let Ok(sensors) = wmi_con.query::<Sensor>() else {
return;
};
let sensors: Vec<Sensor> = sensors; let sensors: Vec<Sensor> = sensors;
let Some(cpu_current_power) = get_sensor(&sensors, "Power", "CPU Package") else {return;}; let Some(cpu_current_power) = get_sensor(&sensors, "Power", "CPU Package") else {
let Some(gpu_current_power) = get_sensor(&sensors, "Power", "GPU Package") else {return;}; return;
};
let Some(gpu_current_power) = get_sensor(&sensors, "Power", "GPU Package") else {
return;
};
let elapsed_sec = elapsed.as_secs_f32(); let elapsed_sec = elapsed.as_secs_f32();