Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion examples/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,36 @@
nixng,
}:
let
modifiedMakeSystem =
{
config ? { },
specialArgs ? { },
...
}@args:
nglib.makeSystem (
args
// {
config = {
nixos.acceptRisks = "I accept the risks";

imports = [ config ];
};
specialArgs = specialArgs // {
__enableExperimentalNixOSCompatibility = true;
};
}
);

modifiedNglib = nglib // {
makeSystem = modifiedMakeSystem;
};

examples = {
"gitea" = ./gitea;
"gitea-sane" = ./gitea/sane.nix;
"apache" = ./apache;
"nginx" = ./nginx;
"nginx-nixos" = ./nginx-nixos;
"crond" = ./crond;
"nix" = ./nix;
"hydra" = ./hydra;
Expand All @@ -33,4 +58,10 @@ let
"ntfy-sh" = ./ntfy-sh;
};
in
nixpkgs.lib.mapAttrs (_: v: import v { inherit nixpkgs nglib nixng; }) examples
nixpkgs.lib.mapAttrs (
_: v:
import v {
inherit nixpkgs nixng;
nglib = modifiedNglib;
}
) examples
41 changes: 41 additions & 0 deletions examples/nginx-nixos/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# SPDX-FileCopyrightText: 2021 Richard Brežák and NixNG contributors
#
# SPDX-License-Identifier: MPL-2.0
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

{ nglib, nixpkgs, ... }:
nglib.makeSystem {
inherit nixpkgs;
system = "x86_64-linux";
name = "nixng-nginx-nixos";
config = (
{ pkgs, config, ... }:
{
config = {
dinit = {
enable = true;
};

init.services.nginx = {
shutdownOnExit = true;
ensureSomething.link."documentRoot" = {
src = "${pkgs.apacheHttpd}/htdocs";
dst = "/var/www";
};
};

nixos.services.nginx = {
enable = true;
virtualHosts."example.org" = {
locations."/" = {
proxyPass = "google.com";
};
};
};
};
}
);
}
113 changes: 109 additions & 4 deletions flake.lock

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

9 changes: 7 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-25.05";
buildbot-nix.url = "github:nix-community/buildbot-nix";
treefmt-nix.url = "github:numtide/treefmt-nix";
};

Expand All @@ -17,7 +18,8 @@
nixpkgs,
self,
treefmt-nix,
}:
...
}@inputs:
let
supportedSystems = [
"x86_64-linux"
Expand All @@ -40,7 +42,10 @@
inherit (nixpkgs.lib) recurseIntoAttrs;
in
{
nglib = import ./lib nixpkgs.lib;
nglib = import ./lib {
inherit (nixpkgs) lib;
inherit inputs;
};
examples = import ./examples {
inherit nixpkgs;
inherit (self) nglib;
Expand Down
2 changes: 1 addition & 1 deletion lib/dag.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

{ lib }:
{ lib, ... }:
import (builtins.fetchurl {
url = "https://raw.githubusercontent.com/nix-community/home-manager/45abf3d38a2b51c00c347cab6950f3734e023bba/modules/lib/dag.nix";
sha256 = "sha256-NN9iKanf86D1MH9Nx8nsQj9T2+Poy9XeW9pLcZIyFHU=";
Expand Down
64 changes: 41 additions & 23 deletions lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
lib:
let
inherit (lib) types;
this = {
makeSystem = import ./make-system.nix {
nglib = this;
overlay = import ../overlay;
{ lib, inputs }:
lib.fix (
nglib:
let
overlay = import ../overlay;
args = {
inherit lib nglib overlay;
};
dag = import ./dag.nix { inherit lib; };
generators = import ./generators.nix { inherit lib; };
in
{
dag = import ./dag.nix args;
generators = import ./generators.nix args;
mkDefaultRec = lib.mapAttrsRecursive (_: v: lib.mkDefault v);
mkApply = fun: x: {
original = x;
Expand All @@ -18,31 +20,31 @@ let
description:
lib.mkOption {
inherit description;
type = types.attrsOf (
types.submodule {
type = lib.types.attrsOf (
lib.types.submodule {
options = {
data = lib.mkOption {
description = ''
Script fragment which to run.
'';
type = types.str;
type = lib.types.str;
};
before = lib.mkOption {
description = ''
Script before dependencies. See <literal>/lib/dag.nix</literal>.
'';
type = with types; listOf str;
type = lib.types.listOf lib.types.str;
};
after = lib.mkOption {
description = ''
Script after dependencies. See <literal>/lib/dag.nix</literal>
'';
type = with types; listOf str;
type = lib.types.listOf lib.types.str;
};
};
}
);
apply = this.dag.dagTopoSort;
apply = nglib.dag.dagTopoSort;
default = { };
};

Expand All @@ -63,18 +65,34 @@ let
'') fragments
)}
'';

nottmpfiles = import ./nottmpfiles {
inherit lib;
nglib = this;
};
nottmpfiles = import ./nottmpfiles args;

maybeChangeUserAndGroup =
user: group: script:
if user != null then
"chpst -u ${user}${lib.optionalString (group != null) ":${group}"} ${script}"
else
script;
};
in
this

errorExperimentalNixOS =
config:
lib.throwIfNot (config.nixos.acceptRisks == "I accept the risks") ''
NixOS module compatibility is highly experimental, severely unfinished and most definitely has
functional and security bugs. Unless you know what you're doing and are willing to accept the risks
reconsider it's usage. To signify you are aware of these risks, set the option
`config.nixos.acceptRisks` to `"I accept the risks"`.

If you run into any of the aforementioned deficiencies please reach out on Matrix at
`#nixng:matrix.redalder.org`.
'';

inherit (import ./options.nix args)
mkUserOption
mkGroupOption
mkOptionsEqual
getOptionFromPath
;

makeSystem = import ./make-system.nix { inherit nglib overlay inputs; };
}
)
2 changes: 1 addition & 1 deletion lib/generators.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

{ lib }:
{ lib, ... }:
let
inherit (lib)
isAttrs
Expand Down
Loading