quadshell/flake.nix

73 lines
2.8 KiB
Nix

{
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
outputs =
{ self, nixpkgs, ... }:
let
forAllSystems = nixpkgs.lib.genAttrs [
"x86_64-linux"
"aarch64-linux"
];
in
{
overlays.default = final: prev: {
quadshell = final.callPackage ./package.nix { };
};
packages = forAllSystems (system: {
default = (nixpkgs.legacyPackages.${system}.extend self.overlays.default).quadshell;
});
apps = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
# Just the path, the phone should already have it, so this machine doesn't need it
quickshell = builtins.unsafeDiscardStringContext (
nixpkgs.lib.getExe nixpkgs.legacyPackages.aarch64-linux.quickshell
);
# This one isn't in the cache, so its derivation is copied over and the phone builds it
locationAgent =
(nixpkgs.legacyPackages.aarch64-linux.extend self.overlays.default).quadshell.locationAgent;
agentDrv = builtins.unsafeDiscardOutputDependency locationAgent.drvPath;
agentBin = "${builtins.unsafeDiscardStringContext locationAgent.outPath}/bin";
in
{
# nix run .#phone [host]: runs the shell on the phone until Ctrl+C.
phone = {
type = "app";
program = nixpkgs.lib.getExe (
pkgs.writeShellApplication {
name = "quadshell-phone";
runtimeInputs = [
pkgs.openssh
pkgs.gnutar
];
text = ''
host=''${1:-phone}
dest=.cache/quadshell-dev
mapfile -t inputs < <(nix-store --query --references ${agentDrv} | grep '\.drv$')
nix-store --realise "''${inputs[@]}" >/dev/null
nix copy --derivation --to "ssh-ng://$host" ${agentDrv}
nix copy --to "ssh-ng://$host" "''${inputs[@]/%/^*}"
# The store's files are read-only, which would stop the next run replacing them
# shellcheck disable=SC2029
tar -C ${self}/src --mode=u+w -c . | ssh "$host" "rm -rf $dest; mkdir -p $dest; tar -C $dest -x"
# shellcheck disable=SC2029
exec ssh -t "$host" "
nix-store --realise ${builtins.dirOf (builtins.dirOf quickshell)} >/dev/null;
nix-store --realise --option substitute false ${agentDrv} >/dev/null;
pkill -f '^/nix/store/[^ ]*/bin/quickshell ';
exec systemd-run --user --pty --quiet --collect --setenv=PATH=${agentBin}:\"\$PATH\" ${quickshell} --path ~/$dest
"
'';
}
);
};
}
);
};
}