Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
164 commits
Select commit Hold shift + click to select a range
eaa94b2
pythonPackages.websocket_client: 0.40.0 -> 0.47.0
lsix Feb 26, 2018
95d59d4
pythonPackages.kubernetes: init at 5.0.0
lsix Feb 26, 2018
dc53d5f
man-pages: 4.14 -> 4.15
ryantm Feb 27, 2018
fad95a3
gopass: 1.6.7 -> 1.6.11
suvash Feb 27, 2018
b5f475c
gambit: 4.8.8-435-gd1991ba7 -> 4.8.9
fare Feb 27, 2018
e01ecc2
mbpfan: 2.0.1 -> 2.0.2
ryantm Feb 27, 2018
ef27d3e
mcelog: 153 -> 154
ryantm Feb 27, 2018
b0a8ca6
mediainfo-gui: 17.10 -> 17.12
ryantm Feb 27, 2018
95e9896
memcached: 1.5.4 -> 1.5.5
ryantm Feb 27, 2018
939e653
menu-cache: 1.0.2 -> 1.1.0
ryantm Feb 27, 2018
bb76359
meterbridge: 0.9.2 -> 0.9.3
ryantm Feb 27, 2018
f361beb
mg: 20170828 -> 20171014
ryantm Feb 27, 2018
9c51e9f
minisign: 0.7 -> 0.8
ryantm Feb 27, 2018
4e2def9
mksh: 56b -> 56c
ryantm Feb 27, 2018
fb73e0e
mpdas: 0.4.4 -> 0.4.5
ryantm Feb 27, 2018
b8c67f3
Merge pull request #35870 from ryantm/auto-update/memcached-1.5.4-to-…
adisbladis Feb 27, 2018
f5f8330
Merge pull request #35866 from ryantm/auto-update/meterbridge-0.9.2-t…
FRidh Feb 27, 2018
a69917e
Merge pull request #35871 from ryantm/auto-update/mediainfo-gui-17.10…
adisbladis Feb 27, 2018
b5baccb
Merge pull request #35864 from ryantm/auto-update/minisign-0.7-to-0.8
adisbladis Feb 27, 2018
6d0f342
Merge pull request #35875 from ryantm/auto-update/mbpfan-2.0.1-to-2.0.2
adisbladis Feb 27, 2018
84249c7
Merge pull request #35873 from ryantm/auto-update/mcelog-153-to-154
adisbladis Feb 27, 2018
0a4f591
Merge pull request #35865 from ryantm/auto-update/mg-20170828-to-2017…
adisbladis Feb 27, 2018
b75327e
Merge pull request #35869 from ryantm/auto-update/menu-cache-1.0.2-to…
adisbladis Feb 27, 2018
3265226
Merge pull request #35859 from ryantm/auto-update/mksh-56b-to-56c
joachifm Feb 27, 2018
62f0942
Merge pull request #35668 from lsix/add_pythonPackages_kubernetes
FRidh Feb 27, 2018
c4cd0ec
Merge pull request #35845 from suvash/update-gopass
Mic92 Feb 27, 2018
79a7f95
Merge pull request #35876 from ryantm/auto-update/mpdas-0.4.4-to-0.4.5
FRidh Feb 27, 2018
dc3bbb9
Merge pull request #35877 from ryantm/auto-update/man-pages-4.14-to-4.15
FRidh Feb 27, 2018
acc2273
gdbgui: 0.11.0.0 -> 0.11.1.2
Mic92 Feb 27, 2018
e5a8dc8
dnsperf: fix build by adding openssl
Mic92 Feb 27, 2018
b649b08
gerbil: 0.12-DEV-1404-g0a266db -> 0.12-RELEASE
fare Feb 27, 2018
90b69fa
a2jmidid: does not build on aarch64
Mic92 Feb 27, 2018
e41641d
Merge pull request #35888 from fare-patches/master
7c6f434c Feb 27, 2018
973a801
gcc 6: Allow cross-compilation
bgamari Oct 30, 2017
5a654d0
xz: Don't run testsuite when cross-compiling
bgamari Oct 15, 2017
040fbdd
gperf: Don't hard-code name of ar
bgamari Oct 15, 2017
e1b5f70
iptables: Link explicitly against libdl
bgamari Oct 15, 2017
3f9d004
readline: Don't attempt to check for broken wcwidth
bgamari Oct 15, 2017
cb70370
binutils: Add support for overriding default ld
bgamari Oct 16, 2017
adc0cdf
perl: Cross-compilation isn't possible
bgamari Oct 16, 2017
a29caea
perl: Add support for cross-compilation via perl-cross
bgamari Oct 16, 2017
b74ca10
cc-wrapper: Also produce platform-prefixed wrappers
bgamari Oct 17, 2017
7419128
ed: Fix executable name
bgamari Oct 17, 2017
e305c2f
[HACK] ld-wrapper: Pass -rpath-link as well
bgamari Oct 17, 2017
0c87ab0
[HACK] cyrus-sasl: Enable cross-compilation and bump version to 2.1.2…
bgamari Oct 17, 2017
23eedcc
ld-wrapper: Consider all shared library references
bgamari Oct 17, 2017
8159f50
libssh2: Enable cross-compiling
bgamari Oct 18, 2017
ef786b8
lzip: Enable cross-compilation
bgamari Oct 18, 2017
e01541b
HACK: curl: Enable cross-compilation
bgamari Oct 18, 2017
51e1c6a
libtasn1: Enable cross-compilation
bgamari Oct 18, 2017
e7803a7
swig: Use autoreconfHook
bgamari Oct 18, 2017
f84780d
swig: Enable cross-compilation
bgamari Oct 18, 2017
90d38ca
guile: Enable cross compilation
bgamari Oct 18, 2017
6068d40
guile2_0: Enable cross-compilation
bgamari Oct 25, 2017
5664410
stdenv/adapters: Ensure all build inputs are propagated?
bgamari Oct 26, 2017
1652642
openldap: Enable cross-compiling
bgamari Oct 18, 2017
5905d29
gperf: Drop bit of patch that was already applied?
bgamari Oct 27, 2017
d01c7ee
swig3: Enable cross-compilation
bgamari Oct 27, 2017
5fc29ea
llvm: Try cross-compiling
bgamari Oct 27, 2017
9a6a803
llvm: Enable cross-compilation
bgamari Oct 27, 2017
55a8ddd
fetchurl: Always use curl for build platform
bgamari Oct 27, 2017
ab5c76f
curl: Fix toolchain paths
bgamari Oct 28, 2017
c4f96bb
kernel: Enable cross compiling
bgamari Oct 28, 2017
1a4fe3c
uboot: Enable cross-compilation
bgamari Oct 28, 2017
c1e8f0d
uboot: Add ubootMicrozed expression
bgamari Oct 28, 2017
4bcfb06
uboot: Bump version to 2017.09
bgamari Oct 28, 2017
c4dbc38
uboot: Make it build
bgamari Oct 28, 2017
8daeb54
vim: Fix cross-compilation
bgamari Oct 29, 2017
d9a88ac
runit: Enable cross-compilation
bgamari Oct 29, 2017
2210827
strace: Enable cross-compilation
bgamari Oct 29, 2017
1955e2f
util-linux: A bit of cleanup
bgamari Oct 29, 2017
e56045e
libnl: Enable parallel building
bgamari Oct 29, 2017
d1a6e26
libnfsidmap: Fix setting of configureFlags
bgamari Oct 29, 2017
0f7f606
ti-rpc: Enable cross-compilation
bgamari Oct 29, 2017
464ef1e
tcp-wrappers: Fix AR name
bgamari Oct 29, 2017
7a77303
nfs-utils: Enable cross-compilation
bgamari Oct 29, 2017
3741227
gcc: Refactor treatment of configure flags
bgamari Nov 5, 2017
ccfd1cb
autoconf264: Enable cross-compilation
bgamari Nov 5, 2017
da0958b
kernel fixes
bgamari Dec 6, 2017
6aa61ac
Revert "cc-wrapper: Also produce platform-prefixed wrappers"
bgamari Dec 6, 2017
8f87ac3
gettext: Fix circular dependency on acl
bgamari Dec 7, 2017
66b56e8
getopt: Enable cross-compilation
bgamari Dec 7, 2017
2759677
net-tools: Enable cross-compilation
bgamari Dec 7, 2017
94ef059
mmc-utils: Enable cross-compilation
bgamari Dec 7, 2017
eab6818
uboot: Update to 2017.11
bgamari Dec 7, 2017
82e2b69
XXX: libunistring: Disable tests
bgamari Dec 9, 2017
41b0e80
boost: Fix cross-compilation
bgamari Dec 9, 2017
2b6fff8
XXX: gcc6: Fix cross-compilation
bgamari Dec 9, 2017
205df01
vim: Fix cross-compilation
bgamari Dec 10, 2017
431b960
libidn2: Enable cross-compilation
bgamari Dec 10, 2017
10116de
libuv: Disable tests when cross-compiling
bgamari Dec 10, 2017
9163ada
rhash: Enable cross-compilation
bgamari Dec 10, 2017
e15c66a
libarchive: Enable parallel building
bgamari Dec 10, 2017
04a34d7
bintools-wrapper: Wrap ar, ranlib, and strip
bgamari Dec 10, 2017
0dfdde1
gdb: Enable cross-compilation
bgamari Dec 10, 2017
36a2e77
perl-modules: Don't run tests when cross-compiling
bgamari Dec 10, 2017
b386032
cyrus-sasl: update
bgamari Dec 10, 2017
24d8f00
git: Allow use of default texinfo
bgamari Dec 10, 2017
d734e9a
git: Allow perl usage to be disabled
bgamari Dec 10, 2017
462d058
git: Documentation builders are nativeBuildInputs
bgamari Dec 10, 2017
3fce3cd
opensp: All dependencies are nativeBuildInputs
bgamari Dec 10, 2017
b65c93a
git: Enable cross-compilation
bgamari Dec 10, 2017
a0dd917
git: Fix USE_LIBPCRE2 configuration
bgamari Dec 10, 2017
4e139c0
bridge-utils: Enable cross-compilation
bgamari Dec 10, 2017
b78540f
cyrus-sasl: Propagate kerberos dependency
bgamari Dec 11, 2017
355624d
nixos/nixpkgs: Add crossSystem option
bgamari Dec 15, 2017
d20f903
pixman: Don't run tests when cross-compiling
bgamari Dec 15, 2017
a406a0b
parted: Don't run tests when cross-compiling
bgamari Dec 15, 2017
25a240a
uthash: Don't run testsuite when cross-compiling
bgamari Dec 15, 2017
0835c79
giflib: Enable cross-compilation
bgamari Dec 16, 2017
7d5e6ab
gperf3: Fix cross-compilation
bgamari Dec 16, 2017
2c70332
XXX: tzdata: Fix cross compilation
bgamari Dec 16, 2017
5073147
zip: Add support for cross-compilation
bgamari Dec 16, 2017
d156f37
nixos/boot/stage-1: Build inputs are nativeBuildInputs
bgamari Dec 17, 2017
f6d75f6
XXX: iputils: Use from git
bgamari Dec 17, 2017
c0fbd9f
lmdb: Fix cross-compilation
bgamari Dec 17, 2017
91f8a13
bind: Enable cross-compilation
bgamari Dec 17, 2017
e275f75
XXX: make-wrapper: Avoid bash ${var@Q} syntax
bgamari Dec 18, 2017
7ececd2
fuse: Fix cross-compilation
bgamari Dec 18, 2017
20a19ce
apt: Fix cross-compilation
bgamari Dec 18, 2017
59376ea
w3m: Fix cross-compilation
bgamari Dec 19, 2017
7393576
uboot: Fix cross-compilation
bgamari Dec 19, 2017
a1e9c2e
xmlto: Fix cross-compilation
bgamari Dec 19, 2017
197bc85
nixos/ssh: Disable by default
bgamari Dec 19, 2017
923926f
nixos/sd-image: Inputs are nativeBuildInputs
bgamari Dec 19, 2017
d952e5b
system/boot/stage-2: Ensure that $shell is set
bgamari Dec 19, 2017
fa39225
nixos/systemd: Force use of bash in service wrappers
bgamari Dec 19, 2017
f571101
XXX: perl-cross: Is this necessary?
bgamari Dec 19, 2017
efb0d1e
XXX: glibc: Always expose ldd
bgamari Dec 19, 2017
7334997
systemd: Ensure the target utilities are used
bgamari Dec 19, 2017
5ced538
dtc: python2 is a nativeBuildInput
bgamari Dec 19, 2017
ec2c32a
avahi: Enable cross-compilation
bgamari Dec 20, 2017
de07562
bintools-wrapper: Wrap nm
bgamari Dec 21, 2017
7fa75ab
make-derivation: Don't add host-suffix to fixed-output derivations names
bgamari Dec 22, 2017
3401c12
python: Never test python packages when cross-compiling
bgamari Dec 23, 2017
0cea327
libvorbis: Don't run tests when cross-compiling
bgamari Dec 25, 2017
02695ef
ghc-8.2.2: Fix gmp-enabled build
bgamari Jan 7, 2018
e8193a8
nixos/firewall: Use target bash in script
bgamari Jan 8, 2018
43d814c
linux/kernel: Use stdenvNoCC for configuration
bgamari Jan 29, 2018
d80db6d
fixup! git: Enable cross-compilation
bgamari Feb 19, 2018
3a2fd6d
XXX: gmp: Disable tests
bgamari Feb 19, 2018
781b5c3
fixup! XXX: libunistring: Disable tests
bgamari Feb 19, 2018
71f373a
fixup! XXX: iputils: Use from git
bgamari Feb 19, 2018
6ddce89
[HACK] libgpg-error: Fix armv7l build
bgamari Oct 29, 2017
93b812b
perl-cross: Build with gcc6
bgamari Feb 24, 2018
981bed0
gcc6: Mark fallthrus explicitly
bgamari Feb 24, 2018
a314b29
ruby: XXX: Don't use buildRuby
bgamari Feb 24, 2018
53c5d9d
fixup! gcc6: Mark fallthrus explicitly
bgamari Feb 25, 2018
9d8e303
ldns: Enable cross-compilation
bgamari Feb 25, 2018
47b5b4f
systemd: m4 is a nativeBuildInput
bgamari Feb 25, 2018
6a17313
perl-cross: Update versions
bgamari Feb 25, 2018
c6a6521
fixup! perl-cross: Build with gcc6
bgamari Feb 25, 2018
df8eab1
ubootTools: Build envtools as well
bgamari Feb 25, 2018
997142f
strongswan: Enable cross-compilation
bgamari Feb 26, 2018
17599f3
fixup! w3m: Fix cross-compilation
bgamari Feb 26, 2018
163a835
rng-tools: Enable cross-compilation
bgamari Feb 26, 2018
9875426
nixos: add the strongswan-swanctl service
basvandijk Aug 5, 2017
bb4f9d0
strongswan-swanctl: support strongswan-5.6.1 configuration options
basvandijk Nov 27, 2017
b347de0
strongswan-swanctl: don't generate options for charon
basvandijk Dec 24, 2017
e9b8ed6
fixup! libnfsidmap: Fix setting of configureFlags
bgamari Feb 27, 2018
e57de88
fixup! ti-rpc: Enable cross-compilation
bgamari Feb 27, 2018
30cec12
fixup! fuse: Fix cross-compilation
bgamari Feb 27, 2018
8cd439d
fixup! bind: Enable cross-compilation
bgamari Feb 27, 2018
caea96e
fixup! linux/kernel: Use stdenvNoCC for configuration
bgamari Feb 27, 2018
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
2 changes: 1 addition & 1 deletion nixos/modules/installer/cd-dvd/sd-image.nix
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ in
system.build.sdImage = pkgs.stdenv.mkDerivation {
name = "sd-image-${pkgs.stdenv.system}.img";

buildInputs = with pkgs; [ dosfstools e2fsprogs mtools libfaketime utillinux ];
nativeBuildInputs = with pkgs; [ dosfstools e2fsprogs mtools libfaketime utillinux ];

buildCommand = ''
# Create the image file sized to fit /boot and /, plus 20M of slack
Expand Down
8 changes: 8 additions & 0 deletions nixos/modules/misc/nixpkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ in
Ignored when <code>nixpkgs.pkgs</code> is set.
'';
};

crossSystem = mkOption {
default = null;
example = "i686-linux";
description = ''
TODO
'';
};
};

config = {
Expand Down
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@
./services/networking/ssh/lshd.nix
./services/networking/ssh/sshd.nix
./services/networking/strongswan.nix
./services/networking/strongswan-swanctl/module.nix
./services/networking/stunnel.nix
./services/networking/supplicant.nix
./services/networking/supybot.nix
Expand Down
1 change: 1 addition & 0 deletions nixos/modules/programs/ssh.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ in

setXAuthLocation = mkOption {
type = types.bool;
default = false;
description = ''
Whether to set the path to <command>xauth</command> for X11-forwarded connections.
This causes a dependency on X11 packages.
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/services/networking/firewall.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ let
'';

writeShScript = name: text: let dir = pkgs.writeScriptBin name ''
#! ${pkgs.stdenv.shell} -e
#! ${pkgs.bash} -e
${text}
''; in "${dir}/bin/${name}";

Expand Down
80 changes: 80 additions & 0 deletions nixos/modules/services/networking/strongswan-swanctl/module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{ config, lib, pkgs, ... }:

with lib;
with (import ./param-lib.nix lib);

let
cfg = config.services.strongswan-swanctl;

# TODO: auto-generate these files using:
# https://github.com/strongswan/strongswan/tree/master/conf
# IDEA: extend the format-options.py script to output these Nix files.
strongswanParams = import ./strongswan-params.nix lib;
swanctlParams = import ./swanctl-params.nix lib;
in {
options.services.strongswan-swanctl = {
enable = mkEnableOption "strongswan-swanctl service";

package = mkOption {
type = types.package;
default = pkgs.strongswan;
defaultText = "pkgs.strongswan";
description = ''
The strongswan derivation to use.
'';
};

strongswan = paramsToOptions strongswanParams;
swanctl = paramsToOptions swanctlParams;
};

config = mkIf cfg.enable {

assertions = [
{ assertion = !config.services.strongswan.enable;
message = "cannot enable both services.strongswan and services.strongswan-swanctl. Choose either one.";
}
];

environment.etc."swanctl/swanctl.conf".text =
paramsToConf cfg.swanctl swanctlParams;

# The swanctl command complains when the following directories don't exist:
# See: https://wiki.strongswan.org/projects/strongswan/wiki/Swanctldirectory
system.activationScripts.strongswan-swanctl-etc = stringAfter ["etc"] ''
mkdir -p '/etc/swanctl/x509' # Trusted X.509 end entity certificates
mkdir -p '/etc/swanctl/x509ca' # Trusted X.509 Certificate Authority certificates
mkdir -p '/etc/swanctl/x509ocsp'
mkdir -p '/etc/swanctl/x509aa' # Trusted X.509 Attribute Authority certificates
mkdir -p '/etc/swanctl/x509ac' # Attribute Certificates
mkdir -p '/etc/swanctl/x509crl' # Certificate Revocation Lists
mkdir -p '/etc/swanctl/pubkey' # Raw public keys
mkdir -p '/etc/swanctl/private' # Private keys in any format
mkdir -p '/etc/swanctl/rsa' # PKCS#1 encoded RSA private keys
mkdir -p '/etc/swanctl/ecdsa' # Plain ECDSA private keys
mkdir -p '/etc/swanctl/bliss'
mkdir -p '/etc/swanctl/pkcs8' # PKCS#8 encoded private keys of any type
mkdir -p '/etc/swanctl/pkcs12' # PKCS#12 containers
'';

systemd.services.strongswan-swanctl = {
description = "strongSwan IPsec IKEv1/IKEv2 daemon using swanctl";
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" "keys.target" ];
wants = [ "keys.target" ];
path = with pkgs; [ kmod iproute iptables utillinux ];
environment.STRONGSWAN_CONF = pkgs.writeTextFile {
name = "strongswan.conf";
text = paramsToConf cfg.strongswan strongswanParams;
};
restartTriggers = [ config.environment.etc."swanctl/swanctl.conf".source ];
serviceConfig = {
ExecStart = "${cfg.package}/sbin/charon-systemd";
Type = "notify";
ExecStartPost = "${cfg.package}/sbin/swanctl --load-all --noprompt";
ExecReload = "${cfg.package}/sbin/swanctl --reload";
Restart = "on-abnormal";
};
};
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# In the following context a parameter is an attribute set that
# contains a NixOS option and a render function. It also contains the
# attribute: '_type = "param"' so we can distinguish it from other
# sets.
#
# The render function is used to convert the value of the option to a
# snippet of strongswan.conf. Most parameters simply render their
# value to a string. For example, take the following parameter:
#
# threads = mkIntParam 10 "Threads to use for request handling.";
#
# When a users defines the corresponding option as for example:
#
# services.strongswan-swanctl.strongswan.threads = 32;
#
# It will get rendered to the following snippet in strongswan.conf:
#
# threads = 32
#
# Some parameters however need to be able to change the attribute
# name. For example, take the following parameter:
#
# id = mkPrefixedAttrsOfParam (mkOptionalStrParam "") "...";
#
# A user can define the corresponding option as for example:
#
# id = {
# "foo" = "bar";
# "baz" = "qux";
# };
#
# This will get rendered to the following snippet:
#
# foo-id = bar
# baz-id = qux
#
# For this reason the render function is not simply a function from
# value -> string but a function from a value to an attribute set:
# { "${name}" = string }. This allows parameters to change the attribute
# name like in the previous example.

lib :

with lib;
with (import ./param-lib.nix lib);

rec {
mkParamOfType = type : strongswanDefault : description : {
_type = "param";
option = mkOption {
type = types.nullOr type;
default = null;
description = documentDefault description strongswanDefault;
};
render = single toString;
};

documentDefault = description : strongswanDefault :
if isNull strongswanDefault
then description
else description + ''
</para><para>
StrongSwan default: <literal><![CDATA[${builtins.toJSON strongswanDefault}]]></literal>
'';

single = f: name: value: { "${name}" = f value; };

mkStrParam = mkParamOfType types.str;
mkOptionalStrParam = mkStrParam null;

mkEnumParam = values : mkParamOfType (types.enum values);

mkIntParam = mkParamOfType types.int;
mkOptionalIntParam = mkIntParam null;

# We should have floats in Nix...
mkFloatParam = mkStrParam;

# TODO: Check for hex format:
mkHexParam = mkStrParam;
mkOptionalHexParam = mkOptionalStrParam;

# TODO: Check for duration format:
mkDurationParam = mkStrParam;
mkOptionalDurationParam = mkOptionalStrParam;

mkYesNoParam = strongswanDefault : description : {
_type = "param";
option = mkOption {
type = types.nullOr types.bool;
default = null;
description = documentDefault description strongswanDefault;
};
render = single (b: if b then "yes" else "no");
};
yes = true;
no = false;

mkSpaceSepListParam = mkSepListParam " ";
mkCommaSepListParam = mkSepListParam ",";

mkSepListParam = sep : strongswanDefault : description : {
_type = "param";
option = mkOption {
type = types.nullOr (types.listOf types.str);
default = null;
description = documentDefault description strongswanDefault;
};
render = single (value: concatStringsSep sep value);
};

mkAttrsOfParams = params :
mkAttrsOf params (types.submodule {options = paramsToOptions params;});

mkAttrsOfParam = param :
mkAttrsOf param param.option.type;

mkAttrsOf = param : option : description : {
_type = "param";
option = mkOption {
type = types.attrsOf option;
default = {};
inherit description;
};
render = single (attrs:
(paramsToRenderedStrings attrs
(mapAttrs (_n: _v: param) attrs)));
};

mkPrefixedAttrsOfParams = params :
mkPrefixedAttrsOf params (types.submodule {options = paramsToOptions params;});

mkPrefixedAttrsOfParam = param :
mkPrefixedAttrsOf param param.option.type;

mkPrefixedAttrsOf = p : option : description : {
_type = "param";
option = mkOption {
type = types.attrsOf option;
default = {};
inherit description;
};
render = prefix: attrs:
let prefixedAttrs = mapAttrs' (name: nameValuePair "${prefix}-${name}") attrs;
in paramsToRenderedStrings prefixedAttrs
(mapAttrs (_n: _v: p) prefixedAttrs);
};

mkPostfixedAttrsOfParams = params : description : {
_type = "param";
option = mkOption {
type = types.attrsOf (types.submodule {options = paramsToOptions params;});
default = {};
inherit description;
};
render = postfix: attrs:
let postfixedAttrs = mapAttrs' (name: nameValuePair "${name}-${postfix}") attrs;
in paramsToRenderedStrings postfixedAttrs
(mapAttrs (_n: _v: params) postfixedAttrs);
};

}
82 changes: 82 additions & 0 deletions nixos/modules/services/networking/strongswan-swanctl/param-lib.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
lib :

with lib;

rec {
paramsToConf = cfg : ps : mkConf 0 (paramsToRenderedStrings cfg ps);

# mkConf takes an indentation level (which usually starts at 0) and a nested
# attribute set of strings and will render that set to a strongswan.conf style
# configuration format. For example:
#
# mkConf 0 {a = "1"; b = { c = { "foo" = "2"; "bar" = "3"; }; d = "4";};} => ''
# a = 1
# b {
# c {
# foo = 2
# bar = 3
# }
# d = 4
# }''
mkConf = indent : ps :
concatMapStringsSep "\n"
(name:
let value = ps."${name}";
indentation = replicate indent " ";
in
indentation + (
if isAttrs value
then "${name} {\n" +
mkConf (indent + 2) value + "\n" +
indentation + "}"
else "${name} = ${value}"
)
)
(attrNames ps);

replicate = n : c : concatStrings (builtins.genList (_x : c) n);

# `paramsToRenderedStrings cfg ps` converts the NixOS configuration `cfg`
# (typically the "config" argument of a NixOS module) and the set of
# parameters `ps` (an attribute set where the values are constructed using the
# parameter constructors in ./param-constructors.nix) to a nested attribute
# set of strings (rendered parameters).
paramsToRenderedStrings = cfg : ps :
filterEmptySets (
(mapParamsRecursive (path: name: param:
let value = attrByPath path null cfg;
in optionalAttrs (!isNull value) (param.render name value)
) ps));

filterEmptySets = set : filterAttrs (n: v: !(isNull v)) (mapAttrs (name: value:
if isAttrs value
then let value' = filterEmptySets value;
in if value' == {}
then null
else value'
else value
) set);

# Recursively map over every parameter in the given attribute set.
mapParamsRecursive = mapAttrsRecursiveCond' (as: (!(as ? "_type" && as._type == "param")));

mapAttrsRecursiveCond' = cond: f: set:
let
recurse = path: set:
let
g =
name: value:
if isAttrs value && cond value
then { "${name}" = recurse (path ++ [name]) value; }
else f (path ++ [name]) name value;
in mapAttrs'' g set;
in recurse [] set;

mapAttrs'' = f: set:
foldl' (a: b: a // b) {} (map (attr: f attr set.${attr}) (attrNames set));

# Extract the options from the given set of parameters.
paramsToOptions = ps :
mapParamsRecursive (_path: name: param: { "${name}" = param.option; }) ps;

}
Loading