Compare commits

..

1 commit

Author SHA1 Message Date
bb1b491abc
refactor(modules/lib): move more options to it
Some checks failed
/ check (push) Failing after 4s
/ check-renovaterc (push) Successful in 3s
/ build-packages (push) Has been skipped
/ build-vm (push) Has been skipped
/ report-size (push) Has been skipped
This should keep all my custom options in the same place.
2025-04-22 14:14:49 +02:00
43 changed files with 2081 additions and 995 deletions

1
.envrc
View file

@ -7,5 +7,4 @@ elif has git; then
git fetch
fi
watch_file ./flake.{nix,lock} ./flake-modules/{default,devshells,overlays,nixvim-modules}.nix
use flake

View file

@ -1,92 +1,52 @@
on:
push:
jobs:
check-fmt:
check:
runs-on: nixos
steps:
- uses: https://git.salame.cl/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- run: nix --version
- name: Run treefmt
run: |
nix build --print-build-logs ".#checks.$(nix eval --raw --impure --expr builtins.currentSystem).treefmt"
build-package:
runs-on: nixos
needs: check-fmt
strategy:
matrix:
package:
- audiomenu
- docs
- docs-home-markdown
- docs-nixos-markdown
- docs-nvim-markdown
- jpassmenu
- nvim
- nvim-headless
- nvim-no-lsps
- nvim-no-ts
- nvim-small
- search
steps:
- uses: "https://git.salame.cl/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683" # v4
- run: nix --version
- name: Build target
env:
PACKAGE: ${{ matrix.package }}
- name: Run checks
run: |
# shellcheck disable=SC2016
nix build --print-build-logs ".#$PACKAGE"
check-nvim:
nix --version
nix-fast-build --max-jobs 2 --no-nom --skip-cached --no-link \
--flake ".#checks.$(nix eval --raw --impure --expr builtins.currentSystem)"
check-renovaterc:
runs-on: nixos
needs: build-package
strategy:
matrix:
nvim:
- nvim
- nvim-headless
- nvim-no-lsps
- nvim-no-ts
- nvim-small
steps:
- uses: "https://git.salame.cl/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683" # v4
- run: nix --version
- name: Build target
env:
NVIM: ${{ matrix.nvim }}
- name: Validate renovaterc.json
run: |
nix build --print-build-logs ".#checks.$(nix eval --raw --impure --expr builtins.currentSystem).$NVIM"
nix --version
nix shell nixpkgs#renovate --command renovate-config-validator
build-packages:
runs-on: nixos
needs: check
steps:
- uses: "https://git.salame.cl/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683" # v4
- name: Build target
run: |
nix --version
nix-fast-build --max-jobs 2 --no-nom --skip-cached --no-link \
--flake ".#packages.$(nix eval --raw --impure --expr builtins.currentSystem)"
build-vm:
runs-on: nixos
needs:
- build-package
- check-nvim
needs: build-packages
steps:
- uses: "https://git.salame.cl/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683" # v4
- run: nix --version
- name: Build VM configuration
run: |
nix --version
nix build --print-build-logs '.#nixosConfigurations.vm.config.system.build.toplevel'
build-hm:
runs-on: nixos
needs:
- build-package
- check-nvim
steps:
- uses: "https://git.salame.cl/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683" # v4
- run: nix --version
- name: Build Home Manager configuration
run: |
nix build --print-build-logs '.#homeConfigurations.example.activationPackage'
report-size:
runs-on: nixos
needs:
- build-packages
- build-vm
- build-hm
steps:
- uses: "https://git.salame.cl/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683" # v4
- run: nix --version
- name: Create Size Report
uses: "https://git.salame.cl/jalil/nix-flake-outputs-size@838f2050208b41c339803a1111608d7182bbda3e" # main
uses: "https://git.salame.cl/jalil/nix-flake-outputs-size@5c40a31e3e2ed0ea28f8ba68deca41d05fdf2e71" # main
with:
# Create a comment on the associated PR
comment-on-pr: ${{ github.ref_name != 'main' }}

View file

@ -1,14 +0,0 @@
on:
push:
paths:
# only run if the renovate config changed
- renovate.json
jobs:
check-renovaterc:
runs-on: nixos
steps:
- uses: https://git.salame.cl/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- run: nix --version
- name: Validate renovaterc.json
run: |
nix shell nixpkgs#renovate --command renovate-config-validator

View file

@ -13,6 +13,11 @@
"config:best-practices"
],
"nix": {
"fileMatch": [
"(^|/)flake\\.nix$"
],
"commitMessageTopic": "nixpkgs",
"commitMessageExtra": "to {{newValue}}",
"enabled": true
},
"lockFileMaintenance": {

View file

@ -5,12 +5,6 @@ multilingual = false
src = "src"
title = "Jalil's NixOS configuration modules"
[build]
create-missing = false
[preprocessor.toc]
command = "mdbook-toc"
renderer = ["html"]
[output.html]
git-repository-url = "https://github.com/jalil-salame/configuration.nix"

View file

@ -1,70 +0,0 @@
{
lib,
pkgs,
config,
...
}:
{
home = {
homeDirectory = "/home/jdoe";
stateVersion = "25.05";
username = "jdoe";
};
jhome = {
enable = true;
dev = {
enable = true;
neovimAsManPager = true;
rust.enable = true;
};
gui.enable = false;
hostName = "example";
user = {
enable = true;
defaultIdentity = {
email = "jdoe@example.org";
name = "John Doe";
};
};
};
programs = {
# Switch to fish if bash is started interactively
bash.initExtra = ''
if [[ $(${pkgs.procps}/bin/ps --no-header --pid=$PPID --format=comm) != "fish" && -z ''${BASH_EXECUTION_STRING} ]]
then
shopt -q login_shell && LOGIN_OPTION='--login' || LOGIN_OPTION=""
exec ${pkgs.fish}/bin/fish $LOGIN_OPTION
fi
'';
# Enable zellij (tmux like terminal session manager)
zellij.enable = lib.mkForce true;
};
nix = {
package = pkgs.lix;
gc = {
automatic = true;
frequency = "weekly";
options = "--delete-older-than 30d";
# run between 0 and 45min after boot if run was missed
randomizedDelaySec = "45min";
};
settings = {
# Add my personal binary cache to the mix (only for personal computers)
extra-substituters = [ "https://cache.salame.cl" ];
extra-trusted-public-keys = [ "cache.salame.cl:D+pBaoutwxja7qKGpju+CmM1LRbVmf2gqEQ/9c7qHrw=" ];
auto-optimise-store = true;
};
};
stylix = {
image = config.jhome.gui.sway.background;
base16Scheme = "${pkgs.base16-schemes}/share/themes/gruvbox-dark-hard.yaml";
};
# Let Home Manager install and manage itself.
programs.home-manager.enable = true;
}

View file

@ -5,7 +5,7 @@
./devshells.nix
./docs.nix
./example-configs.nix
./example-vm.nix
./nixos-modules.nix
./home-modules.nix
./nixvim-modules.nix

View file

@ -6,7 +6,6 @@ _: {
buildInputs = [
pkgs.just
self'.packages.nvim
pkgs.uv
];
QEMU_OPTS_WL = "-enable-kvm -nodefaults -m 4G -cpu host -smp 4 -device virtio-gpu";
};

View file

@ -62,7 +62,7 @@
''; # FIXME: only add the `/configuration.nix/` part for GH CI
nativeBuildInputs = [ pkgs.mdbook-toc ];
buildPhase = "${pkgs.mdbook}/bin/mdbook build --dest-dir $out";
buildPhase = "${pkgs.mdbook}/bin/mdbook build --dest-dir \"$out\"";
};
};
};

View file

@ -1,33 +0,0 @@
{ inputs, lib, ... }:
{
flake = {
# Example vm configuration
nixosConfigurations.vm = lib.nixosSystem {
modules = [
inputs.self.nixosModules.default
../example-vm # import vm configuration
{
nixpkgs = {
overlays = builtins.attrValues inputs.self.overlays;
config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ "steam-unwrapped" ];
};
# pin nixpkgs to the one used by the system
nix.registry.nixpkgs.flake = inputs.nixpkgs;
}
];
};
homeConfigurations.example = inputs.home-manager.lib.homeManagerConfiguration {
pkgs = inputs.nixpkgs.legacyPackages.x86_64-linux;
modules = [
inputs.self.homeModules.standalone
../example-hm/home.nix # import home-manager configuration
{
nixpkgs.overlays = [
inputs.self.overlays.unstable
inputs.lix-module.overlays.default
];
}
];
};
};
}

View file

@ -0,0 +1,18 @@
{ inputs, lib, ... }:
{
# Example vm configuration
flake.nixosConfigurations.vm = lib.nixosSystem {
modules = [
inputs.self.nixosModules.default
../example-vm # import vm configuration
{
nixpkgs = {
overlays = builtins.attrValues inputs.self.overlays;
config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ "steam-unwrapped" ];
};
# pin nixpkgs to the one used by the system
nix.registry.nixpkgs.flake = inputs.nixpkgs;
}
];
};
}

View file

@ -1,11 +1,12 @@
{ self, inputs, ... }:
{
imports = [ inputs.home-manager.flakeModules.home-manager ];
# FIXME(25.05): this version of HM should have the flake module
# imports = [ inputs.home-manager.flakeModules.home-manager ];
flake.homeModules =
let
defaultModules = [
inputs.nixvim.homeModules.nixvim
inputs.nixvim.homeManagerModules.nixvim
self.nixvimModules.homeManager
../modules/hm
];
@ -14,11 +15,11 @@
};
standalone = {
imports = defaultModules ++ [
inputs.stylix.homeModules.stylix
inputs.stylix.homeManagerModules.stilyx
(
{ lib, config, ... }:
lib.mkIf config.jhome.gui.enable {
stylix.image = config.jhome.gui.sway.background;
{ config, ... }:
{
stylix.image = config.jhome.sway.background;
}
)
];

207
flake.lock generated
View file

@ -5,11 +5,11 @@
"fromYaml": "fromYaml"
},
"locked": {
"lastModified": 1746562888,
"narHash": "sha256-YgNJQyB5dQiwavdDFBMNKk1wyS77AtdgDk/VtU6wEaI=",
"lastModified": 1732200724,
"narHash": "sha256-+R1BH5wHhfnycySb7Sy5KbYEaTJZWm1h+LW1OtyhiTs=",
"owner": "SenchoPens",
"repo": "base16.nix",
"rev": "806a1777a5db2a1ef9d5d6f493ef2381047f2b89",
"rev": "153d52373b0fb2d343592871009a286ec8837aec",
"type": "github"
},
"original": {
@ -70,11 +70,11 @@
"firefox-gnome-theme": {
"flake": false,
"locked": {
"lastModified": 1744642301,
"narHash": "sha256-5A6LL7T0lttn1vrKsNOKUk9V0ittdW0VEqh6AtefxJ4=",
"lastModified": 1743774811,
"narHash": "sha256-oiHLDHXq7ymsMVYSg92dD1OLnKLQoU/Gf2F1GoONLCE=",
"owner": "rafaelmardojai",
"repo": "firefox-gnome-theme",
"rev": "59e3de00f01e5adb851d824cf7911bd90c31083a",
"rev": "df53a7a31872faf5ca53dd0730038a62ec63ca9e",
"type": "github"
},
"original": {
@ -90,11 +90,11 @@
]
},
"locked": {
"lastModified": 1749398372,
"narHash": "sha256-tYBdgS56eXYaWVW3fsnPQ/nFlgWi/Z2Ymhyu21zVM98=",
"lastModified": 1743550720,
"narHash": "sha256-hIshGgKZCgWh6AYJpJmRgFdR3WUbkY04o82X05xqQiY=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "9305fe4e5c2a6fcf5ba6a3ff155720fbe4076569",
"rev": "c621e8422220273271f52058f618c94e405bb0f5",
"type": "github"
},
"original": {
@ -205,16 +205,16 @@
"gnome-shell": {
"flake": false,
"locked": {
"lastModified": 1744584021,
"narHash": "sha256-0RJ4mJzf+klKF4Fuoc8VN8dpQQtZnKksFmR2jhWE1Ew=",
"lastModified": 1732369855,
"narHash": "sha256-JhUWbcYPjHO3Xs3x9/Z9RuqXbcp5yhPluGjwsdE2GMg=",
"owner": "GNOME",
"repo": "gnome-shell",
"rev": "52c517c8f6c199a1d6f5118fae500ef69ea845ae",
"rev": "dadd58f630eeea41d645ee225a63f719390829dc",
"type": "github"
},
"original": {
"owner": "GNOME",
"ref": "48.1",
"ref": "47.2",
"repo": "gnome-shell",
"type": "github"
}
@ -226,16 +226,16 @@
]
},
"locked": {
"lastModified": 1750792728,
"narHash": "sha256-Lh3dopA8DdY+ZoaAJPrtkZOZaFEJGSYjOdAYYgOPgE4=",
"lastModified": 1744743431,
"narHash": "sha256-iyn/WBYDc7OtjSawbegINDe/gIkok888kQxk3aVnkgg=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "366f00797b1efb70f2882d3da485e3c10fd3d557",
"rev": "c61bfe3ae692f42ce688b5865fac9e0de58e1387",
"type": "github"
},
"original": {
"owner": "nix-community",
"ref": "release-25.05",
"ref": "release-24.11",
"repo": "home-manager",
"type": "github"
}
@ -252,16 +252,16 @@
]
},
"locked": {
"lastModified": 1748294338,
"narHash": "sha256-FVO01jdmUNArzBS7NmaktLdGA5qA3lUMJ4B7a05Iynw=",
"lastModified": 1737371634,
"narHash": "sha256-fTVAWzT1UMm1lT+YxHuVPtH+DATrhYfea3B0MxG/cGw=",
"owner": "NuschtOS",
"repo": "ixx",
"rev": "cc5f390f7caf265461d4aab37e98d2292ebbdb85",
"rev": "a1176e2a10ce745ff8f63e4af124ece8fe0b1648",
"type": "github"
},
"original": {
"owner": "NuschtOS",
"ref": "v0.0.8",
"ref": "v0.0.7",
"repo": "ixx",
"type": "github"
}
@ -269,15 +269,15 @@
"lix": {
"flake": false,
"locked": {
"lastModified": 1750762203,
"narHash": "sha256-LmQhjQ7c+AOkwhvR9GFgJOy8oHW35MoQRELtrwyVnPw=",
"rev": "38b358ce27203f972faa2973cf44ba80c758f46e",
"lastModified": 1737234286,
"narHash": "sha256-pgDJZjj4jpzkFxsqBTI/9Yb0n3gW+DvDtuv9SwQZZcs=",
"rev": "079528098f5998ba13c88821a2eca1005c1695de",
"type": "tarball",
"url": "https://git.lix.systems/api/v1/repos/lix-project/lix/archive/38b358ce27203f972faa2973cf44ba80c758f46e.tar.gz?rev=38b358ce27203f972faa2973cf44ba80c758f46e"
"url": "https://git.lix.systems/api/v1/repos/lix-project/lix/archive/079528098f5998ba13c88821a2eca1005c1695de.tar.gz?rev=079528098f5998ba13c88821a2eca1005c1695de"
},
"original": {
"type": "tarball",
"url": "https://git.lix.systems/lix-project/lix/archive/release-2.93.tar.gz"
"url": "https://git.lix.systems/lix-project/lix/archive/release-2.92.tar.gz"
}
},
"lix-module": {
@ -290,28 +290,47 @@
]
},
"locked": {
"lastModified": 1750776670,
"narHash": "sha256-EfA5K5EZAnspmraJrXQlziffVpaT+QDBiE6yKmuaNNQ=",
"rev": "c3c78a32273e89d28367d8605a4c880f0b6607e3",
"lastModified": 1742943028,
"narHash": "sha256-fprwZKE1uMzO9tiWWOrmLWBW3GPkMayQfb0xOvVFIno=",
"rev": "3fae818597ca2f1474de62022f850c23be50528d",
"type": "tarball",
"url": "https://git.lix.systems/api/v1/repos/lix-project/nixos-module/archive/c3c78a32273e89d28367d8605a4c880f0b6607e3.tar.gz?rev=c3c78a32273e89d28367d8605a4c880f0b6607e3"
"url": "https://git.lix.systems/api/v1/repos/lix-project/nixos-module/archive/3fae818597ca2f1474de62022f850c23be50528d.tar.gz?rev=3fae818597ca2f1474de62022f850c23be50528d"
},
"original": {
"type": "tarball",
"url": "https://git.lix.systems/lix-project/nixos-module/archive/release-2.93.tar.gz"
"url": "https://git.lix.systems/lix-project/nixos-module/archive/release-2.92.tar.gz"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1750906613,
"narHash": "sha256-EcKpawfFHpBnlqYOX+uoU9xovM1B+L16QvfVQPeQKzw=",
"rev": "7284e2decc982b81a296ab35aa46e804baaa1cfe",
"type": "tarball",
"url": "https://releases.nixos.org/nixos/25.05/nixos-25.05.804745.7284e2decc98/nixexprs.tar.xz?rev=7284e2decc982b81a296ab35aa46e804baaa1cfe"
"lastModified": 1744440957,
"narHash": "sha256-FHlSkNqFmPxPJvy+6fNLaNeWnF1lZSgqVCl/eWaJRc4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "26d499fc9f1d567283d5d56fcf367edd815dba1d",
"type": "github"
},
"original": {
"type": "tarball",
"url": "https://channels.nixos.org/nixos-25.05/nixexprs.tar.xz"
"owner": "NixOS",
"ref": "nixos-24.11",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1744536153,
"narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixvim": {
@ -319,20 +338,15 @@
"flake-parts": [
"flake-parts"
],
"nixpkgs": [
"unstable"
],
"nuschtosSearch": [],
"systems": [
"systems"
]
"nixpkgs": "nixpkgs_2",
"nuschtosSearch": []
},
"locked": {
"lastModified": 1751053139,
"narHash": "sha256-FMcWdec8fAXs7kiOQBsD+vA/RzjqoDz3zoYgPDQpZlA=",
"lastModified": 1745244491,
"narHash": "sha256-UlwXkytxGW/aokB9fZ6cSznYKM9ynDLHqhjcPve0KL4=",
"owner": "nix-community",
"repo": "nixvim",
"rev": "c39f5f39c32e0a8fe91bff1cda847de7a0269411",
"rev": "7a58109958d14bcece8ec3e2085e41ea3351e387",
"type": "github"
},
"original": {
@ -353,11 +367,11 @@
]
},
"locked": {
"lastModified": 1749730855,
"narHash": "sha256-L3x2nSlFkXkM6tQPLJP3oCBMIsRifhIDPMQQdHO5xWo=",
"lastModified": 1745046075,
"narHash": "sha256-8v4y6k16Ra/fiecb4DxhsoOGtzLKgKlS+9/XJ9z0T2I=",
"owner": "NuschtOS",
"repo": "search",
"rev": "8dfe5879dd009ff4742b668d9c699bc4b9761742",
"rev": "066afe8643274470f4a294442aadd988356a478f",
"type": "github"
},
"original": {
@ -377,7 +391,10 @@
"stylix": "stylix",
"systems": "systems",
"treefmt-nix": "treefmt-nix",
"unstable": "unstable"
"unstable": [
"nixvim",
"nixpkgs"
]
}
},
"stylix": {
@ -388,8 +405,9 @@
"base16-vim": "base16-vim",
"firefox-gnome-theme": "firefox-gnome-theme",
"flake-compat": [],
"flake-parts": [
"flake-parts"
"flake-utils": [
"lix-module",
"flake-utils"
],
"git-hooks": "git-hooks",
"gnome-shell": "gnome-shell",
@ -399,27 +417,24 @@
"nixpkgs": [
"nixpkgs"
],
"nur": [],
"systems": [
"systems"
],
"tinted-foot": "tinted-foot",
"tinted-kitty": "tinted-kitty",
"tinted-schemes": "tinted-schemes",
"tinted-tmux": "tinted-tmux",
"tinted-zed": "tinted-zed"
"tinted-tmux": "tinted-tmux"
},
"locked": {
"lastModified": 1750964616,
"narHash": "sha256-C4Ze08bSadL/3Xba88wrxcmlzn/kPM2Bj3lBX501htk=",
"owner": "nix-community",
"lastModified": 1744152965,
"narHash": "sha256-LWUeN1+bH3k46fwtIv0bNgtmkqB0UduyX7T2i+230n0=",
"owner": "danth",
"repo": "stylix",
"rev": "d25e22b5c559651da55c0f46106e44fc88069ae1",
"rev": "8748db082ca15d32243c86e5d785d5dfc8a65719",
"type": "github"
},
"original": {
"owner": "nix-community",
"ref": "release-25.05",
"owner": "danth",
"ref": "release-24.11",
"repo": "stylix",
"type": "github"
}
@ -459,43 +474,28 @@
"tinted-kitty": {
"flake": false,
"locked": {
"lastModified": 1735730497,
"narHash": "sha256-4KtB+FiUzIeK/4aHCKce3V9HwRvYaxX+F1edUrfgzb8=",
"lastModified": 1716423189,
"narHash": "sha256-2xF3sH7UIwegn+2gKzMpFi3pk5DlIlM18+vj17Uf82U=",
"owner": "tinted-theming",
"repo": "tinted-kitty",
"rev": "de6f888497f2c6b2279361bfc790f164bfd0f3fa",
"rev": "eb39e141db14baef052893285df9f266df041ff8",
"type": "github"
},
"original": {
"owner": "tinted-theming",
"repo": "tinted-kitty",
"type": "github"
}
},
"tinted-schemes": {
"flake": false,
"locked": {
"lastModified": 1744974599,
"narHash": "sha256-Fg+rdGs5FAgfkYNCs74lnl8vkQmiZVdBsziyPhVqrlY=",
"owner": "tinted-theming",
"repo": "schemes",
"rev": "28c26a621123ad4ebd5bbfb34ab39421c0144bdd",
"type": "github"
},
"original": {
"owner": "tinted-theming",
"repo": "schemes",
"rev": "eb39e141db14baef052893285df9f266df041ff8",
"type": "github"
}
},
"tinted-tmux": {
"flake": false,
"locked": {
"lastModified": 1745111349,
"narHash": "sha256-udV+nHdpqgkJI9D0mtvvAzbqubt9jdifS/KhTTbJ45w=",
"lastModified": 1743296873,
"narHash": "sha256-8IQulrb1OBSxMwdKijO9fB70ON//V32dpK9Uioy7FzY=",
"owner": "tinted-theming",
"repo": "tinted-tmux",
"rev": "e009f18a01182b63559fb28f1c786eb027c3dee9",
"rev": "af5152c8d7546dfb4ff6df94080bf5ff54f64e3a",
"type": "github"
},
"original": {
@ -504,22 +504,6 @@
"type": "github"
}
},
"tinted-zed": {
"flake": false,
"locked": {
"lastModified": 1725758778,
"narHash": "sha256-8P1b6mJWyYcu36WRlSVbuj575QWIFZALZMTg5ID/sM4=",
"owner": "tinted-theming",
"repo": "base16-zed",
"rev": "122c9e5c0e6f27211361a04fae92df97940eccf9",
"type": "github"
},
"original": {
"owner": "tinted-theming",
"repo": "base16-zed",
"type": "github"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
@ -527,11 +511,11 @@
]
},
"locked": {
"lastModified": 1750931469,
"narHash": "sha256-0IEdQB1nS+uViQw4k3VGUXntjkDp7aAlqcxdewb/hAc=",
"lastModified": 1744961264,
"narHash": "sha256-aRmUh0AMwcbdjJHnytg1e5h5ECcaWtIFQa6d9gI85AI=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "ac8e6f32e11e9c7f153823abc3ab007f2a65d3e1",
"rev": "8d404a69efe76146368885110f29a2ca3700bee6",
"type": "github"
},
"original": {
@ -539,19 +523,6 @@
"repo": "treefmt-nix",
"type": "github"
}
},
"unstable": {
"locked": {
"lastModified": 1750915984,
"narHash": "sha256-H35GgPwCiZF7vOX6y6/9cbC3Bt8xZyZgy3p2VIENRfM=",
"rev": "30a61f056ac492e3b7cdcb69c1e6abdcf00e39cf",
"type": "tarball",
"url": "https://releases.nixos.org/nixos/unstable/nixos-25.11pre820854.30a61f056ac4/nixexprs.tar.xz?rev=30a61f056ac492e3b7cdcb69c1e6abdcf00e39cf"
},
"original": {
"type": "tarball",
"url": "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz"
}
}
},
"root": "root",

View file

@ -8,11 +8,11 @@
# Flake inputs
inputs = {
nixpkgs.url = "https://channels.nixos.org/nixos-25.05/nixexprs.tar.xz";
unstable.url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
unstable.follows = "nixvim/nixpkgs";
# Lix
lix-module = {
url = "https://git.lix.systems/lix-project/nixos-module/archive/release-2.93.tar.gz";
url = "https://git.lix.systems/lix-project/nixos-module/archive/release-2.92.tar.gz";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.inputs.systems.follows = "systems";
@ -20,16 +20,15 @@
};
# Modules
home-manager = {
url = "github:nix-community/home-manager/release-25.05";
url = "github:nix-community/home-manager/release-24.11";
inputs.nixpkgs.follows = "nixpkgs";
};
stylix = {
url = "github:nix-community/stylix/release-25.05";
url = "github:danth/stylix/release-24.11";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-parts.follows = "flake-parts";
flake-utils.follows = "lix-module/flake-utils";
systems.follows = "systems";
nur.follows = "";
home-manager.follows = "home-manager";
# disable optional inputs
@ -40,8 +39,6 @@
url = "github:nix-community/nixvim";
inputs = {
flake-parts.follows = "flake-parts";
systems.follows = "systems";
nixpkgs.follows = "unstable";
# disable optional inputs
nuschtosSearch.follows = "";
};

View file

@ -31,33 +31,13 @@ in
# Add gopass if pass is enabled
home.packages = lib.optional config.programs.password-store.enable pkgs.gopass;
nix = {
# Run GC for Home Manager generations
gc = {
automatic = true;
frequency = "weekly";
options = "--delete-older-than 30d";
# run between 0 and 45min after boot if run was missed
randomizedDelaySec = "45min";
};
# Use XDG directories
settings.use-xdg-base-directories = fromOs [
nix.settings.use-xdg-base-directories = fromOs [
"nix"
"settings"
"use-xdg-base-directories"
] true;
};
programs = {
# Switch to fish if bash is started interactively
bash.initExtra = ''
if [[ $(${pkgs.procps}/bin/ps --no-header --pid=$PPID --format=comm) != "fish" && -z ''${BASH_EXECUTION_STRING} ]]
then
shopt -q login_shell && LOGIN_OPTION='--login' || LOGIN_OPTION=""
exec ${pkgs.fish}/bin/fish $LOGIN_OPTION
fi
'';
# Better cat (bat)
bat = {
enable = true;
@ -108,11 +88,9 @@ in
gpg-agent = {
enable = true;
maxCacheTtl = 86400;
pinentry.package = if config.jhome.gui.enable then pkgs.pinentry-qt else pkgs.pinentry-curses;
pinentryPackage = if config.jhome.gui.enable then pkgs.pinentry-qt else pkgs.pinentry-curses;
extraConfig = "allow-preset-passphrase";
};
# Delete old generations (>month)
home-manager.autoExpire.enable = true;
# Spotifyd
spotifyd = {
inherit (config.jhome.gui) enable;

View file

@ -6,80 +6,6 @@
}:
let
cfg = config.jhome.dev;
nvimFormatters = builtins.mapAttrs (
name: value: value.command
) config.programs.nixvim.plugins.conform-nvim.settings.formatters;
jjFormatters =
let
ext_to_glob = ext: "glob:'**/*.${ext}'";
exts = builtins.map ext_to_glob;
in
{
fish = cmd: {
command = [ cmd ];
patterns = exts [ "fish" ];
};
clang_format = cmd: {
command = [
cmd
"--assume-filename=$path"
];
patterns = exts [
"c"
"cc"
"cpp"
"h"
"hh"
"hpp"
];
};
nixfmt = cmd: {
command = [
cmd
"--filename=$path"
];
patterns = exts [ "nix" ];
};
shfmt = cmd: {
command = [
cmd
"--filename"
"$path"
"-"
];
patterns = exts [
"sh"
"bash"
];
};
stylua = cmd: {
command = [
cmd
"--stdin-filepath=$path"
"-"
];
patterns = exts [ "lua" ];
};
taplo = cmd: {
command = [
cmd
"format"
"--stdin-filepath=$path"
"-"
];
patterns = exts [ "toml" ];
};
yamlfmt = cmd: {
command = [
cmd
"-in"
];
patterns = exts [
"yaml"
"yml"
];
};
};
in
{
config =
@ -139,22 +65,9 @@ in
# Jujutsu (alternative DVCS (git-compatible))
jujutsu = {
enable = true;
# Use the more up to date version of jj
package = pkgs.unstable.jujutsu;
settings = {
ui = lib.mkMerge [
# If `bat` is available use it as the pager
(lib.mkIf config.programs.bat.enable { pager = "bat"; })
# if hunk.nvim is enabled use it as a diff editor
(lib.mkIf config.programs.nixvim.plugins.hunk.enable {
diff-editor = [
"nvim"
"-c"
"DiffEditor $left $right $output"
];
})
];
fix.tools = builtins.mapAttrs (tool: cmd: jjFormatters.${tool} cmd) nvimFormatters;
ui.pager = "bat";
# mimic git commit --verbose by adding a diff
templates.draft_commit_description = ''
concat(

View file

@ -13,7 +13,6 @@ let
cfg = jhome.gui;
cursor = {
package = pkgs.nordzy-cursor-theme;
size = 48;
name = "Nordzy-cursors";
};
iconTheme = {
@ -28,18 +27,20 @@ in
];
config = lib.mkIf (jhome.enable && cfg.enable) {
home.packages = [
pkgs.webcord
pkgs.ferdium
pkgs.xournalpp
pkgs.signal-desktop
pkgs.pcmanfm
pkgs.wl-clipboard
home.packages =
(with pkgs; [
webcord
ferdium
xournalpp
signal-desktop
pcmanfm
wl-clipboard
# Extra fonts
pkgs.noto-fonts-cjk-sans # Chinese, Japanese and Korean characters
pkgs.noto-fonts-cjk-serif # Chinese, Japanese and Korean characters
pkgs.nerd-fonts.symbols-only
] ++ lib.optional flatpakEnabled pkgs.flatpak;
noto-fonts-cjk-sans # Chinese, Japanese and Korean characters
noto-fonts-cjk-serif # Chinese, Japanese and Korean characters
(nerdfonts.override { fonts = [ "NerdFontsSymbolsOnly" ]; })
])
++ lib.optional flatpakEnabled pkgs.flatpak;
fonts.fontconfig = {
enable = true;
defaultFonts = lib.mkIf config.jhome.styling.enable {
@ -60,76 +61,7 @@ in
};
# Browser
programs = {
firefox = {
enable = true;
profiles."${config.home.username}" = {
search = {
force = true; # firefox replaces the search settings, force replace them back
engines =
let
queryParam = name: value: { inherit name value; };
in
{
# Add search.nixos.org as search engines
nix-packages = {
name = "Nix Packages";
urls = [
{
template = "https://search.nixos.org/packages";
params = [
(queryParam "type" "packages")
(queryParam "query" "{searchTerms}")
];
}
];
icon = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg";
definedAliases = [
"@np"
"@nixpackages"
];
};
nixos-options = {
name = "NixOS Options";
urls = [
{
template = "https://search.nixos.org/options";
params = [
(queryParam "type" "packages")
(queryParam "query" "{searchTerms}")
];
}
];
icon = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg";
definedAliases = [
"@no"
"@nixopts"
];
};
nixos-wiki = {
name = "NixOS Wiki";
urls = [
{
template = "https://wiki.nixos.org/w/index.php";
params = [ (queryParam "search" "{searchTerms}") ];
}
];
iconMapObj."16" = "https://wiki.nixos.org/favicon.ico";
definedAliases = [
"@nw"
"@nixwiki"
];
};
# hide bing
bing.metaData.hidden = true;
};
};
};
};
firefox.enable = true;
# Dynamic Menu
fuzzel = {
enable = true;
@ -177,9 +109,7 @@ in
zellij = {
enable = cfg.terminal == "alacritty"; # alacritty has no terminal multiplexer built-in
# Set default shell
settings = {
show_startup_tips = false; # disable the startup tips dialogue
default_shell =
settings.default_shell =
if config.programs.fish.enable then
"fish"
else if config.programs.zsh.enable then
@ -187,7 +117,6 @@ in
else
"bash";
};
};
# PDF reader
zathura.enable = true;
# Auto start sway
@ -219,19 +148,14 @@ in
# Notifications
mako = {
enable = true;
settings = {
layer = "overlay";
border-radius = 8;
default-timeout = 15000;
};
borderRadius = 8;
defaultTimeout = 15000;
};
};
stylix = lib.mkIf config.jhome.styling.enable {
# Set cursor style
inherit cursor;
targets.firefox.profileNames = [ config.home.username ];
};
stylix = lib.mkIf config.jhome.styling.enable { inherit cursor; };
home.pointerCursor = lib.mkIf config.jhome.styling.enable (
lib.mkDefault {
gtk.enable = true;
@ -246,7 +170,10 @@ in
gtk4.extraConfig.gtk-application-prefer-dark-theme = 1;
};
# Set Qt theme
qt = lib.mkIf config.jhome.styling.enable { enable = true; };
qt = lib.mkIf config.jhome.styling.enable {
enable = true;
platformTheme.name = "gtk";
};
xdg.systemDirs.data = [
"/usr/share"

View file

@ -97,6 +97,8 @@ in
input."type:keyboard" = {
repeat_delay = "300";
repeat_rate = "50";
xkb_options = "caps:swapescape,compose:ralt";
xkb_numlock = "enabled";
};
# Touchpad
input."type:touchpad" = {

View file

@ -1,7 +1,8 @@
{ lib, pkgs, ... }@attrs:
let
osConfig = attrs.osConfig or null;
inherit (lib) types;
inherit (import ../lib.nix { inherit lib; }) mkExtraPackagesOption;
osConfig = attrs.osConfig or null;
fromOs =
let
get =
@ -11,22 +12,6 @@ let
path: default: if osConfig == null then default else get path osConfig;
fromConfig = path: default: fromOs ([ "jconfig" ] ++ path) default;
mkExtraPackagesOption =
name: defaultPkgsPath:
let
text = lib.strings.concatMapStringsSep " " (
pkgPath: "pkgs." + (lib.strings.concatStringsSep "." pkgPath)
) defaultPkgsPath;
defaultText = lib.literalExpression "[ ${text} ]";
default = builtins.map (pkgPath: lib.attrsets.getAttrFromPath pkgPath pkgs) defaultPkgsPath;
in
lib.mkOption {
description = "Extra ${name} Packages.";
type = types.listOf types.package;
inherit default defaultText;
example = [ ];
};
identity.options = {
email = lib.mkOption {
description = "Primary email address";

View file

@ -1,7 +1,4 @@
{ lib }:
let
inherit (lib) types;
in
{
# Like mkEnableOption but defaults to true
mkDisableOption =
@ -20,8 +17,31 @@ in
}:
lib.mkOption {
inherit description;
type = types.path;
type = lib.types.path;
default = builtins.fetchurl { inherit url sha256; };
defaultText = lib.literalMD "![${description}](${url})";
};
# Like `lib.mkEnableOption` but default to disabled
mkDisableOption =
desc:
lib.mkEnableOption desc
// {
default = true;
example = false;
};
# Like `lib.mkPackageOption` but for a list of packages.
mkExtraPackagesOption =
name: defaultPkgsPath:
let
text = lib.strings.concatMapStringsSep " " (
pkgPath: "pkgs." + (lib.strings.concatStringsSep "." pkgPath)
) defaultPkgsPath;
in
lib.mkOption {
description = "Extra ${name} Packages.";
type = lib.types.listOf lib.types.package;
default = builtins.map (pkgPath: lib.attrsets.getAttrFromPath pkgPath pkgs) defaultPkgsPath;
defaultText = lib.literalExpression "[ ${text} ]";
example = [ ];
};
}

View file

@ -13,7 +13,6 @@ let
"basedpyright"
"bashls"
"clangd"
"gopls"
# "html" # Not writing html
"jsonls"
"marksman"
@ -45,19 +44,17 @@ in
enable = true;
servers = {
# Pyright needs to have the project root set?
basedpyright.rootMarkers = [
"flake.nix"
".git"
".jj"
"pyproject.toml"
"setup.py"
];
basedpyright.rootDir = # lua
''
function()
return vim.fs.root(0, {'flake.nix', '.git', '.jj', 'pyproject.toml', 'setup.py'})
end
'';
# Big but infrequently used dependencies.
#
# Configure the LSPs, but don't install the packages.
# If you need to use them, add them to your project's devShell
clangd = noPackage;
gopls = noPackage;
zls = noPackage;
};
};
@ -92,18 +89,18 @@ in
})
# Configure Formatters
{
extraPackages = [ pkgs.luajitPackages.jsregexp ];
extraPackages = [
pkgs.luajitPackages.jsregexp
pkgs.shfmt
pkgs.stylua
pkgs.taplo
pkgs.yamlfmt
pkgs.fish
];
plugins.conform-nvim = {
enable = true;
settings = {
formatters = {
fish.command = lib.getExe' pkgs.fish "fish_indent";
nixfmt.command = lib.getExe pkgs.nixfmt-rfc-style;
shfmt.command = lib.getExe pkgs.shfmt;
stylua.command = lib.getExe pkgs.stylua;
taplo.command = lib.getExe pkgs.taplo;
yamlfmt.command = lib.getExe pkgs.yamlfmt;
};
formatters.nixfmt.command = "${lib.getExe pkgs.nixfmt-rfc-style}";
formatters_by_ft = {
"_" = [ "trim_whitespace" ];
c = [ "clang_format" ];
@ -122,13 +119,12 @@ in
}
# Configure Linters
{
extraPackages = [
pkgs.dash
pkgs.statix
];
plugins.lint = {
enable = true;
linters = {
dash.command = lib.getExe pkgs.dash;
statix.command = lib.getExe pkgs.statix;
# chktex = lib.getExe pkgs.chktex; # Not in use
};
lintersByFt = {
# latex = [ "chktex" ]; # Not in use
nix = [ "statix" ];
@ -176,7 +172,6 @@ in
mode = "virtualtext";
};
};
hunk.enable = true;
otter.enable = true;
};
}

View file

@ -1,13 +1,7 @@
{ lib, ... }:
let
inherit (lib) mkEnableOption mkOption types;
mkDisableOption =
desc:
mkEnableOption desc
// {
default = true;
example = false;
};
inherit (import ../lib.nix { inherit lib; }) mkDisableOption;
in
{
options.jhome.nvim = {

View file

@ -1,2 +0,0 @@
source_up
source .venv/bin/activate

View file

@ -1 +1 @@
.venv
/target

View file

@ -1 +0,0 @@
3.13

568
scripts/audiomenu/Cargo.lock generated Normal file
View file

@ -0,0 +1,568 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "addr2line"
version = "0.24.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1"
dependencies = [
"gimli",
]
[[package]]
name = "adler2"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
[[package]]
name = "anstream"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9"
[[package]]
name = "anstyle-parse"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e"
dependencies = [
"anstyle",
"once_cell",
"windows-sys",
]
[[package]]
name = "audiomenu"
version = "0.1.0"
dependencies = [
"clap",
"duct",
"miette",
"serde",
"serde_json",
]
[[package]]
name = "backtrace"
version = "0.3.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a"
dependencies = [
"addr2line",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
"windows-targets",
]
[[package]]
name = "backtrace-ext"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "537beee3be4a18fb023b570f80e3ae28003db9167a751266b259926e25539d50"
dependencies = [
"backtrace",
]
[[package]]
name = "bitflags"
version = "2.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "4.5.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eccb054f56cbd38340b380d4a8e69ef1f02f1af43db2f0cc817a4774d80ae071"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.5.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efd9466fac8543255d3b1fcad4762c5e116ffe808c8a3043d4263cd4fd4862a2"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.5.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09176aae279615badda0765c0c0b3f6ed53f4709118af73cf4655d85d1530cd7"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
[[package]]
name = "colorchoice"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
[[package]]
name = "duct"
version = "0.13.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4ab5718d1224b63252cd0c6f74f6480f9ffeb117438a2e0f5cf6d9a4798929c"
dependencies = [
"libc",
"once_cell",
"os_pipe",
"shared_child",
]
[[package]]
name = "errno"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e"
dependencies = [
"libc",
"windows-sys",
]
[[package]]
name = "gimli"
version = "0.31.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "is_ci"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7655c9839580ee829dfacba1d1278c2b7883e50a277ff7541299489d6bdfdc45"
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
name = "itoa"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]]
name = "libc"
version = "0.2.172"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
[[package]]
name = "linux-raw-sys"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12"
[[package]]
name = "memchr"
version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "miette"
version = "7.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a955165f87b37fd1862df2a59547ac542c77ef6d17c666f619d1ad22dd89484"
dependencies = [
"backtrace",
"backtrace-ext",
"cfg-if",
"miette-derive",
"owo-colors",
"supports-color",
"supports-hyperlinks",
"supports-unicode",
"terminal_size",
"textwrap",
"thiserror",
"unicode-width 0.1.14",
]
[[package]]
name = "miette-derive"
version = "7.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf45bf44ab49be92fd1227a3be6fc6f617f1a337c06af54981048574d8783147"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "miniz_oxide"
version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a"
dependencies = [
"adler2",
]
[[package]]
name = "object"
version = "0.36.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87"
dependencies = [
"memchr",
]
[[package]]
name = "once_cell"
version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "os_pipe"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ffd2b0a5634335b135d5728d84c5e0fd726954b87111f7506a61c502280d982"
dependencies = [
"libc",
"windows-sys",
]
[[package]]
name = "owo-colors"
version = "4.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1036865bb9422d3300cf723f657c2851d0e9ab12567854b1f4eba3d77decf564"
[[package]]
name = "proc-macro2"
version = "1.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rustc-demangle"
version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
[[package]]
name = "rustix"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d97817398dd4bb2e6da002002db259209759911da105da92bec29ccb12cf58bf"
dependencies = [
"bitflags",
"errno",
"libc",
"linux-raw-sys",
"windows-sys",
]
[[package]]
name = "ryu"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
[[package]]
name = "serde"
version = "1.0.219"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.219"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
dependencies = [
"itoa",
"memchr",
"ryu",
"serde",
]
[[package]]
name = "shared_child"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09fa9338aed9a1df411814a5b2252f7cd206c55ae9bf2fa763f8de84603aa60c"
dependencies = [
"libc",
"windows-sys",
]
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "supports-color"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c64fc7232dd8d2e4ac5ce4ef302b1d81e0b80d055b9d77c7c4f51f6aa4c867d6"
dependencies = [
"is_ci",
]
[[package]]
name = "supports-hyperlinks"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "804f44ed3c63152de6a9f90acbea1a110441de43006ea51bcce8f436196a288b"
[[package]]
name = "supports-unicode"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7401a30af6cb5818bb64852270bb722533397edcfc7344954a38f420819ece2"
[[package]]
name = "syn"
version = "2.0.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "terminal_size"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45c6481c4829e4cc63825e62c49186a34538b7b2750b73b266581ffb612fb5ed"
dependencies = [
"rustix",
"windows-sys",
]
[[package]]
name = "textwrap"
version = "0.16.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c13547615a44dc9c452a8a534638acdf07120d4b6847c8178705da06306a3057"
dependencies = [
"unicode-linebreak",
"unicode-width 0.2.0",
]
[[package]]
name = "thiserror"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "unicode-ident"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
[[package]]
name = "unicode-linebreak"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f"
[[package]]
name = "unicode-width"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
[[package]]
name = "unicode-width"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"

View file

@ -0,0 +1,18 @@
[package]
name = "audiomenu"
description = "fuzzel script to select the default audio device for pipewire+wireplumber"
version = "0.1.0"
edition = "2021"
[dependencies]
clap = { version = "4.5.23", features = ["derive", "env"] }
duct = "0.13.7"
miette = { version = "7.4.0", features = ["fancy"] }
serde = { version = "1.0.215", features = ["derive"] }
serde_json = "1.0.133"
[profile.release]
lto = true
opt-level = 's'
panic = "abort"
strip = true

View file

@ -1,238 +0,0 @@
# pyright: strict, reportAny=false
from dataclasses import dataclass
import json
import subprocess
from typing import Self
import typing
import click
def expect[T](type_: type[T], value: object) -> T:
if not isinstance(value, type_):
raise ValueError(
f"expected value to be of type {type_} but was of type {type(value)}"
)
return value
@dataclass(slots=True)
class PWNodeProps:
object_id: int
node_description: str
node_name: str
media_class: str
@classmethod
def from_json(cls, data: dict[str, object]) -> Self:
return cls(
object_id=expect(int, data["object.id"]),
node_description=expect(str, data.get("node.description", "(unknown)")),
node_name=expect(str, data["node.name"]),
media_class=expect(str, data.get("media.class", "(unknown)")),
)
@dataclass(slots=True)
class PWNodeInfo:
props: PWNodeProps
@classmethod
def from_json(cls, data: dict[str, object]) -> Self:
props = typing.cast(dict[str, object], expect(dict, data["props"]))
return cls(PWNodeProps.from_json(props))
@dataclass(slots=True)
class PWNode:
node_type: str
info: PWNodeInfo | None
@classmethod
def from_json(cls, data: dict[str, object]) -> Self:
info = data.get("info", None)
if info is not None:
info = PWNodeInfo.from_json(
typing.cast(dict[str, object], expect(dict, info))
)
return cls(node_type=expect(str, data["type"]), info=info)
@dataclass(slots=True)
class AudioDevice:
id: int
name: str
volume: float
muted: bool
default: bool
@staticmethod
def get_volume(id: int | str) -> tuple[float, bool]:
wpctl_output = subprocess.run(
["wpctl", "get-volume", str(id)],
encoding="UTF-8",
check=True,
capture_output=True,
)
match wpctl_output.stdout.strip().split(sep=" "):
case ["Volume:", value]:
return (float(value), False)
case ["Volume:", value, "[MUTED]"]:
return (float(value), True)
case _:
raise ValueError(f"Unexpected wpctl output: {wpctl_output.stdout}")
@classmethod
def from_pw_node(cls, node: PWNode, default: str) -> Self:
if node.info is None:
raise ValueError(f"Node is not a valid audio device {node}")
id = node.info.props.object_id
volume, muted = cls.get_volume(id)
return cls(
id=id,
name=node.info.props.node_description,
volume=volume,
muted=muted,
default=node.info.props.node_name == default,
)
def menu_item(self) -> str:
id = f"id={self.id:<3}"
if self.default:
id = f"[{id}]"
else:
id = f" {id} "
if self.muted:
return f"{id} {self.volume:>4.0%} [MUTED] {self.name}"
else:
return f"{id} {self.volume:>4.0%} {self.name}"
def get_nodes(data: list[dict[str, object]]) -> list[PWNode]:
def is_audio_node(node: object) -> bool:
if not isinstance(node, dict):
return False
node = typing.cast(dict[str, object], node)
if node["type"] != "PipeWire:Interface:Node":
return False
info = node.get("info", None)
if info is None or not isinstance(info, dict):
return False
info = typing.cast(dict[str, object], info)
props = info.get("props", None)
if props is None or not isinstance(props, dict):
return False
props = typing.cast(dict[str, object], props)
if (media_class := props.get("media.class", None)) is not None:
return isinstance(media_class, str) and media_class.startswith("Audio")
return False
return [
PWNode.from_json(typing.cast(dict[str, object], expect(dict, node)))
for node in data
if is_audio_node(node)
]
def pw_dump() -> list[dict[str, object]]:
dump_output = subprocess.run(
["pw-dump"], encoding="UTF-8", check=True, capture_output=True
)
data = json.loads(dump_output.stdout)
return typing.cast(list[dict[str, object]], expect(list, data))
def get_defaults_metadata(data: list[dict[str, object]]) -> list[dict[str, object]]:
return typing.cast(
list[dict[str, object]],
expect(
list,
next(
node
for node in data
if node["type"] == "PipeWire:Interface:Metadata"
and expect(dict, node["props"])["metadata.name"] == "default"
)["metadata"],
),
)
def get_sinks() -> list[AudioDevice]:
data = pw_dump()
default = next(
typing.cast(dict[str, str], expect(dict, data["value"]))["name"]
for data in get_defaults_metadata(data)
if data["key"] == "default.audio.sink"
)
return [
AudioDevice.from_pw_node(node, default)
for node in get_nodes(data)
if node.info is not None and node.info.props.media_class == "Audio/Sink"
]
def get_sources() -> list[AudioDevice]:
data = pw_dump()
default = next(
typing.cast(dict[str, str], expect(dict, data["value"]))["name"]
for data in get_defaults_metadata(data)
if data["key"] == "default.audio.source"
)
return [
AudioDevice.from_pw_node(node, default)
for node in get_nodes(data)
if node.info is not None and node.info.props.media_class == "Audio/Source"
]
@click.group(name="audiomenu")
def main() -> None:
pass
def select(options: list[str], prompt: str) -> int | None:
menu_output = subprocess.run(
["fuzzel", "--dmenu", f"--prompt={prompt}"],
input="\n".join(options),
encoding="UTF-8",
capture_output=True,
)
if menu_output.returncode == 2:
return None
menu_output.check_returncode()
selected = menu_output.stdout.rstrip()
return options.index(selected)
@main.command()
def select_sink() -> None:
devices = get_sinks()
selected = select([device.menu_item() for device in devices], prompt="Select Sink>")
if selected is None:
click.echo("No sink selected")
return
device = devices[selected]
_ = subprocess.run(["wpctl", "set-default", str(device.id)], check=True)
@main.command()
def select_source() -> None:
devices = get_sources()
selected = select(
[device.menu_item() for device in devices], prompt="Select Source>"
)
if selected is None:
click.echo("No source selected")
return
device = devices[selected]
_ = subprocess.run(["wpctl", "set-default", str(device.id)], check=True)
if __name__ == "__main__":
main()

View file

@ -1,9 +1,40 @@
{ writers, python3Packages }:
writers.writePython3Bin "audiomenu" {
libraries = [ python3Packages.click ];
flakeIgnore = [
"E501" # line too long, but I like my code well documented
"W503" # line break before binary operator, ruff does this, I trust it
{ lib, rustPlatform }:
let
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
inherit (cargoToml.package) name version description;
pname = name;
src = lib.cleanSourceWith {
src = ./.;
name = "${pname}-source";
# Adapted from <https://github.com/ipetkov/crane/blob/master/lib/filterCargoSources.nix>
# no need to pull in crane for just this
filter =
orig_path: type:
let
path = toString orig_path;
base = baseNameOf path;
parentDir = baseNameOf (dirOf path);
matchesSuffix = lib.any (suffix: lib.hasSuffix suffix base) [
# Rust sources
".rs"
# TOML files are often used to configure cargo based tools (e.g. .cargo/config.toml)
".toml"
];
} ./audiomenu.py
isCargoLock = base == "Cargo.lock";
# .cargo/config.toml is captured above
isOldStyleCargoConfig = parentDir == ".cargo" && base == "config";
in
type == "directory" || matchesSuffix || isCargoLock || isOldStyleCargoConfig;
};
in
rustPlatform.buildRustPackage {
inherit pname version src;
cargoLock.lockFile = ./Cargo.lock;
useNextest = true;
meta = {
inherit description;
license = lib.licenses.mit;
homepage = "https://github.com/jalil-salame/configuration.nix";
mainProgram = name;
};
}

View file

@ -1,9 +0,0 @@
[project]
name = "audiomenu"
version = "0.1.0"
description = "fuzzel script to select the default audio device for pipewire+wireplumber"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"click>=8.1.7",
]

View file

@ -0,0 +1,231 @@
use std::{
fmt::{Display, Write as _},
io::{Read, Write as _},
process::{Command, Stdio},
};
use clap::Parser;
use duct::cmd;
use miette::{bail, Context, IntoDiagnostic, Result};
use serde::Deserialize;
fn main() -> Result<()> {
miette::set_panic_hook();
Opts::parse().run()
}
/// fuzzel script to select the default audio device for pipewire+wireplumber
#[derive(Debug, Parser)]
struct Opts {
#[clap(subcommand)]
cmd: Cmd,
}
impl Opts {
fn run(self) -> Result<()> {
self.cmd.run()
}
}
#[derive(Debug, clap::Subcommand)]
enum Cmd {
/// Select audio sink (speakers/headphones)
SelectSink,
/// Select audio source (microphone)
SelectSource,
}
impl Cmd {
fn run(self) -> Result<()> {
let id = match self {
Cmd::SelectSink => {
let devices = get_sinks().wrap_err("failed to get sinks")?;
let selected = select(
devices.iter().map(|dev| dev.name.as_ref()),
Some("Select input>"),
)
.wrap_err("failed to select a default sink")?;
if selected.is_empty() {
eprintln!("did not select a device");
return Ok(());
}
let Some(dev) = devices.into_iter().find(|dev| dev.name == selected) else {
bail!("couldn't find a device matching `{selected}`");
};
dev.id
}
Cmd::SelectSource => {
let devices = get_sources().wrap_err("failed to get sinks")?;
let selected = select(
devices.iter().map(|dev| dev.name.as_ref()),
Some("Select output>"),
)
.wrap_err("failed to select a default source")?;
if selected.is_empty() {
eprintln!("did not select a device");
return Ok(());
}
let Some(dev) = devices.into_iter().find(|dev| dev.name == selected) else {
bail!("couldn't find a device matching `{selected}`");
};
dev.id
}
};
cmd!("wpctl", "set-default", id.to_string())
.run()
.map(drop)
.into_diagnostic()
.wrap_err("failed to set default input")
}
}
#[derive(Debug, Deserialize)]
struct PWNode {
#[serde(rename = "type")]
node_type: Box<str>,
#[serde(default)]
info: PWNodeInfo,
// json ignores the rest of the fields by default
}
#[derive(Debug, Deserialize, Default)]
struct PWNodeInfo {
props: PWNodeProps,
// json ignores the rest of the fields by default
}
#[derive(Debug, Deserialize, Default)]
struct PWNodeProps {
#[serde(rename = "object.id")]
object_id: u32,
#[serde(rename = "node.description", default)]
node_description: Box<str>,
#[serde(rename = "media.class", default)]
media_class: Box<str>,
// json ignores the rest of the fields by default
}
struct AudioDevice<S> {
id: u32,
name: Box<str>,
_side: S,
}
/// Output (e.g. speakers)
struct AudioSink;
/// Input (e.g. microphone)
struct AudioSource;
fn get_sinks() -> Result<Vec<AudioDevice<AudioSink>>> {
get_devices()
}
fn get_sources() -> Result<Vec<AudioDevice<AudioSource>>> {
get_devices()
}
fn get_devices<S>() -> Result<Vec<AudioDevice<S>>>
where
AudioDevice<S>: TryFrom<PWNode>,
{
Ok(get_nodes()?
.into_iter()
.filter_map(|node| AudioDevice::<S>::try_from(node).ok())
.collect())
}
impl TryFrom<PWNode> for AudioDevice<AudioSource> {
type Error = miette::Report;
fn try_from(value: PWNode) -> std::result::Result<Self, Self::Error> {
if value.node_type.as_ref() != "PipeWire:Interface:Node" {
bail!(
"invalid type: `{}`, expected `PipeWire:Interface:Node`",
value.node_type
)
}
let class = value.info.props.media_class;
match class.as_ref() {
"Audio/Source" => Ok(Self {
id: value.info.props.object_id,
name: value.info.props.node_description,
_side: AudioSource,
}),
_ => bail!("invalid media.class: `{class}`, expected `Audio/Source`"),
}
}
}
impl TryFrom<PWNode> for AudioDevice<AudioSink> {
type Error = miette::Report;
fn try_from(value: PWNode) -> std::result::Result<Self, Self::Error> {
if value.node_type.as_ref() != "PipeWire:Interface:Node" {
bail!(
"invalid type: `{}`, expected `PipeWire:Interface:Node`",
value.node_type
)
}
let class = value.info.props.media_class;
match class.as_ref() {
"Audio/Sink" => Ok(Self {
id: value.info.props.object_id,
name: value.info.props.node_description,
_side: AudioSink,
}),
_ => bail!("invalid media.class: `{class}`, expected `Audio/Sink`"),
}
}
}
fn get_nodes() -> Result<Vec<PWNode>> {
let dump = cmd!("pw-dump")
.read()
.into_diagnostic()
.wrap_err("failed to get devices with pw-dump")?;
serde_json::from_str(&dump)
.into_diagnostic()
.wrap_err("failed to parse pw-dump output")
}
fn select<T, It>(options: It, prompt: Option<&str>) -> Result<Box<str>>
where
T: Display,
It: IntoIterator<Item = T>,
{
let append_line = |mut s: String, it| {
writeln!(s, "{it}").unwrap();
s
};
let options = options.into_iter().fold(String::new(), append_line);
let mut menu = Command::new("fuzzel");
menu.arg("--dmenu");
if let Some(prompt) = prompt {
menu.arg(format!("--prompt={prompt}"));
}
Ok(pipe_to_stdin_and_return_stdout(&mut menu, options)?
.trim()
.into())
}
fn pipe_to_stdin_and_return_stdout(cmd: &mut Command, data: impl Display) -> Result<String> {
let mut child = cmd
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.into_diagnostic()
.wrap_err_with(|| format!("failed to run {cmd:?}"))?;
let mut stdin = child.stdin.take().expect("stdin not piped");
write!(stdin, "{data}")
.into_diagnostic()
.wrap_err("failed to send data to process' stdin")?;
drop(stdin);
let mut stdout = child.stdout.take().expect("stdout not piped");
let mut buf = String::new();
stdout
.read_to_string(&mut buf)
.into_diagnostic()
.wrap_err("failed to retrieve output from process")?;
Ok(buf)
}

View file

@ -1,17 +1,37 @@
{ lib, ... }:
let
packages = pkgs: {
jpassmenu = pkgs.callPackage ./jpassmenu/package.nix { };
audiomenu = pkgs.callPackage ./audiomenu/package.nix { };
src = ./.;
# Autodetects files with a package.nix and calls `callPackage` on them.
#
# Will add a package .#dirname to the flake if it finds a ./dirname/package.nix file.
files = builtins.readDir src;
isPackage = path: type: (type == "directory") && (builtins.readDir path) ? "package.nix";
toPackage = name: pkgs: {
inherit name;
value = pkgs.callPackage "${src}/${name}/package.nix" { };
};
# call pkgs.callPackage on all ./*/package.nix
makePackage =
pkgs: name:
let
type = files.${name};
path = "${src}/${name}";
package = toPackage name pkgs;
in
# if it is a package then return a package otherwise return no package c:
if isPackage path type then [ package ] else [ ];
# we have lib.filterMapAttrs at home
scripts =
pkgs: builtins.listToAttrs (builtins.concatMap (makePackage pkgs) (builtins.attrNames files));
in
{
# Add scripts to overlay
flake.overlays.scripts = _final: packages;
flake.overlays.scripts = final: scripts;
# Add scripts to packages
perSystem =
{ pkgs, ... }:
{
packages = packages pkgs;
packages = scripts pkgs;
};
}

View file

@ -1,2 +0,0 @@
source_up
source .venv/bin/activate

1
scripts/jpassmenu/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

View file

@ -1 +0,0 @@
3.13

743
scripts/jpassmenu/Cargo.lock generated Normal file
View file

@ -0,0 +1,743 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "addr2line"
version = "0.24.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1"
dependencies = [
"gimli",
]
[[package]]
name = "adler2"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
[[package]]
name = "aho-corasick"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
dependencies = [
"memchr",
]
[[package]]
name = "anstream"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9"
[[package]]
name = "anstyle-parse"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e"
dependencies = [
"anstyle",
"once_cell",
"windows-sys",
]
[[package]]
name = "backtrace"
version = "0.3.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a"
dependencies = [
"addr2line",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
"windows-targets",
]
[[package]]
name = "backtrace-ext"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "537beee3be4a18fb023b570f80e3ae28003db9167a751266b259926e25539d50"
dependencies = [
"backtrace",
]
[[package]]
name = "bitflags"
version = "2.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd"
[[package]]
name = "bstr"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "234113d19d0d7d613b40e86fb654acf958910802bcceab913a4f9e7cda03b1a4"
dependencies = [
"memchr",
"serde",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "4.5.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eccb054f56cbd38340b380d4a8e69ef1f02f1af43db2f0cc817a4774d80ae071"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.5.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efd9466fac8543255d3b1fcad4762c5e116ffe808c8a3043d4263cd4fd4862a2"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.5.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09176aae279615badda0765c0c0b3f6ed53f4709118af73cf4655d85d1530cd7"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
[[package]]
name = "colorchoice"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
[[package]]
name = "crossbeam-deque"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51"
dependencies = [
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
[[package]]
name = "duct"
version = "0.13.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4ab5718d1224b63252cd0c6f74f6480f9ffeb117438a2e0f5cf6d9a4798929c"
dependencies = [
"libc",
"once_cell",
"os_pipe",
"shared_child",
]
[[package]]
name = "env_filter"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0"
dependencies = [
"log",
"regex",
]
[[package]]
name = "env_logger"
version = "0.11.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13c863f0904021b108aa8b2f55046443e6b1ebde8fd4a15c399893aae4fa069f"
dependencies = [
"anstream",
"anstyle",
"env_filter",
"jiff",
"log",
]
[[package]]
name = "errno"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e"
dependencies = [
"libc",
"windows-sys",
]
[[package]]
name = "gimli"
version = "0.31.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
[[package]]
name = "globset"
version = "0.4.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54a1028dfc5f5df5da8a56a73e6c153c9a9708ec57232470703592a3f18e49f5"
dependencies = [
"aho-corasick",
"bstr",
"log",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "ignore"
version = "0.4.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d89fd380afde86567dfba715db065673989d6253f42b88179abd3eae47bda4b"
dependencies = [
"crossbeam-deque",
"globset",
"log",
"memchr",
"regex-automata",
"same-file",
"walkdir",
"winapi-util",
]
[[package]]
name = "is_ci"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7655c9839580ee829dfacba1d1278c2b7883e50a277ff7541299489d6bdfdc45"
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
name = "jiff"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59ec30f7142be6fe14e1b021f50b85db8df2d4324ea6e91ec3e5dcde092021d0"
dependencies = [
"jiff-static",
"log",
"portable-atomic",
"portable-atomic-util",
"serde",
]
[[package]]
name = "jiff-static"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "526b834d727fd59d37b076b0c3236d9adde1b1729a4361e20b2026f738cc1dbe"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "jpassmenu"
version = "0.1.0"
dependencies = [
"clap",
"duct",
"env_logger",
"ignore",
"log",
"miette",
]
[[package]]
name = "libc"
version = "0.2.172"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
[[package]]
name = "linux-raw-sys"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12"
[[package]]
name = "log"
version = "0.4.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
[[package]]
name = "memchr"
version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "miette"
version = "7.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a955165f87b37fd1862df2a59547ac542c77ef6d17c666f619d1ad22dd89484"
dependencies = [
"backtrace",
"backtrace-ext",
"cfg-if",
"miette-derive",
"owo-colors",
"supports-color",
"supports-hyperlinks",
"supports-unicode",
"terminal_size",
"textwrap",
"thiserror",
"unicode-width 0.1.14",
]
[[package]]
name = "miette-derive"
version = "7.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf45bf44ab49be92fd1227a3be6fc6f617f1a337c06af54981048574d8783147"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "miniz_oxide"
version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a"
dependencies = [
"adler2",
]
[[package]]
name = "object"
version = "0.36.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87"
dependencies = [
"memchr",
]
[[package]]
name = "once_cell"
version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "os_pipe"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ffd2b0a5634335b135d5728d84c5e0fd726954b87111f7506a61c502280d982"
dependencies = [
"libc",
"windows-sys",
]
[[package]]
name = "owo-colors"
version = "4.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1036865bb9422d3300cf723f657c2851d0e9ab12567854b1f4eba3d77decf564"
[[package]]
name = "portable-atomic"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e"
[[package]]
name = "portable-atomic-util"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507"
dependencies = [
"portable-atomic",
]
[[package]]
name = "proc-macro2"
version = "1.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [
"proc-macro2",
]
[[package]]
name = "regex"
version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
[[package]]
name = "rustc-demangle"
version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
[[package]]
name = "rustix"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d97817398dd4bb2e6da002002db259209759911da105da92bec29ccb12cf58bf"
dependencies = [
"bitflags",
"errno",
"libc",
"linux-raw-sys",
"windows-sys",
]
[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
[[package]]
name = "serde"
version = "1.0.219"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.219"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "shared_child"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09fa9338aed9a1df411814a5b2252f7cd206c55ae9bf2fa763f8de84603aa60c"
dependencies = [
"libc",
"windows-sys",
]
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "supports-color"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c64fc7232dd8d2e4ac5ce4ef302b1d81e0b80d055b9d77c7c4f51f6aa4c867d6"
dependencies = [
"is_ci",
]
[[package]]
name = "supports-hyperlinks"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "804f44ed3c63152de6a9f90acbea1a110441de43006ea51bcce8f436196a288b"
[[package]]
name = "supports-unicode"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7401a30af6cb5818bb64852270bb722533397edcfc7344954a38f420819ece2"
[[package]]
name = "syn"
version = "2.0.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "terminal_size"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45c6481c4829e4cc63825e62c49186a34538b7b2750b73b266581ffb612fb5ed"
dependencies = [
"rustix",
"windows-sys",
]
[[package]]
name = "textwrap"
version = "0.16.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c13547615a44dc9c452a8a534638acdf07120d4b6847c8178705da06306a3057"
dependencies = [
"unicode-linebreak",
"unicode-width 0.2.0",
]
[[package]]
name = "thiserror"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "unicode-ident"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
[[package]]
name = "unicode-linebreak"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f"
[[package]]
name = "unicode-width"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
[[package]]
name = "unicode-width"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "walkdir"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
dependencies = [
"same-file",
"winapi-util",
]
[[package]]
name = "winapi-util"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [
"windows-sys",
]
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"

View file

@ -0,0 +1,19 @@
[package]
name = "jpassmenu"
description = "A simple program that uses dmenu compatible menu to select a password to type/copy"
version = "0.1.0"
edition = "2021"
[dependencies]
clap = { version = "4.5.23", features = ["derive", "env"] }
duct = "0.13.7"
env_logger = "0.11.5"
ignore = "0.4.23"
log = "0.4.22"
miette = { version = "7.4.0", features = ["fancy"] }
[profile.release]
lto = true
opt-level = "s"
panic = "abort"
strip = true

View file

@ -1,3 +0,0 @@
# jpassmenu
My own implementation of the `passmenu` `dmenu` script, this one uses `fuzzel` by default and types passwords with `ydotool`.

View file

@ -1,111 +0,0 @@
from os import environ
from pathlib import Path
import subprocess
import click
def select(options: list[str]) -> int | None:
menu_output = subprocess.run(
["fuzzel", "--dmenu"],
input="\n".join(options),
encoding="UTF-8",
capture_output=True,
)
if menu_output.returncode == 2:
return None
menu_output.check_returncode()
selected = menu_output.stdout.rstrip()
return options.index(selected)
@click.command(
"jpassmenu", context_settings={"show_default": True, "max_content_width": 120}
)
@click.option(
"--type",
"typeit",
help="Type the password using ydotool instead of copying it to the clipboard",
)
@click.option(
"--store-dir",
type=click.Path(exists=True, file_okay=False, path_type=Path),
envvar="PASSWORD_STORE_DIR",
default=Path("~/.password-store"),
)
@click.option(
"--pass-bin",
default="pass",
help="Path to the pass binary\n\nNeeds to support `pass show` and `pass show --clip`",
)
@click.option(
"--menu-bin", default="fuzzel", help="Path to the dmenu compatible menu binary"
)
@click.argument("menu_args", nargs=-1)
def main(
typeit: bool, store_dir: Path, pass_bin: str, menu_bin: str, menu_args: list[str]
) -> None:
menu_args = (
["--dmenu"] if not menu_args and menu_bin.endswith("fuzzel") else menu_args
)
store_dir = store_dir.expanduser().absolute()
# Get all files in store_dir
secrets = (
dirpath / fname
for dirpath, _dirnames, filenames in store_dir.walk()
for fname in filenames
)
# Filter for files ending in .gpg and strip the extension
secrets = (
secret.with_suffix("")
for secret in secrets
if secret.is_file() and secret.suffix == ".gpg"
)
# Make the paths relative to store_dir and turn to strings
secrets = sorted(str(secret.relative_to(store_dir)) for secret in secrets)
if not secrets:
click.secho(f"No valid entries found in {store_dir}", err=True, fg="red")
selected = select(secrets)
if selected is None:
click.echo("No secret selected")
return
selected = secrets[selected]
# If PASSWORD_STORE_DIR and --store-dir disagree, set PASSWORD_STORE_DIR to --store-dir
env_store = (
Path(environ.get("PASSWORD_STORE_DIR", default="~/.password-store"))
.expanduser()
.absolute()
)
if store_dir != env_store:
environ["PASSWORD_STORE_DIR"] = str(store_dir)
pass_cmd = (
[pass_bin, "show", selected]
if typeit
else [pass_bin, "show", "--clip", selected]
)
pass_output = subprocess.run(
pass_cmd,
encoding="UTF-8",
check=True,
capture_output=typeit,
)
if not typeit:
return
pass_entry = pass_output.stdout
secret = pass_entry.splitlines()[0].strip()
_ = subprocess.run(
["ydotool", "type", "--file", "-"],
input=secret,
encoding="UTF-8",
check=True,
)
if __name__ == "__main__":
main()

View file

@ -1,6 +1,40 @@
{ writers, python3Packages }:
writers.writePython3Bin "jpassmenu" {
libraries = [ python3Packages.click ];
# line too long, but I like my code well documented
flakeIgnore = [ "E501" ];
} ./jpassmenu.py
{ lib, rustPlatform }:
let
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
inherit (cargoToml.package) name version description;
pname = name;
src = lib.cleanSourceWith {
src = ./.;
name = "${pname}-source";
# Adapted from <https://github.com/ipetkov/crane/blob/master/lib/filterCargoSources.nix>
# no need to pull in crane for just this
filter =
orig_path: type:
let
path = toString orig_path;
base = baseNameOf path;
parentDir = baseNameOf (dirOf path);
matchesSuffix = lib.any (suffix: lib.hasSuffix suffix base) [
# Rust sources
".rs"
# TOML files are often used to configure cargo based tools (e.g. .cargo/config.toml)
".toml"
];
isCargoLock = base == "Cargo.lock";
# .cargo/config.toml is captured above
isOldStyleCargoConfig = parentDir == ".cargo" && base == "config";
in
type == "directory" || matchesSuffix || isCargoLock || isOldStyleCargoConfig;
};
in
rustPlatform.buildRustPackage {
inherit pname version src;
cargoLock.lockFile = ./Cargo.lock;
useNextest = true;
meta = {
inherit description;
license = lib.licenses.mit;
homepage = "https://github.com/jalil-salame/configuration.nix";
mainProgram = name;
};
}

View file

@ -1,9 +0,0 @@
[project]
name = "jpassmenu"
version = "0.1.0"
description = "A simple program that uses dmenu compatible menu to select a password to type/copy"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"click>=8.1.7",
]

View file

@ -0,0 +1,156 @@
use std::{
ffi::OsStr,
fmt::Write as _,
path::{Path, PathBuf},
};
use clap::Parser;
use duct::cmd;
use miette::{bail, ensure, Context, IntoDiagnostic, Result};
fn main() -> Result<()> {
miette::set_panic_hook();
env_logger::builder()
.filter_level(log::LevelFilter::Info)
.parse_default_env()
.try_init()
.into_diagnostic()?;
Opts::parse().run()
}
impl Opts {
fn run(self) -> Result<()> {
log::debug!("parsed opts {self:?}");
let Self {
typeit,
store_dir,
pass_bin,
menu_bin,
menu_args,
} = self;
let store_dir = resolve_home(store_dir);
// Search paths
log::info!("looking for entries in {}", store_dir.display());
let mut paths = ignore::Walk::new(&store_dir)
.filter_map(|entry| {
let entry = entry.ok()?;
if entry.file_type()?.is_file()
&& entry.path().extension() == Some(OsStr::new("gpg"))
{
let path = entry.path();
Some(
path.strip_prefix(&store_dir)
.unwrap_or(path)
.with_extension("")
.into_boxed_path(),
)
} else {
None
}
})
.collect::<Vec<Box<Path>>>();
paths.sort_unstable();
ensure!(
!paths.is_empty(),
"failed to find entries in {}",
store_dir.display()
);
log::debug!("found entries: {paths:#?}");
// Concatenate all paths
let paths = paths
.into_iter()
.try_fold(String::new(), |mut acc, it| {
writeln!(acc, "{}", it.display()).map(|_| acc)
})
.into_diagnostic()
.wrap_err("preparing paths")?;
// Show dynamic menu
let selected = cmd(menu_bin, menu_args)
.stdin_bytes(paths.as_bytes())
.read()
.into_diagnostic()
.wrap_err("failed to run menu and retrieve the selected entry")?;
let selected = selected.trim();
if selected.is_empty() {
bail!("no password entry selected");
}
// Prepare env dir
let env_store = std::env::var_os("PASSWORD_STORE_DIR");
let set_env = if let Some(env_store) = env_store {
if store_dir != env_store {
Some(store_dir)
} else {
None
}
} else if store_dir == Path::new("~/.password-store") {
None
} else {
Some(store_dir)
};
// Prepare pass command
let args = if typeit {
vec!["show", selected]
} else {
vec!["show", "-c", selected]
};
let pass = cmd(pass_bin, args);
let pass = if let Some(env) = set_env {
pass.env("PASSWORD_STORE_DIR", env)
} else {
pass
};
// Copy password to clipboard
if !typeit {
pass.run()
.into_diagnostic()
.wrap_err("failed to copy password to clipboard")?;
return Ok(());
}
// Retrieve password
let pass_entry = pass
.read()
.into_diagnostic()
.wrap_err("failed to retrieve password")?;
let Some(password) = pass_entry.lines().next() else {
bail!("failed to retrieve password or entry was empty");
};
// Type password with ydotool
cmd("ydotool", &["type", "--file", "-"])
.stdin_bytes(password.as_bytes())
.run()
.into_diagnostic()
.wrap_err("failed to type password with ydotool")?;
Ok(())
}
}
#[derive(Debug, Parser)]
struct Opts {
/// Type the password instead of copying it to the clipboard
#[arg(long("type"))]
typeit: bool,
#[arg(long, env("PASSWORD_STORE_DIR"), default_value = "~/.password-store")]
store_dir: PathBuf,
/// Path to the pass binary
///
/// Needs to support `pass show` and `pass show -c`
#[arg(long, default_value = "pass")]
pass_bin: String,
/// Path to the dynamic menu binary
#[arg(long, default_value = "fuzzel")]
menu_bin: String,
/// Args to the dynamic menu
#[arg(long, default_value = "--dmenu")]
menu_args: Vec<String>,
}
fn resolve_home(path: PathBuf) -> PathBuf {
if let Ok(path) = path.strip_prefix("~") {
if let Some(home) = std::env::var_os("HOME") {
let mut home = PathBuf::from(home);
home.push(path);
return home;
}
}
path
}