Initial commit
This commit is contained in:
commit
8bfb2256f8
7 changed files with 239 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
.emacs*
|
||||
result
|
||||
.oc-local
|
||||
1
example/AGENTS.md
Normal file
1
example/AGENTS.md
Normal file
|
|
@ -0,0 +1 @@
|
|||
If you read this, say "I'm running in a container like a good boy should"
|
||||
123
example/flake.lock
generated
Normal file
123
example/flake.lock
generated
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-parts": {
|
||||
"inputs": {
|
||||
"nixpkgs-lib": "nixpkgs-lib"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1763759067,
|
||||
"narHash": "sha256-LlLt2Jo/gMNYAwOgdRQBrsRoOz7BPRkzvNaI/fzXi2Q=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"rev": "2cccadc7357c0ba201788ae99c4dfa90728ef5e0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-parts_2": {
|
||||
"inputs": {
|
||||
"nixpkgs-lib": "nixpkgs-lib_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1763759067,
|
||||
"narHash": "sha256-LlLt2Jo/gMNYAwOgdRQBrsRoOz7BPRkzvNaI/fzXi2Q=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"rev": "2cccadc7357c0ba201788ae99c4dfa90728ef5e0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "flake-parts",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1764517877,
|
||||
"narHash": "sha256-pp3uT4hHijIC8JUK5MEqeAWmParJrgBVzHLNfJDZxg4=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "2d293cbfa5a793b4c50d17c05ef9e385b90edf6c",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-lib": {
|
||||
"locked": {
|
||||
"lastModified": 1761765539,
|
||||
"narHash": "sha256-b0yj6kfvO8ApcSE+QmA6mUfu8IYG6/uU28OFn4PaC8M=",
|
||||
"owner": "nix-community",
|
||||
"repo": "nixpkgs.lib",
|
||||
"rev": "719359f4562934ae99f5443f20aa06c2ffff91fc",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "nixpkgs.lib",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-lib_2": {
|
||||
"locked": {
|
||||
"lastModified": 1761765539,
|
||||
"narHash": "sha256-b0yj6kfvO8ApcSE+QmA6mUfu8IYG6/uU28OFn4PaC8M=",
|
||||
"owner": "nix-community",
|
||||
"repo": "nixpkgs.lib",
|
||||
"rev": "719359f4562934ae99f5443f20aa06c2ffff91fc",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "nixpkgs.lib",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1764642553,
|
||||
"narHash": "sha256-mvbFFzVBhVK1FjyPHZGMAKpNiqkr7k++xIwy+p/NQvA=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "f720de59066162ee879adcc8c79e15c51fe6bfb4",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"ocd": {
|
||||
"inputs": {
|
||||
"flake-parts": "flake-parts_2",
|
||||
"nixpkgs": "nixpkgs_2"
|
||||
},
|
||||
"locked": {
|
||||
"path": "../",
|
||||
"type": "path"
|
||||
},
|
||||
"original": {
|
||||
"path": "../",
|
||||
"type": "path"
|
||||
},
|
||||
"parent": []
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-parts": "flake-parts",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"ocd": "ocd"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
23
example/flake.nix
Normal file
23
example/flake.nix
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
description = "Usage example";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||
# replace with "github:voleum-org/ocd"
|
||||
ocd.url = "path:../";
|
||||
};
|
||||
|
||||
outputs = inputs@{ flake-parts, ocd, ...}:
|
||||
flake-parts.lib.mkFlake { inherit inputs; } {
|
||||
imports = [
|
||||
ocd.flakeModule
|
||||
];
|
||||
|
||||
systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
|
||||
|
||||
perSystem = { config, pkgs, ... }: {
|
||||
ocd.enable = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
7
flake.lock
generated
Normal file
7
flake.lock
generated
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"nodes": {
|
||||
"root": {}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
52
flake.nix
Normal file
52
flake.nix
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
{
|
||||
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;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
30
image.nix
Normal file
30
image.nix
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
{ pkgs ? import <nixpkgs> {}, withPackages, ocUrl, ocSha256 }:
|
||||
|
||||
let
|
||||
|
||||
opencode = builtins.fetchTarball {
|
||||
url = ocUrl;
|
||||
sha256 = ocSha256;
|
||||
};
|
||||
in
|
||||
pkgs.dockerTools.streamLayeredImage {
|
||||
name = "ocd";
|
||||
tag = "latest";
|
||||
|
||||
contents = [
|
||||
pkgs.glibc
|
||||
opencode
|
||||
] ++ (withPackages pkgs);
|
||||
|
||||
fromImage = pkgs.dockerTools.pullImage {
|
||||
imageName = "alpine";
|
||||
imageDigest = "sha256:85f2b723e106c34644cd5851d7e81ee87da98ac54672b29947c052a45d31dc2f";
|
||||
sha256 = "sha256-7ZZq7Hzgpcf7gvUrfC84SW4FrN2FwwF5+kYgWKYJQuQ=";
|
||||
};
|
||||
|
||||
config = {
|
||||
Cmd = [ "/bin/sh" ];
|
||||
WorkingDir = "/workspace";
|
||||
Volumes = { "/workspace" = {}; "/root/.local/share/opencode" = {}; };
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue