quickshell-toki-night/services/NixOS.qml

60 lines
1.7 KiB
QML

pragma Singleton
import QtQuick
import Quickshell
import Quickshell.Io
Singleton {
id: root
readonly property string nixVersion: nixVersionProc.nixVersion
readonly property list<Generation> generations: nixosGenerationsProc.generations
readonly property Generation currentGen: generations.find(g => g.current) ?? null
Timer {
running: true
repeat: true
triggeredOnStart: true
interval: 60000
onTriggered: {
nixVersionProc.running = true;
nixosGenerationsProc.running = true;
}
}
Process {
id: nixVersionProc
command: ["nix", "--version"]
property string nixVersion: ""
stdout: StdioCollector {
onStreamFinished: nixVersionProc.nixVersion = this.text.split(" ")[2].trim()
}
}
Process {
id: nixosGenerationsProc
command: ["nixos-rebuild", "list-generations", "--json"]
property list<Generation> generations: []
stdout: StdioCollector {
onStreamFinished: {
const json = JSON.parse(this.text);
nixosGenerationsProc.generations = json.map(o => genComp.createObject(root, { ipcObject: o }));
}
}
}
component Generation: QtObject {
required property var ipcObject
readonly property int id: ipcObject.generation
readonly property date date: ipcObject.date
readonly property string nixosVersion: ipcObject.nixosVersion
readonly property string kernelVersion: ipcObject.kernelVersion
readonly property string revision: ipcObject.configurationRevision
readonly property bool current: ipcObject.current
}
Component {
id: genComp
Generation {}
}
}