-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
108 lines (95 loc) · 3.47 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
{
inputs = {
nixpkgs.url = "github:m1cr0man/nixpkgs/rfc108-minimal";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
let
name = "nixos-nspawn";
version = with builtins; head (split "[:space:\n]+" (readFile "${self}/nixos_nspawn/version.txt"));
nspawnNix = "${self}/nixos_nspawn/nix";
in
{
overlays = {
default = self.overlays."${name}";
"${name}" = (final: prev: {
# Use pythonPackageExtensions so that any supported version of Python can be used
"${name}" = prev.python3Packages."${name}";
pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [
(python-final: python-prev: {
"${name}" = python-prev.buildPythonPackage {
inherit version;
pname = name;
src = self;
disabled = python-prev.pythonOlder "3.9";
format = "pyproject";
buildInputs = [ python-prev.poetry-core ];
propagatedBuildInputs = [ python-prev.rich ];
patches = [
# Need to compile in the system architecture.
# The Nix tools do the same thing.
(final.writeText
"nixos_nspawn_set_system.patch"
''
--- a/nixos_nspawn/system.txt
+++ b/nixos_nspawn/system.txt
@@ -1 +1 @@
-x86_64-linux
+${final.hostPlatform.system}
'')
];
checkPhase = ''
$out/bin/nixos-nspawn list > /dev/null
'';
meta = {
name = "${name}-${version}";
description = "RFC 108 imperative container manager";
};
};
})
];
});
};
lib = import "${nspawnNix}/lib.nix";
nixosModules.hypervisor = "${nspawnNix}/containers-next/hypervisor.nix";
} // (flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import "${nixpkgs}/pkgs/top-level/default.nix" {
localSystem.system = system;
overlays = [ self.overlays.default ];
config = { };
};
in
rec {
packages = {
default = pkgs."${name}";
"${name}" = packages.default;
sudo-nspawn = import "${self}/nixos_nspawn/nix/sudo-nspawn.nix" { inherit (pkgs) sudo; };
};
apps = {
default = flake-utils.lib.mkApp { drv = packages.default; };
"${name}" = apps.default;
};
devShells = {
default = (pkgs.python3.withPackages (pyPkgs: [ pyPkgs.rich ])).env.overrideAttrs (prev: {
nativeBuildInputs = prev.nativeBuildInputs ++ [ pkgs.poetry ];
});
};
checks = import ./tests/nix {
inherit system pkgs nixpkgs self;
};
# Example container
nixosContainers.example = self.lib.mkContainer {
inherit nixpkgs system pkgs;
name = "example";
modules = [
({ pkgs, ... }: {
system.stateVersion = "23.11";
environment.systemPackages = [ pkgs.python311 ];
nixosContainer.network.v4.addrPool = [ "10.151.1.1/24" ];
nixosContainer.forwardPorts = [{ hostPort = 12345; containerPort = 12345; }];
})
];
};
}));
}