Created
January 22, 2017 16:27
-
-
Save bennofs/de8098067940142af39971376352913a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ config, lib, pkgs, ... }: | |
with lib; # provides mkOption, types, ... | |
let | |
# this env builds the python interpreter that you want to run your app against | |
env = pkgs.python27.withPackages (ps: [ ps.flask ]); | |
# fetch the source from github | |
src = pkgs.fetchFromGitHub { | |
owner = "pradeepchhetri"; | |
repo = "hello-world"; | |
rev = "master"; | |
sha256 = "1c79svqzp1q740fbprwidsiws3dsiyz3afb039h7q6839b7fj8fw"; | |
}; | |
# pull the values set for the configuration options | |
cfg = config.services.hello-world; | |
in { | |
# define the options that we support | |
options = { | |
services.hello-world = { | |
enable = mkOption { | |
type = types.bool; | |
default = false; | |
description = "Enable exampe web app"; | |
}; | |
port = mkOption { | |
type = types.int; | |
default = 5000; | |
description = "Port to run hello-world app on"; | |
}; | |
host = mkOption { | |
type = types.string; | |
default = "172.0.0.1"; | |
description = "Interface to bind to"; | |
}; | |
}; | |
}; | |
# implementation | |
config = mkIf cfg.enable { # only activate service if enabled | |
systemd.services.hello-world = { | |
description = "Hello world web app"; | |
after = ["network.target"]; | |
wantedBy = ["multi-user.target"]; | |
environment.FLASK_APP = "${src}/hello.py"; | |
script = "${env}/bin/flask run -p ${toString cfg.port} -h ${cfg.host}"; | |
}; | |
networking.firewall.allowedTCPPorts = [ cfg.port ]; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ config, pkgs, lib, ... }: | |
{ | |
imports = [ ./app.nix ]; | |
services.hello-world = { | |
enable = true; | |
port = 80; | |
host = "0.0.0.0"; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment