Use the "assertions" option instead of mkAssert

This commit is contained in:
Eelco Dolstra
2013-10-30 18:47:44 +01:00
parent c7171b2c8f
commit 244cf195c8
5 changed files with 52 additions and 40 deletions
@@ -24,12 +24,12 @@ with pkgs.lib;
};
listenAddress = mkOption {
default = null;
default = null;
description = "IP address to listen on.";
};
port = mkOption {
default = 8080;
default = 8080;
description = "port to listen on.";
};
@@ -45,9 +45,12 @@ with pkgs.lib;
###### implementation
config = mkIf cfg.enable (
mkAssert (cfg.enable -> cfg.database != "")
"Must specify database name" {
config = mkIf cfg.enable {
assertions = singleton
{ assertion = cfg.enable -> cfg.database != "";
message = "Must specify 4Store database name";
};
users.extraUsers = singleton
{ name = endpointUser;
@@ -63,10 +66,10 @@ with pkgs.lib;
startOn = "filesystem";
exec = ''
${run} '${pkgs.rdf4store}/bin/4s-httpd -D ${cfg.options} ${if cfg.listenAddress!=null then "-H ${cfg.listenAddress}" else "" } -p ${toString cfg.port} ${cfg.database}'
${run} '${pkgs.rdf4store}/bin/4s-httpd -D ${cfg.options} ${if cfg.listenAddress!=null then "-H ${cfg.listenAddress}" else "" } -p ${toString cfg.port} ${cfg.database}'
'';
};
});
};
}
+10 -7
View File
@@ -36,9 +36,12 @@ with pkgs.lib;
###### implementation
config = mkIf cfg.enable (
mkAssert (cfg.enable -> cfg.database != "")
"Must specify database name" {
config = mkIf cfg.enable {
assertions = singleton
{ assertion = cfg.enable -> cfg.database != "";
message = "Must specify 4Store database name.";
};
users.extraUsers = singleton
{ name = fourStoreUser;
@@ -56,16 +59,16 @@ with pkgs.lib;
preStart = ''
mkdir -p ${stateDir}/
chown ${fourStoreUser} ${stateDir}
if ! test -e "${stateDir}/${cfg.database}"; then
${run} -c '${pkgs.rdf4store}/bin/4s-backend-setup ${cfg.database}'
if ! test -e "${stateDir}/${cfg.database}"; then
${run} -c '${pkgs.rdf4store}/bin/4s-backend-setup ${cfg.database}'
fi
'';
exec = ''
${run} -c '${pkgs.rdf4store}/bin/4s-backend -D ${cfg.options} ${cfg.database}'
${run} -c '${pkgs.rdf4store}/bin/4s-backend -D ${cfg.options} ${cfg.database}'
'';
};
});
};
}