Skip to content
Closed
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
26 changes: 25 additions & 1 deletion lib/attrsets.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ rec {
then attrByPath (tail attrPath) default e.${attr}
else default;


/* Return if an attribute from nested attribute set exists.
For instance ["x" "y"] applied to some set e returns true, if e.x.y exists. False
is returned otherwise. */
Expand All @@ -36,13 +37,36 @@ rec {


/* Return nested attribute set in which an attribute is set. For instance
["x" "y"] applied with some value v returns `x.y = v;' */
["x" "y"] applied with some value v returns `x.y = v;'
If you want to update a value in an existing attrset, use setAttrInSetByPath. */
setAttrByPath = attrPath: value:
if attrPath == [] then value
else listToAttrs
[ { name = head attrPath; value = setAttrByPath (tail attrPath) value; } ];


/* Update attribute in set described by attrPath with value. If the attribute
doesn’t exist, it is created.
For instance, setAttrInSetByPath [ "x" "y" ] 5 { x.y = 3; } returns { x.y = 5; }
The function name was chosen because from setAttrByPath is already taken. */
setAttrInSetByPath = attrPath: value: set:
if attrPath == [] then value
else set // {
${head attrPath} = let new = set.${head attrPath} or {}; in
setAttrInSetByPath (tail attrPath) value (optionalAttrs (isAttrs new) new);
};


/* Apply function f over the value of the attribute described by attrPath.
For instance, updateAttrByPath [ "x" "y" ] (a: a+1) 0 { x.y = 1; } returns
{ x.y = 2; }. If the path doesn’t exist the default value is used. */
updateAttrByPath = attrPath: f: default: e:
(setAttrInSetByPath attrPath
(f (attrByPath attrPath default e))
e);


/* Like attrByPath, but aborts if the attribute is missing. */
getAttrFromPath = attrPath: set:
let errorMsg = "cannot find attribute `" + concatStringsSep "." attrPath + "'";
in attrByPath attrPath (abort errorMsg) set;
Expand Down
25 changes: 25 additions & 0 deletions lib/tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,29 @@ runTests {
expected = false;
};

testSetAttrInSetByPathInsert = {
expr = setAttrInSetByPath ["a" "b"] 42 {};
expected = { a.b = 42; };
};

testSetAttrInSetByPathExisting = {
expr = setAttrInSetByPath ["a" "b"] 42 { a.b = 41; foo = "bar"; };
expected = { a.b = 42; foo = "bar"; };
};

testSetAttrInSetAttrByPathShorterPath = {
expr = setAttrInSetByPath ["a" "b"] 42 { a = 2; };
expected = { a.b = 42; };
};

testUpdateAttrByPath = {
expr = updateAttrByPath ["a" "b"] (a: a+1) 0 { a.b = 41; };
expected = { a.b = 42; };
};

testUpdateAttrByPathDefault = {
expr = updateAttrByPath ["a" "b"] (a: a+1) 41 {};
expected = { a.b = 42; };
};

}
2 changes: 2 additions & 0 deletions nixos/modules/misc/ids.nix
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@
pdnsd = 229;
octoprint = 230;
avahi-autoipd = 231;
isso = 232;

# When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!

Expand Down Expand Up @@ -481,6 +482,7 @@
cfdyndns = 227;
pdnsd = 229;
octoprint = 230;
isso = 232;

# When adding a gid, make sure it doesn't match an existing
# uid. Users and groups with the same name should have equal
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 @@ -423,6 +423,7 @@
./services/ttys/agetty.nix
./services/ttys/gpm.nix
./services/ttys/kmscon.nix
./services/web-apps/isso.nix
./services/web-apps/pump.io.nix
./services/web-servers/apache-httpd/default.nix
./services/web-servers/fcgiwrap.nix
Expand Down
111 changes: 111 additions & 0 deletions nixos/modules/services/web-apps/isso.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{ lib, config, pkgs, ... }:

with lib;

let
cfg = config.services.isso;

user = "isso";
desc = "Isso commenting server";
home = "/var/lib/isso";
db = "${home}/comments.db";

sectEsc = escape [ "[" "]" ];
keyEsc = escape [ "=" ];
# TODO: assert that the above escapes are not used
mkSection = sect: attrs: ''
[${sect}]
${concatStringsSep "\n" (mapAttrsToList (key: val: ''
${key} = ${val}
'') attrs)}
'';

mergedConfig = cfg.config.otherConfig
// { general.host = concatStringsSep "\n " cfg.config.general.host; };
generatedConfig = mapAttrsToList mkSection mergedConfig;
configFile = pkgs.writeText "isso.cfg" (concatStringsSep "\n" generatedConfig);

in
{
options = {
services.isso = with types; {

enable = mkEnableOption "the ${desc}";

config = mkOption {
description = ''
Isso INI-style configuration.
'';
type = submodule ({ options = {

general = mkOption {
description = "Isso [general] section.";
type = submodule ({ options = {
host = mkOption {
type = listOf str;
description = ''
Websites isso should respond to. Non-empty.
'';
example = [ "localhost" "example.com" ];
default = [];
};
};});
default = {};
};

otherConfig = mkOption {
type = attrsOf (attrsOf str);
description = ''
Attribute set converted to INI; more specific options
overwrite the contents of this set.
'';
example = {
server.listen = "localhost:8080";
general.log-file = "${home}/isso.log";
};
default = {
general.dbpath = db;
};
};

};});
};
};
};


config = mkIf cfg.enable {

assertions = [
{ assertion = cfg.config.general.host != [];
message = "host must not be empty"; }
];

systemd.services.isso = {
description = desc;
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
restartIfChanged = true;

serviceConfig = {
# TODO: wsgi support
ExecStart = ''
${pkgs.pythonPackages.isso}/bin/isso -c "${configFile}" run
'';
User = user;
Group = user;
PrivateTmp = true;
};
};

users.users.isso = {
description = desc;
group = user;
uid = config.ids.uids.isso;
home = home;
createHome = true;
};
users.groups.isso.gid = config.ids.gids.isso;

};
}
2 changes: 2 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9550,6 +9550,8 @@ let

ircdHybrid = callPackage ../servers/irc/ircd-hybrid { };

isso = pythonPackages.isso;

jboss = callPackage ../servers/http/jboss { };

jboss_mysql_jdbc = callPackage ../servers/http/jboss/jdbc/mysql { };
Expand Down
59 changes: 59 additions & 0 deletions pkgs/top-level/python-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5945,6 +5945,34 @@ in modules // {
};
};

isso = buildPythonPackage rec {
name = "isso-${meta.version}";

src = pkgs.fetchurl {
url = "https://pypi.python.org/packages/source/i/isso/isso-${meta.version}.tar.gz";
sha256 = "1dyz4745fn4vrpl3brsvvq9lv0ikr6lippz31yzpmlr2ndjx231w";
};

outputs = [ "out" "js" ];

preInstall = ''
mkdir -p $js
mv ./isso/js/* $js
rmdir ./isso/js
'';

propagatedBuildInputs = with self; [ html5lib itsdangerous misaka1 configparser ipaddr werkzeug sqlite3 ];


meta = {
description = "Lightweight Disqus alternative";
homepage = "https://posativ.org/isso/";
version = "0.9.10";
maintainers = with maintainers; [ profpatsch ];
license = licenses.mit;
};
};

itsdangerous = buildPythonPackage rec {
name = "itsdangerous-0.24";

Expand Down Expand Up @@ -11573,6 +11601,37 @@ in modules // {
};
};

misaka =
let misakaPkg = version: sha:
buildPythonPackage rec {
name = "misaka-${meta.version}";

src = pkgs.fetchFromGitHub {
owner = "FSX";
repo = "misaka";
rev = "v${version}";
sha256 = sha;
};

propagatedBuildInputs = with self; [ cffi ];

doCheck = false;

meta = {
description = "A Python binding for Hoedown";
homepage = "http://misaka.61924.nl/";
version = version;
maintainer = with maintainers; [ profpatsch ];
license = licenses.mit;
};
};
in {
misaka1 = misakaPkg "1.0.2" "15w3l3k6fpyg7vpijwrbjya18g4a72xc9i26ghll7pv7pdklaxfs";
misaka2 = misakaPkg "2.0.0" "01fhj8bvbics2hanagyk7n95fhmw9cawhb92x0jc0sqp8nvm9cbv";
};

inherit (self.misaka) misaka1 misaka2;

munch = buildPythonPackage rec {
name = "munch-${version}";
version = "2.0.4";
Expand Down