Last active
June 10, 2019 06:50
-
-
Save YuMingLiao/e36a5e3b33311541d86e8a57bbf5df44 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
{ pkgs ? import <nixpkgs> {}, compiler ? "ghc844" }: | |
pkgs.haskell.packages.${compiler}.callPackage ./hellogce.nix { } |
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
[root@nixos:~/hellogce]# nixops deploy -d formosa-charity > 1 | |
trace: `lib.nixpkgsVersion` is deprecated, use `lib.version` instead! | |
building all machine configurations... | |
warning: dumping very large path (> 256 MiB); this may run out of memory | |
formosa-charity> copying closure... | |
formosa-charity> closures copied successfully | |
formosa-charity> updating GRUB 2 menu... | |
formosa-charity> activating the configuration... | |
formosa-charity> setting up /etc... | |
formosa-charity> reloading user units for root... | |
formosa-charity> setting up tmpfiles | |
formosa-charity> warning: the following units failed: formosa-charity.service | |
formosa-charity> | |
formosa-charity> ● formosa-charity.service - formosa-charity Webserver | |
formosa-charity> Loaded: loaded (/nix/store/v5z9ds473n6zrzv8k2w8whms7p36fr3p-unit-formosa-charity.service/formosa-charity.service; enabled; vendor preset: enabled) | |
formosa-charity> Active: failed (Result: exit-code) since Mon 2019-06-10 05:26:55 UTC; 232ms ago | |
formosa-charity> Process: 8342 ExecStart=/nix/store/d3r079kbwqjzd0w06dix3id9pmm8x5s6-formosa-charity-0.0.0/bin/formosa-charity (code=exited, status=1/FAILURE) | |
formosa-charity> Main PID: 8342 (code=exited, status=1/FAILURE) | |
formosa-charity> | |
formosa-charity> Jun 10 05:26:55 formosa-chairty systemd[1]: Started formosa-charity Webserver. | |
formosa-charity> Jun 10 05:26:55 formosa-chairty formosa-charity[8342]: formosa-charity: static: getDirectoryContents:openDirStream: does not exist (No such file or directory) | |
formosa-charity> Jun 10 05:26:55 formosa-chairty systemd[1]: formosa-charity.service: Main process exited, code=exited, status=1/FAILURE | |
formosa-charity> Jun 10 05:26:55 formosa-chairty systemd[1]: formosa-charity.service: Failed with result 'exit-code'. | |
formosa-charity> error: Traceback (most recent call last): | |
File "/nix/store/sl1gfk7ff7dsa6w9r63pxhsn9vywn28h-nixops-1.6/lib/python2.7/site-packages/nixops/deployment.py", line 731, in worker | |
raise Exception("unable to activate new configuration") | |
Exception: unable to activate new configuration | |
error: activation of 1 of 1 machines failed (namely on ‘formosa-charity’) |
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
{ | |
network.description = "formosa-charity"; | |
formosa-charity = | |
{ config, pkgs, ... }: let | |
formosa-charity = import ./formosa-charity/default.nix { }; | |
in | |
{ networking.hostName = "formosa-chairty"; | |
networking.firewall.allowedTCPPorts = [ 22 80 ]; | |
environment.systemPackages = [ formosa-charity ]; | |
systemd.services.formosa-charity = | |
{ description = "formosa-charity Webserver"; | |
wantedBy = [ "multi-user.target" ]; | |
after = [ "network.target" ]; | |
serviceConfig = | |
{ ExecStart = "${formosa-charity}/bin/formosa-charity"; | |
}; | |
}; | |
}; | |
} |
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
let | |
# change this as necessary or wipe and use ENV vars | |
credentials = { | |
project = "johnny-nixos-cloud"; | |
serviceAccount = "882134740696-compute@developer.gserviceaccount.com"; | |
accessKey = "key.pem"; | |
}; | |
gce = { resources, ...}: { | |
networking.firewall.allowedTCPPorts = [ 80 ]; | |
deployment.targetEnv = "gce"; | |
deployment.gce = credentials // { | |
region = "asia-east1-a"; | |
tags = [ "public-http" ]; | |
rootDiskSize = 10; | |
network = resources.gceNetworks.lb-net; | |
}; | |
}; | |
in { | |
# create a network that allows SSH traffic(by default), pings | |
# and HTTP traffic for machines tagged "public-http" | |
resources.gceNetworks.lb-net = credentials // { | |
addressRange = "192.168.4.0/24"; | |
firewall = { | |
allow-http = { | |
targetTags = [ "public-http" ]; | |
allowed.tcp = [ 80 ]; | |
}; | |
allow-ping.allowed.icmp = null; | |
}; | |
}; | |
# by default, health check pings port 80, so we don't have to set anything | |
/* resources.gceHTTPHealthChecks.plain-hc = credentials; */ | |
formosa-charity = gce; | |
} |
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
-- This file has been generated from package.yaml by hpack version 0.28.2. | |
-- | |
-- see: https://github.com/sol/hpack | |
-- | |
-- hash: fb8443f14c80efe58c5edca745fc5bf213cc223b3ecaab8fecbb9ce48683b019 | |
name: formosa-charity | |
version: 0.0.0 | |
build-type: Simple | |
cabal-version: >= 1.10 | |
flag dev | |
description: Turn on development settings, like auto-reload templates. | |
manual: False | |
default: False | |
flag library-only | |
description: Build for use with "yesod devel" | |
manual: False | |
default: False | |
library | |
exposed-modules: | |
Application | |
Foundation | |
Handler.Admin | |
Handler.Comment | |
Handler.Common | |
Handler.Home | |
Handler.Profile | |
Handler.SignUpForm | |
Import | |
Import.NoFoundation | |
Model | |
Settings | |
Settings.StaticFiles | |
HelloSub | |
HelloSub.Data | |
UserCrud | |
ActivityCrud | |
other-modules: | |
Paths_formosa_charity | |
hs-source-dirs: | |
src | |
build-depends: | |
aeson >=0.6 && <1.4 | |
, base >=4.8.2.0 && <4.9 || >=4.9.1.0 && <5 | |
, bytestring >=0.9 && <0.11 | |
, case-insensitive | |
, classy-prelude >=1.4 | |
-- && <1.5 | |
, classy-prelude-conduit >=1.4 | |
-- && <1.5 | |
, classy-prelude-yesod >=1.4 | |
-- && <1.5 | |
, conduit >=1.0 && <2.0 | |
, containers | |
, data-default | |
, directory >=1.1 && <1.4 | |
, fast-logger >=2.2 && <2.5 | |
, file-embed | |
, foreign-store | |
, hjsmin >=0.1 && <0.3 | |
, http-client-tls >=0.3 && <0.4 | |
, http-conduit >=2.3 && <2.4 | |
, monad-control >=0.3 && <1.1 | |
, monad-logger >=0.3 && <0.4 | |
, persistent >=2.8 && <2.9 | |
, persistent-sqlite >=2.8 && <2.9 | |
, persistent-template >=2.5 && <2.9 | |
, safe | |
, shakespeare >=2.0 && <2.1 | |
, template-haskell | |
, text >=0.11 && <2.0 | |
, time | |
, unordered-containers | |
, vector | |
, wai | |
, wai-extra >=3.0 && <3.1 | |
, wai-logger >=2.2 && <2.4 | |
, warp >=3.0 && <3.3 | |
, yaml >=0.8 && <0.9 | |
, yesod >=1.6 && <1.7 | |
, yesod-auth >=1.6 && <1.7 | |
, yesod-core >=1.6 && <1.7 | |
, yesod-form >=1.6 && <1.7 | |
, yesod-static >=1.6 && <1.7 | |
-- , persistent-project-m36 | |
, project-m36 >= 0.6 | |
, yesod-auth | |
, rio | |
, project-m36-typed | |
-- , uuid | |
, basic-sop | |
, generics-sop | |
, binary | |
, deepseq | |
, QuickCheck | |
, yesod-project-m36 | |
, yesod-auth-fb | |
, yesod-auth-oauth2 | |
, yesod-fb | |
, fb | |
, blaze-builder | |
, blaze-markup | |
, blaze-html | |
, directory | |
, yesod-crud | |
, mtl | |
if (flag(dev)) || (flag(library-only)) | |
ghc-options: -Wall -fwarn-tabs -O0 | |
cpp-options: -DDEVELOPMENT | |
else | |
ghc-options: -Wall -fwarn-tabs -O2 -fprint-potential-instances | |
default-language: Haskell2010 | |
executable formosa-charity | |
main-is: main.hs | |
other-modules: | |
DevelMain | |
Paths_formosa_charity | |
hs-source-dirs: | |
app | |
ghc-options: -threaded -rtsopts -with-rtsopts=-N | |
build-depends: | |
aeson >=0.6 && <1.4 | |
, base >=4.8.2.0 && <4.9 || >=4.9.1.0 && <5 | |
, bytestring >=0.9 && <0.11 | |
, case-insensitive | |
, classy-prelude >=1.4 && <1.5 | |
, classy-prelude-conduit >=1.4 && <1.5 | |
, classy-prelude-yesod >=1.4 && <1.5 | |
, conduit >=1.0 && <2.0 | |
, containers | |
, data-default | |
, directory >=1.1 && <1.4 | |
, fast-logger >=2.2 && <2.5 | |
, file-embed | |
, foreign-store | |
, formosa-charity | |
, hjsmin >=0.1 && <0.3 | |
, http-client-tls >=0.3 && <0.4 | |
, http-conduit >=2.3 && <2.4 | |
, monad-control >=0.3 && <1.1 | |
, monad-logger >=0.3 && <0.4 | |
, persistent >=2.8 && <2.9 | |
, persistent-sqlite >=2.8 && <2.9 | |
, persistent-template >=2.5 && <2.9 | |
, safe | |
, shakespeare >=2.0 && <2.1 | |
, template-haskell | |
, text >=0.11 && <2.0 | |
, time | |
, unordered-containers | |
, vector | |
, wai | |
, wai-extra >=3.0 && <3.1 | |
, wai-logger >=2.2 && <2.4 | |
, warp >=3.0 && <3.3 | |
, yaml >=0.8 && <0.9 | |
, yesod >=1.6 && <1.7 | |
, yesod-auth >=1.6 && <1.7 | |
, yesod-core >=1.6 && <1.7 | |
, yesod-form >=1.6 && <1.7 | |
, yesod-static >=1.6 && <1.7 | |
if flag(library-only) | |
buildable: False | |
default-language: Haskell2010 | |
--test-suite formosa-charity-test | |
-- type: exitcode-stdio-1.0 | |
-- main-is: Spec.hs | |
-- other-modules: | |
-- Handler.CommentSpec | |
-- Handler.CommonSpec | |
-- Handler.HomeSpec | |
-- Handler.ProfileSpec | |
-- TestImport | |
-- Paths_formosa_charity | |
-- hs-source-dirs: | |
-- test | |
-- ghc-options: -Wall | |
-- build-depends: | |
-- aeson >=0.6 && <1.4 | |
-- , base >=4.8.2.0 && <4.9 || >=4.9.1.0 && <5 | |
-- , bytestring >=0.9 && <0.11 | |
-- , case-insensitive | |
-- , classy-prelude >=1.4 && <1.5 | |
-- , classy-prelude-conduit >=1.4 && <1.5 | |
-- , classy-prelude-yesod >=1.4 && <1.5 | |
-- , conduit >=1.0 && <2.0 | |
-- , containers | |
-- , data-default | |
-- , directory >=1.1 && <1.4 | |
-- , fast-logger >=2.2 && <2.5 | |
-- , file-embed | |
-- , foreign-store | |
-- , formosa-charity | |
-- , hjsmin >=0.1 && <0.3 | |
-- , hspec >=2.0.0 | |
-- , http-client-tls >=0.3 && <0.4 | |
-- , http-conduit >=2.3 && <2.4 | |
-- , microlens | |
-- , monad-control >=0.3 && <1.1 | |
-- , monad-logger >=0.3 && <0.4 | |
-- , persistent >=2.8 && <2.9 | |
-- , persistent-sqlite >=2.8 && <2.9 | |
-- , persistent-template >=2.5 && <2.9 | |
-- , safe | |
-- , shakespeare >=2.0 && <2.1 | |
-- , template-haskell | |
-- , text >=0.11 && <2.0 | |
-- , time | |
-- , unordered-containers | |
-- , vector | |
-- , wai | |
-- , wai-extra >=3.0 && <3.1 | |
-- , wai-logger >=2.2 && <2.4 | |
-- , warp >=3.0 && <3.3 | |
-- , yaml >=0.8 && <0.9 | |
-- , yesod >=1.6 && <1.7 | |
-- , yesod-auth >=1.6 && <1.7 | |
-- , yesod-core >=1.6 && <1.7 | |
-- , yesod-form >=1.6 && <1.7 | |
-- , yesod-static >=1.6 && <1.7 | |
-- , yesod-test | |
-- default-language: Haskell2010 |
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
{ mkDerivation, aeson, base, basic-sop, binary, blaze-builder | |
, blaze-html, blaze-markup, bytestring, case-insensitive | |
, classy-prelude, classy-prelude-conduit, classy-prelude-yesod | |
, conduit, containers, data-default, deepseq, directory | |
, fast-logger, fb, file-embed, foreign-store, generics-sop, hjsmin | |
, http-client-tls, http-conduit, monad-control, monad-logger, mtl | |
, persistent, persistent-sqlite, persistent-template, project-m36 | |
, project-m36-typed, QuickCheck, rio, safe, shakespeare, stdenv | |
, template-haskell, text, time, unordered-containers, vector, wai | |
, wai-extra, wai-logger, warp, yaml, yesod, yesod-auth | |
, yesod-auth-fb, yesod-auth-oauth2, yesod-core, yesod-crud | |
, yesod-fb, yesod-form, yesod-project-m36, yesod-static | |
}: | |
mkDerivation { | |
pname = "formosa-charity"; | |
version = "0.0.0"; | |
src = ./.; | |
isLibrary = true; | |
isExecutable = true; | |
libraryHaskellDepends = [ | |
aeson base basic-sop binary blaze-builder blaze-html blaze-markup | |
bytestring case-insensitive classy-prelude classy-prelude-conduit | |
classy-prelude-yesod conduit containers data-default deepseq | |
directory fast-logger fb file-embed foreign-store generics-sop | |
hjsmin http-client-tls http-conduit monad-control monad-logger mtl | |
persistent persistent-sqlite persistent-template project-m36 | |
project-m36-typed QuickCheck rio safe shakespeare template-haskell | |
text time unordered-containers vector wai wai-extra wai-logger warp | |
yaml yesod yesod-auth yesod-auth-fb yesod-auth-oauth2 yesod-core | |
yesod-crud yesod-fb yesod-form yesod-project-m36 yesod-static | |
]; | |
executableHaskellDepends = [ | |
aeson base bytestring case-insensitive classy-prelude | |
classy-prelude-conduit classy-prelude-yesod conduit containers | |
data-default directory fast-logger file-embed foreign-store hjsmin | |
http-client-tls http-conduit monad-control monad-logger persistent | |
persistent-sqlite persistent-template safe shakespeare | |
template-haskell text time unordered-containers vector wai | |
wai-extra wai-logger warp yaml yesod yesod-auth yesod-core | |
yesod-form yesod-static | |
]; | |
license = stdenv.lib.licenses.unfree; | |
hydraPlatforms = stdenv.lib.platforms.none; | |
} |
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
# ~/hellogce/hellogce-configuration.nix | |
{ | |
network.description = "hellogce"; | |
hellogce = | |
{ config, pkgs, ... }: let | |
hellogce = import ./hellogce/default.nix { inherit pkgs; }; | |
in | |
{ networking.hostName = "hellogce"; | |
networking.firewall.allowedTCPPorts = [ 22 80 ]; | |
environment.systemPackages = [ hellogce ]; | |
systemd.services.hellogce = | |
{ description = "hellogce Webserver"; | |
wantedBy = [ "multi-user.target" ]; | |
after = [ "network.target" ]; | |
serviceConfig = | |
{ ExecStart = "${hellogce}/bin/hellogce"; | |
}; | |
}; | |
}; | |
} |
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
let | |
# change this as necessary or wipe and use ENV vars | |
credentials = { | |
project = "johnny-nixos-cloud"; | |
serviceAccount = "882134740696-compute@developer.gserviceaccount.com"; | |
accessKey = "key.pem"; | |
}; | |
gce = { resources, ...}: { | |
networking.firewall.allowedTCPPorts = [ 80 ]; | |
deployment.targetEnv = "gce"; | |
deployment.gce = credentials // { | |
region = "asia-east1-a"; | |
tags = [ "public-http" ]; | |
rootDiskSize = 50; | |
network = resources.gceNetworks.lb-net; | |
}; | |
}; | |
in { | |
# create a network that allows SSH traffic(by default), pings | |
# and HTTP traffic for machines tagged "public-http" | |
resources.gceNetworks.lb-net = credentials // { | |
addressRange = "192.168.4.0/24"; | |
firewall = { | |
allow-http = { | |
targetTags = [ "public-http" ]; | |
allowed.tcp = [ 80 ]; | |
}; | |
allow-ping.allowed.icmp = null; | |
}; | |
}; | |
# by default, health check pings port 80, so we don't have to set anything | |
/* resources.gceHTTPHealthChecks.plain-hc = credentials; */ | |
hellogce = gce; | |
} |
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
-- Initial hellogce.cabal generated by cabal init. For further | |
-- documentation, see http://haskell.org/cabal/users-guide/ | |
name: hellogce | |
version: 0.1.0.0 | |
synopsis: deploying a simple haskell project to GCE by nixops | |
-- description: | |
license: GPL-3 | |
license-file: LICENSE | |
author: Yu-Ming Liao | |
maintainer: dycan0716@gmail.com | |
-- copyright: | |
category: Web | |
build-type: Simple | |
extra-source-files: ChangeLog.md | |
cabal-version: >=1.10 | |
executable hellogce | |
main-is: Main.hs | |
-- other-modules: | |
-- other-extensions: | |
build-depends: base >=4.11 && <4.12 | |
, yesod | |
, yesod-auth | |
, data-default | |
, http-conduit | |
, text | |
hs-source-dirs: src | |
default-language: Haskell2010 |
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
{ mkDerivation, base, data-default, http-conduit, stdenv, text | |
, yesod, yesod-auth | |
}: | |
mkDerivation { | |
pname = "hellogce"; | |
version = "0.1.0.0"; | |
src = ./.; | |
isLibrary = false; | |
isExecutable = true; | |
executableHaskellDepends = [ | |
base data-default http-conduit text yesod yesod-auth | |
]; | |
description = "deploying a simple haskell project to GCE by nixops"; | |
license = stdenv.lib.licenses.gpl3; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment