aboutsummaryrefslogtreecommitdiff
path: root/.config/ags/service/nix.ts
diff options
context:
space:
mode:
authorsrdusr <trevorgray@srdusr.com>2025-08-30 19:22:59 +0200
committersrdusr <trevorgray@srdusr.com>2025-08-30 19:22:59 +0200
commit19120d4f9761c67d99ed1ce3da6084b83f5a49c9 (patch)
treef234cad1bdad88114a63c9702144da487024967a /.config/ags/service/nix.ts
parent5928998af5404ae2be84c6cecc10ebf84bd3f3ed (diff)
downloaddotfiles-19120d4f9761c67d99ed1ce3da6084b83f5a49c9.tar.gz
dotfiles-19120d4f9761c67d99ed1ce3da6084b83f5a49c9.zip
Linux-specific dotfiles
Diffstat (limited to '.config/ags/service/nix.ts')
-rw-r--r--.config/ags/service/nix.ts109
1 files changed, 0 insertions, 109 deletions
diff --git a/.config/ags/service/nix.ts b/.config/ags/service/nix.ts
deleted file mode 100644
index 3bde9fc..0000000
--- a/.config/ags/service/nix.ts
+++ /dev/null
@@ -1,109 +0,0 @@
-import icons from "lib/icons"
-import { bash, dependencies } from "lib/utils"
-import options from "options"
-
-const CACHE = `${Utils.CACHE_DIR}/nixpkgs`
-const PREFIX = "legacyPackages.x86_64-linux."
-const MAX = options.launcher.nix.max
-const nixpkgs = options.launcher.nix.pkgs
-
-export type Nixpkg = {
- name: string
- description: string
- pname: string
- version: string
-}
-
-class Nix extends Service {
- static {
- Service.register(this, {}, {
- "available": ["boolean", "r"],
- "ready": ["boolean", "rw"],
- })
- }
-
- #db: { [name: string]: Nixpkg } = {}
- #ready = true
-
- private set ready(r: boolean) {
- this.#ready = r
- this.changed("ready")
- }
-
- get db() { return this.#db }
- get ready() { return this.#ready }
- get available() { return Utils.exec("which nix") }
-
- constructor() {
- super()
- if (!this.available)
- return this
-
- this.#updateList()
- nixpkgs.connect("changed", this.#updateList)
- }
-
- query = async (filter: string) => {
- if (!dependencies("fzf", "nix") || !this.#ready)
- return [] as string[]
-
- return bash(`cat ${CACHE} | fzf -f ${filter} -e | head -n ${MAX} `)
- .then(str => str.split("\n").filter(i => i))
- }
-
- nix(cmd: string, bin: string, args: string) {
- return Utils.execAsync(`nix ${cmd} ${nixpkgs}#${bin} --impure ${args}`)
- }
-
- run = async (input: string) => {
- if (!dependencies("nix"))
- return
-
- try {
- const [bin, ...args] = input.trim().split(/\s+/)
-
- this.ready = false
- await this.nix("shell", bin, "--command sh -c 'exit'")
- this.ready = true
-
- this.nix("run", bin, ["--", ...args].join(" "))
- } catch (err) {
- if (typeof err === "string")
- Utils.notify("NixRun Error", err, icons.nix.nix)
- else
- logError(err)
- } finally {
- this.ready = true
- }
- }
-
- #updateList = async () => {
- if (!dependencies("nix"))
- return
-
- this.ready = false
- this.#db = {}
-
- // const search = await bash(`nix search ${nixpkgs} --json`)
- const search = ""
- if (!search) {
- this.ready = true
- return
- }
-
- const json = Object.entries(JSON.parse(search) as {
- [name: string]: Nixpkg
- })
-
- for (const [pkg, info] of json) {
- const name = pkg.replace(PREFIX, "")
- this.#db[name] = { ...info, name }
- }
-
- const list = Object.keys(this.#db).join("\n")
- await Utils.writeFile(list, CACHE)
- this.ready = true
- }
-}
-
-export default new Nix