ocd/flake.nix
2025-12-03 22:46:21 +07:00

52 lines
2 KiB
Nix

{
description = "Provides containerized opencode";
outputs = inputs@{ ... }: {
flakeModule = { self, lib, flake-parts-lib, ... }:
let
inherit (flake-parts-lib) mkPerSystemOption;
inherit (lib) mkOption mkEnableOption types;
in {
options.perSystem = mkPerSystemOption ({ pkgs, system, ...}: {
options.ocd = {
enable = mkEnableOption "Containerized opencode";
ocUrl = mkOption {
type = types.str;
default = "https://registry.npmjs.org/opencode-linux-x64/-/opencode-linux-x64-1.0.129.tgz";
description = "URL of the opencode tarball";
};
ocSha256 = mkOption {
type = types.str;
default = "sha256:0md8iq7fk6nr3qfbljzyghnz1v0hqqjsmdwp1icql7l1a8nfa09z";
description = "SHA256 hash of the opencode tarball";
};
withPackages = mkOption {
type = types.functionTo (types.listOf types.package);
default = p: [];
description = "Extra packages to include in the container";
example = lib.literalExpression "p: [ p.tmux ]";
};
};
});
config = {
perSystem = { config, pkgs, system, ...}:
lib.mkIf config.ocd.enable {
devShells.default = pkgs.mkShell {
shellHook = ''
set -v
alias ocd-init='$(nix build .#ocd --print-out-paths) | docker load'
alias ocd-start='docker run -it --rm -v $(pwd):/workspace -v $(pwd)/.oc-local:/root/.local/share/opencode --network host ocd:latest'
set +v
echo 'ocd-init needs to be ran once (or on image change)'
'';
};
packages.ocd = pkgs.callPackage ./image.nix {
inherit (config.ocd) withPackages ocUrl ocSha256;
};
};
};
};
};
}