|
21 | 21 | lib = nixpkgs.lib; |
22 | 22 | systems = [ "x86_64-linux" ]; |
23 | 23 | forAllSystems = f: lib.genAttrs systems (system: f system); |
| 24 | + workspaceFor = |
| 25 | + pkgs: |
| 26 | + { |
| 27 | + packageProfile ? ( |
| 28 | + let |
| 29 | + packageProfileEnv = builtins.getEnv "PWN_WORKSPACE_PACKAGES"; |
| 30 | + in |
| 31 | + if packageProfileEnv == "" then "minimal" else packageProfileEnv |
| 32 | + ), |
| 33 | + code ? builtins.getEnv "PWN_WORKSPACE_SERVICE_CODE" == "1", |
| 34 | + desktop ? builtins.getEnv "PWN_WORKSPACE_SERVICE_DESKTOP" == "1", |
| 35 | + }: |
| 36 | + let |
| 37 | + workspacePackages = |
| 38 | + if packageProfile == "minimal" then |
| 39 | + import ./runtime/workspace/packages { inherit pkgs; } |
| 40 | + else if packageProfile == "extended" then |
| 41 | + import ./runtime/workspace/packages/extended.nix { inherit pkgs desktop; } |
| 42 | + else |
| 43 | + throw "unsupported PWN_WORKSPACE_PACKAGES=${packageProfile}; expected minimal or extended"; |
| 44 | + |
| 45 | + workspaceServices = import ./runtime/workspace/services { |
| 46 | + inherit pkgs; |
| 47 | + inherit code desktop workspacePackages; |
| 48 | + }; |
| 49 | + serviceNames = [ |
| 50 | + "tty" |
| 51 | + ] |
| 52 | + ++ lib.optional code "code" |
| 53 | + ++ lib.optional desktop "desktop"; |
| 54 | + serviceProfile = lib.concatStringsSep "-" serviceNames; |
| 55 | + name = |
| 56 | + if packageProfile == "minimal" && serviceProfile == "tty" then |
| 57 | + "pwn-workspace-runtime" |
| 58 | + else |
| 59 | + "pwn-workspace-runtime-${packageProfile}-${serviceProfile}"; |
| 60 | + runtime = import ./runtime/workspace { |
| 61 | + inherit |
| 62 | + pkgs |
| 63 | + name |
| 64 | + workspacePackages |
| 65 | + workspaceServices |
| 66 | + ; |
| 67 | + }; |
| 68 | + in |
| 69 | + { |
| 70 | + inherit runtime; |
| 71 | + summary = "packages=${packageProfile} services=${lib.concatStringsSep "," serviceNames}"; |
| 72 | + }; |
24 | 73 | in |
25 | 74 | { |
26 | 75 | formatter = forAllSystems ( |
|
47 | 96 | let |
48 | 97 | pkgs = import nixpkgs { inherit system; }; |
49 | 98 |
|
50 | | - pwn-workspace-runtime = import ./runtime/workspace { inherit pkgs; }; |
| 99 | + workspace = workspaceFor pkgs { }; |
51 | 100 | pwn-platform-runtime = import ./runtime/platform { inherit pkgs lib; }; |
52 | 101 |
|
53 | | - pwnshop = import ./tools/pwnshop { inherit pkgs pwn-workspace-runtime; }; |
| 102 | + pwnshop = import ./tools/pwnshop { |
| 103 | + inherit pkgs; |
| 104 | + pwn-workspace-runtime = workspace.runtime; |
| 105 | + }; |
54 | 106 | discord-feedback = import ./tools/feedback { inherit pkgs; }; |
55 | 107 | in |
56 | 108 | { |
57 | 109 | default = pwnshop; |
58 | 110 | inherit |
59 | 111 | discord-feedback |
60 | 112 | pwn-platform-runtime |
61 | | - pwn-workspace-runtime |
62 | 113 | pwnshop |
63 | 114 | ; |
64 | 115 | } |
|
69 | 120 | let |
70 | 121 | pkgs = import nixpkgs { inherit system; }; |
71 | 122 |
|
72 | | - pwn-workspace-runtime = import ./runtime/workspace { inherit pkgs; }; |
| 123 | + workspace = workspaceFor pkgs { }; |
| 124 | + fullWorkspace = workspaceFor pkgs { |
| 125 | + packageProfile = "extended"; |
| 126 | + code = true; |
| 127 | + desktop = true; |
| 128 | + }; |
73 | 129 | pwn-platform-runtime = import ./runtime/platform { inherit pkgs lib; }; |
74 | 130 |
|
75 | | - pwnshop = import ./tools/pwnshop { inherit pkgs pwn-workspace-runtime; }; |
| 131 | + pwnshop = import ./tools/pwnshop { |
| 132 | + inherit pkgs; |
| 133 | + pwn-workspace-runtime = workspace.runtime; |
| 134 | + }; |
76 | 135 | discord-feedback = import ./tools/feedback { inherit pkgs; }; |
77 | | - in |
78 | | - { |
79 | | - default = pkgs.mkShell { |
80 | | - packages = with pkgs; [ |
81 | | - asciinema |
82 | | - discord-feedback |
83 | | - docker |
84 | | - git |
85 | | - git-crypt |
86 | | - jq |
87 | | - pwn-platform-runtime |
88 | | - pwn-workspace-runtime |
89 | | - pwnshop |
90 | | - tomlq |
91 | | - uv |
92 | | - ]; |
93 | | - shellHook = '' |
94 | | - export PWN_WORKSPACE="${pwn-workspace-runtime}" |
| 136 | + mkDevShell = |
| 137 | + selectedWorkspace: |
| 138 | + pkgs.mkShell { |
| 139 | + packages = with pkgs; [ |
| 140 | + asciinema |
| 141 | + discord-feedback |
| 142 | + docker |
| 143 | + git |
| 144 | + git-crypt |
| 145 | + jq |
| 146 | + pwn-platform-runtime |
| 147 | + pwnshop |
| 148 | + tomlq |
| 149 | + uv |
| 150 | + selectedWorkspace.runtime |
| 151 | + ]; |
| 152 | + shellHook = '' |
| 153 | + export PWN_WORKSPACE="${selectedWorkspace.runtime}" |
| 154 | + echo "workspace: ${selectedWorkspace.summary}" >&2 |
95 | 155 |
|
96 | | - # Install the secret-test encryption pre-commit hook (idempotent, |
97 | | - # non-destructive). Resolve the path Git actually runs the hook from |
98 | | - # -- honoring core.hooksPath and the shared hooks dir of a linked |
99 | | - # worktree -- and point it at the main checkout's copy so removing a |
100 | | - # worktree can't break it. |
101 | | - if git rev-parse --git-dir >/dev/null 2>&1; then |
102 | | - hooks_dir="$(git config --path core.hooksPath 2>/dev/null || true)" |
103 | | - [ -n "$hooks_dir" ] || hooks_dir="$(git rev-parse --git-path hooks)" |
104 | | - root="$(cd "$(git rev-parse --git-common-dir)/.." && pwd)" |
105 | | - hook="$hooks_dir/pre-commit" |
106 | | - target="$root/tools/git-hooks/pre-commit" |
107 | | - if [ ! -e "$hook" ] && [ ! -L "$hook" ]; then |
108 | | - mkdir -p "$hooks_dir" |
109 | | - ln -s "$target" "$hook" |
110 | | - elif [ "$(readlink -f "$hook" 2>/dev/null)" != "$(readlink -f "$target" 2>/dev/null)" ]; then |
111 | | - echo "note: $hook already exists; not overwriting (encryption hook: tools/git-hooks/pre-commit)" >&2 |
| 156 | + # Install the secret-test encryption pre-commit hook (idempotent, |
| 157 | + # non-destructive). Resolve the path Git actually runs the hook from |
| 158 | + # -- honoring core.hooksPath and the shared hooks dir of a linked |
| 159 | + # worktree -- and point it at the main checkout's copy so removing a |
| 160 | + # worktree can't break it. |
| 161 | + if git rev-parse --git-dir >/dev/null 2>&1; then |
| 162 | + hooks_dir="$(git config --path core.hooksPath 2>/dev/null || true)" |
| 163 | + [ -n "$hooks_dir" ] || hooks_dir="$(git rev-parse --git-path hooks)" |
| 164 | + root="$(cd "$(git rev-parse --git-common-dir)/.." && pwd)" |
| 165 | + hook="$hooks_dir/pre-commit" |
| 166 | + target="$root/tools/git-hooks/pre-commit" |
| 167 | + if [ ! -e "$hook" ] && [ ! -L "$hook" ]; then |
| 168 | + mkdir -p "$hooks_dir" |
| 169 | + ln -s "$target" "$hook" |
| 170 | + elif [ "$(readlink -f "$hook" 2>/dev/null)" != "$(readlink -f "$target" 2>/dev/null)" ]; then |
| 171 | + echo "note: $hook already exists; not overwriting (encryption hook: tools/git-hooks/pre-commit)" >&2 |
| 172 | + fi |
112 | 173 | fi |
113 | | - fi |
114 | 174 |
|
115 | | - sudo= |
116 | | - if [ "$(id -u)" -ne 0 ]; then |
117 | | - if command -v sudo >/dev/null 2>&1; then |
118 | | - sudo=sudo |
119 | | - else |
120 | | - echo "error: cannot start the challenge runtime without root privileges" >&2 |
121 | | - return 1 |
| 175 | + sudo= |
| 176 | + if [ "$(id -u)" -ne 0 ]; then |
| 177 | + if command -v sudo >/dev/null 2>&1; then |
| 178 | + sudo=sudo |
| 179 | + else |
| 180 | + echo "error: cannot start the challenge runtime without root privileges" >&2 |
| 181 | + return 1 |
| 182 | + fi |
122 | 183 | fi |
123 | | - fi |
124 | 184 |
|
125 | | - if ! runtime_environment="$($sudo ${lib.getExe pwn-platform-runtime})"; then |
126 | | - echo "error: failed to start the challenge runtime" >&2 |
127 | | - return 1 |
128 | | - fi |
129 | | - eval "$runtime_environment" |
130 | | - ''; |
131 | | - }; |
| 185 | + if ! runtime_environment="$($sudo ${lib.getExe pwn-platform-runtime})"; then |
| 186 | + echo "error: failed to start the challenge runtime" >&2 |
| 187 | + return 1 |
| 188 | + fi |
| 189 | + eval "$runtime_environment" |
| 190 | + ''; |
| 191 | + }; |
| 192 | + in |
| 193 | + { |
| 194 | + default = mkDevShell workspace; |
| 195 | + full = mkDevShell fullWorkspace; |
132 | 196 | } |
133 | 197 | ); |
134 | 198 | }; |
|
0 commit comments