diff --git a/flake-modules/linux.nix b/flake-modules/linux.nix index 8e9bfd7..1e90543 100644 --- a/flake-modules/linux.nix +++ b/flake-modules/linux.nix @@ -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; @@ -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} diff --git a/flake.lock b/flake.lock index 00e6f1a..6ec21d8 100644 --- a/flake.lock +++ b/flake.lock @@ -377,6 +377,48 @@ "type": "github" } }, + "flake-parts_7": { + "inputs": { + "nixpkgs-lib": [ + "quadlet-nix-linux-stable", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1736143030, + "narHash": "sha256-+hu54pAoLDEZT9pjHlqL9DNzWz0NbUn8NEAHP7PQPzU=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "b905f6fc23a9051a6e1b741e1438dbfc0634c6de", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-parts_8": { + "inputs": { + "nixpkgs-lib": [ + "quadlet-nix-linux-unstable", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1736143030, + "narHash": "sha256-+hu54pAoLDEZT9pjHlqL9DNzWz0NbUn8NEAHP7PQPzU=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "b905f6fc23a9051a6e1b741e1438dbfc0634c6de", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -1597,18 +1639,40 @@ "type": "github" } }, - "quadlet-nix": { + "quadlet-nix-linux-stable": { "inputs": { + "flake-parts": "flake-parts_7", "nixpkgs": [ - "nixpkgs" + "nixpkgs-linux-stable" + ] + }, + "locked": { + "lastModified": 1736504679, + "narHash": "sha256-3CVVjkFZRQq40cyZ3rcJ/I/4TBmAc4KN7SqxvVRmSqI=", + "owner": "mirkolenz", + "repo": "quadlet-nix", + "rev": "5aa31a0fd13e4105ccf7c32e6c26f91de7e72588", + "type": "github" + }, + "original": { + "owner": "mirkolenz", + "repo": "quadlet-nix", + "type": "github" + } + }, + "quadlet-nix-linux-unstable": { + "inputs": { + "flake-parts": "flake-parts_8", + "nixpkgs": [ + "nixpkgs-linux-unstable" ] }, "locked": { - "lastModified": 1736083037, - "narHash": "sha256-4ewS9mACsWd83045DEPigt5Nt7tpigvG/FlJrj8fRig=", + "lastModified": 1736504679, + "narHash": "sha256-3CVVjkFZRQq40cyZ3rcJ/I/4TBmAc4KN7SqxvVRmSqI=", "owner": "mirkolenz", "repo": "quadlet-nix", - "rev": "fcbf045b8adb8b6f298a6c2487c544755ff0dcaf", + "rev": "5aa31a0fd13e4105ccf7c32e6c26f91de7e72588", "type": "github" }, "original": { @@ -1647,7 +1711,8 @@ "plist-manager-unstable": "plist-manager-unstable", "pyproject-build-systems": "pyproject-build-systems", "pyproject-nix": "pyproject-nix", - "quadlet-nix": "quadlet-nix", + "quadlet-nix-linux-stable": "quadlet-nix-linux-stable", + "quadlet-nix-linux-unstable": "quadlet-nix-linux-unstable", "systems": "systems_9", "treefmt-nix": "treefmt-nix_7", "uv2nix": "uv2nix", diff --git a/flake.nix b/flake.nix index fe16687..3f772dd 100644 --- a/flake.nix +++ b/flake.nix @@ -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"; }; }; diff --git a/system/linux/options/quadlet/_container.nix b/system/linux/options/quadlet/_container.nix index 6af3738..d972c8c 100644 --- a/system/linux/options/quadlet/_container.nix +++ b/system/linux/options/quadlet/_container.nix @@ -1,4 +1,4 @@ -{ quadletCfg, writeShellApplication }: +{ quadletCfg }: { lib, config, @@ -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 { @@ -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) ]; - }; - }; } diff --git a/system/linux/options/quadlet/default.nix b/system/linux/options/quadlet/default.nix index 06e391e..90c9119 100644 --- a/system/linux/options/quadlet/default.nix +++ b/system/linux/options/quadlet/default.nix @@ -2,7 +2,6 @@ lib, lib', config, - pkgs, ... }: let @@ -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; } ) ); diff --git a/system/linux/options/quadlet/proxy.nix b/system/linux/options/quadlet/proxy.nix index a65541e..6fc6493 100644 --- a/system/linux/options/quadlet/proxy.nix +++ b/system/linux/options/quadlet/proxy.nix @@ -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 '' @@ -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" diff --git a/system/linux/options/quadlet/update.nix b/system/linux/options/quadlet/update.nix deleted file mode 100644 index 04cd9b6..0000000 --- a/system/linux/options/quadlet/update.nix +++ /dev/null @@ -1,32 +0,0 @@ -{ - lib, - config, - pkgs, - ... -}: -let - cfg = config.virtualisation.quadlet; - updateCfg = cfg.update; -in -{ - options.virtualisation.quadlet.update = with lib; { - enable = mkEnableOption "Automatic updates of container images"; - startAt = mkOption { - type = types.str; - description = "Systemd timer start time"; - # default = "*-*-* 02:00:00"; - }; - }; - config = lib.mkIf (cfg.enable && updateCfg.enable) { - systemd.services.quadlet-update = { - inherit (updateCfg) startAt; - wantedBy = [ "multi-user.target" ]; - wants = [ "network-online.target" ]; - after = [ "network-online.target" ]; - serviceConfig.Type = "oneshot"; - script = '' - ${lib.getExe pkgs.podman} auto-update - ''; - }; - }; -} diff --git a/system/linux/options/quadlet/wrapper.nix b/system/linux/options/quadlet/wrapper.nix index 73d67a0..5c79b8f 100644 --- a/system/linux/options/quadlet/wrapper.nix +++ b/system/linux/options/quadlet/wrapper.nix @@ -5,8 +5,7 @@ ... }: let - cfg = config.virtualisation.quadlet; - wrapperCfg = cfg.shellWrapper; + cfg = config.virtualisation.quadlet.shellWrapper; wrapper = pkgs.writeShellApplication { name = "quadlet"; @@ -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 ]; + }; }