q.sh/flake.nix
2024-09-09 02:03:52 +01:00

73 lines
2.3 KiB
Nix

{
description = "Nix q.sh dev environment";
# Flake inputs
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
};
# Flake outputs
outputs = { self, nixpkgs }:
let
# Systems supported
allSystems = [
"x86_64-linux" # 64-bit Intel/AMD Linux
"aarch64-linux" # 64-bit ARM Linux
"x86_64-darwin" # 64-bit Intel macOS
"aarch64-darwin" # 64-bit ARM macOS
];
# Helper to provide system-specific attributes
forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
pkgs = import nixpkgs { inherit system; };
});
make_package = pkgs: pkgs.stdenv.mkDerivation {
name = "q-sh";
src = self;
installPhase = ''
mkdir -p $out/bin
cp q $out/bin
cp q-* $out/bin
echo "OUT " $out
'';
postFixup = ''
q-fixup() {
TOOL="$1"
PATH="$2"
${pkgs.findutils}/bin/find $out -type f -name 'q*' -exec ${pkgs.gnused}/bin/sed -i "s#ENV_$TOOL=.*#ENV_$TOOL=$PATH#g" {} +
}
q-fixup "fzf" "${pkgs.fzf}/bin/fzf"
q-fixup "find" "${pkgs.findutils}/bin/find"
q-fixup "sed" "${pkgs.gnused}/bin/sed"
q-fixup "awk" "${pkgs.gawk}/bin/awk"
q-fixup "bc" "${pkgs.bc}/bin/bc"
q-fixup "pass" "${pkgs.pass}/bin/pass"
q-fixup "cut" "${pkgs.coreutils}/bin/cut"
q-fixup "base64" "${pkgs.coreutils}/bin/base64"
q-fixup "cat" "${pkgs.coreutils}/bin/cat"
q-fixup "tac" "${pkgs.coreutils}/bin/tac"
q-fixup "sort" "${pkgs.coreutils}/bin/sort"
q-fixup "uniq" "${pkgs.coreutils}/bin/uniq"
q-fixup "wl_copy" "${pkgs.wl-clipboard}/bin/wl-copy"
q-fixup "xdg_open" "${pkgs.xdg-utils}/bin/xdg-open"
q-fixup "q" "$out/bin"
'';
};
in
{
devShells = forAllSystems ({ pkgs }: {
default = pkgs.mkShell {
packages = with pkgs; [
fzf
pass
bc
wl-clipboard
xdg-utils
];
};
});
packages = forAllSystems({ pkgs }: {"q-sh" = make_package pkgs;});
};
}