Skip to content

Commit f622499

Browse files
authored
Merge pull request #57 from tumble1999/mod-framework
Mod framework
2 parents 6f459a2 + f8386a3 commit f622499

20 files changed

+852
-289
lines changed

flake.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
flake = false;
2222
url = "github:nothings/stb/5736b15f7ea0ffb08dd38af21067c314d6a3aae9";
2323
};
24+
ninecraft-mod-toolchain-build-scripts = {
25+
flake = false;
26+
url = "github:MCPI-Revival/ninecraft-mod-toolchain-build-scripts";
27+
};
2428
};
2529

2630
outputs = {
@@ -31,11 +35,15 @@
3135
glad,
3236
ancmp,
3337
stb,
38+
ninecraft-mod-toolchain-build-scripts,
3439
}: let
3540
mkPkgs = system:
3641
import nixpkgs {
3742
inherit system;
38-
config.allowUnfree = true;
43+
config = {
44+
allowUnfree = true;
45+
android_sdk.accept_license = true;
46+
};
3947
overlays = [nixgl.overlay];
4048
};
4149
in
@@ -45,11 +53,14 @@
4553
packages =
4654
(import ./nix/pkgs {
4755
inherit pkgs;
48-
inherit glad stb ancmp;
56+
flakeRoot = self;
57+
# inherit glad stb ancmp ninecraft-mod-toolchain-build-scripts;
4958
# ancmp = ./ancmp;
5059
})
5160
// {
52-
default = packages.ninecraft;
61+
default = packages.buildNinecraftInstance {
62+
version = packages.mcpeVersions.a0_6_1;
63+
};
5364
};
5465
apps = {
5566
extract = {
@@ -58,9 +69,6 @@
5869
};
5970
};
6071
formatter = pkgs.alejandra;
61-
devShell = pkgs.callPackage ./nix/shell.nix {
62-
inherit (packages) ninecraft ninecraft-nixgl;
63-
};
6472
})
6573
// {
6674
nixosModule = {pkgs, ...}: {

nix/README.md

Lines changed: 110 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Please don't just blindly copy and paste the below, please [learn about nix flak
1313
{
1414
inputs = {
1515
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
16-
ninecraft = {
16+
ninecraft = {
1717
url = "github:MCPI-Revival/Ninecraft";
1818
inputs.nixpkgs.follows = "nixpkgs";
1919
};
@@ -25,8 +25,8 @@ Please don't just blindly copy and paste the below, please [learn about nix flak
2525
nixosConfigurations = {
2626
# NOTE: change "host" to your system's hostname
2727
host = nixpkgs.lib.nixosSystem {
28-
system = "x86_64-linux";
29-
specialArgs = [ninecraft];
28+
system = "x86_64-linux";
29+
specialArgs = [ninecraft];
3030
modules = [
3131
./configuration.nix
3232
];
@@ -37,11 +37,11 @@ Please don't just blindly copy and paste the below, please [learn about nix flak
3737
user = lib.homeManagerConfiguration {
3838
extraSpecialArgs = moduleArgs;
3939
40-
specialArgs = [ninecraft];
40+
specialArgs = [ninecraft];
4141
modules = [
4242
./home.nix
4343
];
44-
system
44+
system
4545
};
4646
};
4747
};
@@ -57,78 +57,120 @@ Please don't just blindly copy and paste the below, please [learn about nix flak
5757
```nix
5858
{pkgs,lib,...}:
5959
{
60-
imports = [
61-
# without flakes
62-
<ninecraft/nix/nixos>
63-
#with flakes
64-
ninecraft.nixosModule
65-
];
66-
67-
# ... other stuff
68-
69-
programs.ninecraft = {
70-
enable = true;
71-
openFirewall = true;
72-
};
60+
imports = [
61+
# without flakes
62+
<ninecraft/nix/nixos>
63+
#with flakes
64+
ninecraft.nixosModule
65+
];
66+
67+
# ... other stuff
68+
69+
programs.ninecraft = {
70+
enable = true;
71+
openFirewall = true;
72+
};
7373
}
7474
```
7575

7676
## HomeManager
77+
7778
> home.nix
7879
7980
This is a work in progress and many options may not function yet.
8081

8182
```nix
8283
{pkgs,lib,...}:
8384
{
84-
imports = [
85-
# without flakes
86-
<ninecraft/nix/home>
87-
#with flakes
88-
ninecraft.homeManagerModule
89-
];
90-
91-
# ... other stuff
92-
93-
programs.ninecraft = {
94-
enable = true;
95-
version = "0.6.0";
96-
#apk = fetchzip {
97-
# url = "https://archive.org/download/MCPEAlpha/PE-a0.7.0-x86.apk"
98-
# hash = lib.fakeHash;
99-
# }
100-
options = {
101-
"mp_username"="Steve";
102-
"mp_server"="Steve";
103-
"mp_server_visible_default"=true;
104-
"gfx_fancygraphics"=true;
105-
"gfx_lowquality"=false;
106-
"ctrl_sensitivity"=0.5
107-
"ctrl_invertmouse"=false;
108-
"ctrl_islefthanded"=false;
109-
"ctrl_usetouchscreen"=false;
110-
"ctrl_usetouchjoypad"=false;
111-
"feedback_vibration"=false;
112-
"game_difficulty"=4;
113-
};
114-
115-
#extracts into mod folder
116-
mods = with pkgs; [
117-
(fetchzip {
118-
url = "example.com/mod.zip";
119-
hash = lib.fakeHash;
120-
})
121-
(fetchgit {
122-
url = "https://.../ok.git";
123-
hash = lib.fakeHash;
124-
})
125-
(fetchFromGitHub {
126-
owner = "a";
127-
repo = "b";
128-
rev = "main";
129-
hash = lib.fakeHash;
130-
})
131-
]
132-
}
85+
imports = [
86+
# without flakes
87+
<ninecraft/nix/home>
88+
#with flakes
89+
ninecraft.homeManagerModule
90+
];
91+
92+
# ... other stuff
93+
94+
programs.ninecraft = {
95+
enable = true;
96+
version = "0.6.0";
97+
#apk = fetchzip {
98+
# url = "https://archive.org/download/MCPEAlpha/PE-a0.7.0-x86.apk"
99+
# hash = lib.fakeHash;
100+
# }
101+
options = {
102+
"mp_username"="Steve";
103+
"mp_server"="Steve";
104+
"mp_server_visible_default"=true;
105+
"gfx_fancygraphics"=true;
106+
"gfx_lowquality"=false;
107+
"ctrl_sensitivity"=0.5
108+
"ctrl_invertmouse"=false;
109+
"ctrl_islefthanded"=false;
110+
"ctrl_usetouchscreen"=false;
111+
"ctrl_usetouchjoypad"=false;
112+
"feedback_vibration"=false;
113+
"game_difficulty"=4;
114+
};
115+
116+
#extracts into mod folder
117+
mods = with pkgs; [
118+
(fetchzip {
119+
url = "example.com/mod.zip";
120+
hash = lib.fakeHash;
121+
})
122+
(fetchgit {
123+
url = "https://.../ok.git";
124+
hash = lib.fakeHash;
125+
})
126+
(fetchFromGitHub {
127+
owner = "a";
128+
repo = "b";
129+
rev = "main";
130+
hash = lib.fakeHash;
131+
})
132+
]
133+
}
133134
}
134-
```
135+
```
136+
137+
# Modding
138+
139+
## Create Mod
140+
141+
```nix
142+
with import <ninecraft/nix/pkgs> {}:
143+
buildNinecraftMod {
144+
pname = "mymod";
145+
version = "0.1.0";
146+
src = ./src;
147+
}
148+
```
149+
```nix
150+
with import <ninecraft/nix/pkgs> {}:
151+
buildNinecraftMod {
152+
pname = "mymod";
153+
version = "0.1.0";
154+
src = fetchurl {
155+
url = "example.com/path/to/mod.zip";
156+
hash = lib.fakeHash;
157+
};
158+
precompiled = true;
159+
compiledX86 = "x86/mod.so";
160+
compiledArm = "arm/mod.so";
161+
}
162+
```
163+
164+
```nix
165+
with import <nixpkgs> {};
166+
with import <ninecraft/nix/pkgs> {}:
167+
buildNinecraftMod {
168+
pname = "mymod";
169+
version = "0.1.0";
170+
src = fetchurl {
171+
url = "example.com/path/to/mod/${system}/mod.so";
172+
hash = lib.fakeHash;
173+
};
174+
precompiled = true;
175+
}
176+
```

nix/default.nix

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
pkgs ?
3+
import <nixpkgs> {
4+
config = {
5+
allowUnfree = true;
6+
android_sdk.accept_license = true;
7+
};
8+
},
9+
lib ? import ./lib.nix {inherit pkgs;},
10+
ninecraftPkgs ? import ./pkgs {inherit pkgs;},
11+
}:
12+
ninecraftPkgs
13+
// {
14+
inherit (lib) nixgl;
15+
home = import ./home;
16+
nixos = import ./nixos;
17+
}

nix/home/default.nix

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,61 @@
22
pkgs,
33
config,
44
lib,
5+
osConfig ? null,
56
...
67
}: let
78
cfg = config.programs.ninecraft;
9+
types = lib.types;
10+
mkOptDef = default: lib.mkOption {inherit default;};
11+
mkOptType = type: lib.mkOption {inherit type;};
12+
mkOptNamed = options:
13+
lib.mkOption {
14+
default = {};
15+
type = with types; attrsOf (submodule [{inherit options;}]);
16+
};
817
in {
9-
options.programs.ninecraft = let
10-
types = lib.types;
11-
in {
18+
options.programs.ninecraft = {
1219
enable = lib.mkEnableOption "Install Ninecraft";
13-
version = lib.mkOption {
14-
type = types.str;
15-
default = "0.6.0";
16-
};
1720
package = lib.mkOption {
1821
type = types.package;
19-
default = with import ../pkgs {}; ninecraft;
22+
default = pkgs.ninecraft;
2023
};
21-
apk = lib.mkOption {
22-
type = types.nullOr (types.package);
23-
};
24-
options = lib.mkOption {
25-
type = types.attrsOf (types.oneOf [types.int types.bool types.str]);
26-
default = {
27-
"mp_username" = "Steve";
28-
"mp_server" = "Steve";
29-
"mp_server_visible_default" = true;
30-
"gfx_fancygraphics" = true;
31-
"gfx_lowquality" = false;
32-
"ctrl_sensitivity" = 0.5;
33-
"ctrl_invertmouse" = false;
34-
"ctrl_islefthanded" = false;
35-
"ctrl_usetouchscreen" = false;
36-
"ctrl_usetouchjoypad" = false;
37-
"feedback_vibration" = false;
38-
"game_difficulty" = 4;
24+
instances = mkOptNamed {
25+
version = lib.mkOption {
26+
type = types.str;
27+
default = "0.6.1";
28+
};
29+
30+
options = lib.mkOption {
31+
default = null;
32+
type =
33+
types.nullOr (types.attrsOf (types.oneOf [types.int types.bool types.str]));
34+
};
35+
apk = lib.mkOption {
36+
type = types.nullOr (types.package);
37+
default = pkgs.mcpeVersions.a0_6_1;
38+
};
39+
mods = lib.mkOption {
40+
type = types.listOf types.package;
41+
default = [];
3942
};
4043
};
41-
mods = lib.mkOption {
42-
type = types.listOf types.package;
43-
default = [];
44-
};
44+
};
45+
46+
config = lib.mkIf cfg.enable {
47+
nixpkgs.overlays = lib.mkIf (!(osConfig.home-manager.useGlobalPkgs or false)) [
48+
(new: old: import ../. {pkgs = new;})
49+
];
50+
home.packages = builtins.map (
51+
name: let
52+
inCfg = cfg.instances.${name};
53+
version = inCfg.apk or pkgs.mcpeVersions."a${lib.replaceStrings ["."] ["_"] cfg.version}";
54+
in
55+
pkgs.buildNinecraftInstance (inCfg
56+
// {
57+
inherit name version;
58+
homeDir = "~/.local/share/ninecraft/instances/${name}";
59+
})
60+
) (builtins.attrNames cfg.instances);
4561
};
4662
}

0 commit comments

Comments
 (0)