Skip to content

Commit

Permalink
feat: migrate to new quadlet-nix
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkolenz committed Jan 10, 2025
1 parent 9b25957 commit 830cfa6
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 93 deletions.
6 changes: 5 additions & 1 deletion flake-modules/linux.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ let
inherit inputs channel os;
name = "home-manager";
};
quadletNix = lib'.self.systemInput {
inherit inputs channel os;
name = "quadlet-nix";
};
in
nixpkgs.lib.nixosSystem {
inherit system;
Expand All @@ -33,7 +37,7 @@ let
extraModule
self.configModules.system
homeManager.nixosModules.default
inputs.quadlet-nix.nixosModules.quadlet
quadletNix.nixosModules.default
inputs.determinate.nixosModules.default
../system/linux
../hosts/${hostName}
Expand Down
77 changes: 71 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,13 @@
url = "github:mic92/nix-index-database";
inputs.nixpkgs.follows = "nixpkgs";
};
quadlet-nix = {
quadlet-nix-linux-unstable = {
url = "github:mirkolenz/quadlet-nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.nixpkgs.follows = "nixpkgs-linux-unstable";
};
quadlet-nix-linux-stable = {
url = "github:mirkolenz/quadlet-nix";
inputs.nixpkgs.follows = "nixpkgs-linux-stable";
};
};

Expand Down
36 changes: 4 additions & 32 deletions system/linux/options/quadlet/_container.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ quadletCfg, writeShellApplication }:
{ quadletCfg }:
{
lib,
config,
Expand All @@ -10,22 +10,13 @@ let
in
{
options = {
imageFile = mkOption {
type = with types; nullOr package;
default = null;
};
imageStream = mkOption {
type = with types; nullOr package;
default = null;
};

virtualHost =
let
networkRef = quadletCfg.proxy.networks.internal.ref;
networkConfig = lib.findSingle (
networkEntry = lib.findSingle (
network: lib.hasPrefix "${networkRef}:" network
) "" "" config.containerConfig.networks;
matches = lib.match "ip=([[:digit:].]+)" networkConfig;
) "" "" config.containerConfig.Network;
matches = lib.match "ip=([[:digit:].]+)" networkEntry;
ip = if matches != null && lib.length matches > 0 then lib.head matches else null;
in
mkOption {
Expand All @@ -38,23 +29,4 @@ in
);
};
};
config =
let
prestart = writeShellApplication {
name = "prestart";
text = ''
${lib.optionalString (config.imageFile != null) ''
podman load -i ${config.imageFile}
''}
${lib.optionalString (config.imageStream != null) ''
${config.imageStream} | podman load
''}
'';
};
in
{
serviceConfig = {
ExecStartPre = [ (lib.getExe prestart) ];
};
};
}
7 changes: 0 additions & 7 deletions system/linux/options/quadlet/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
lib,
lib',
config,
pkgs,
...
}:
let
Expand All @@ -12,17 +11,11 @@ in
{
imports = lib'.flocken.getModules ./.;
options.virtualisation.quadlet = {
# TODO: Make sure that all quadlet options are disabled if set to false
enable = mkOption {
default = true;
type = with types; bool;
};
containers = mkOption {
type = types.attrsOf (
types.submodule (
import ./_container.nix {
quadletCfg = cfg;
inherit (pkgs) writeShellApplication;
}
)
);
Expand Down
15 changes: 5 additions & 10 deletions system/linux/options/quadlet/proxy.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let
_: container:
(lib.findSingle (
network: lib.hasPrefix "${proxyNetwork}:" network
) null null container.containerConfig.networks) != null
) null null container.containerConfig.Network) != null
) config.virtualisation.quadlet.containers;
in
''
Expand Down Expand Up @@ -190,23 +190,18 @@ in
config = lib.mkIf (config.virtualisation.quadlet.enable && cfg.enable) {
virtualisation.quadlet.containers.proxy = lib.mkMerge [
{
imageStream = lib.mkDefault pkgs.caddy-custom-docker;
imageStream = pkgs.caddy-custom-docker;
containerConfig = {
image =
let
imageStream = config.virtualisation.quadlet.containers.proxy.imageStream;
in
"localhost/${imageStream.imageName}:${imageStream.imageTag}";
volumes = [
Volume = [
"${cfg.configFile}:/etc/caddy/Caddyfile:ro"
"${cfg.storage.data}:/data"
"${cfg.storage.config}:/config"
] ++ (lib.optional (cfg.storage.certificates != null) "${cfg.storage.certificates}:/certificates");
networks = [
Network = [
"${cfg.networks.internal.ref}:ip=${cfg.networks.internal.ip}"
"${cfg.networks.external.ref}:ip=${cfg.networks.external.ip}"
];
publishPorts = [
PublishPort = [
"80:80"
"443:443"
"443:443/udp"
Expand Down
32 changes: 0 additions & 32 deletions system/linux/options/quadlet/update.nix

This file was deleted.

7 changes: 4 additions & 3 deletions system/linux/options/quadlet/wrapper.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
...
}:
let
cfg = config.virtualisation.quadlet;
wrapperCfg = cfg.shellWrapper;
cfg = config.virtualisation.quadlet.shellWrapper;

wrapper = pkgs.writeShellApplication {
name = "quadlet";
Expand Down Expand Up @@ -52,5 +51,7 @@ in
};
};

config = lib.mkIf (cfg.enable && wrapperCfg.enable) { environment.systemPackages = [ wrapper ]; };
config = lib.mkIf (config.virtualisation.quadlet.enable && cfg.enable) {
environment.systemPackages = [ wrapper ];
};
}

0 comments on commit 830cfa6

Please sign in to comment.