-
Notifications
You must be signed in to change notification settings - Fork 222
Add NixOS module, container integration test, and restructure flake #1508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ericson2314
wants to merge
1
commit into
haskell:master
Choose a base branch
from
Ericson2314:nixos-test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+300
−77
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 contains hidden or 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 contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| { withSystem, ... }: | ||
|
|
||
| { | ||
| flake.nixosModules.default = { config, lib, pkgs, ... }: | ||
| let | ||
| pkg = withSystem pkgs.stdenv.hostPlatform.system ({ config, ... }: config.packages.hackage-server); | ||
| in { | ||
| imports = [ ./nixos-module.nix ]; | ||
| services.hackage-server.package = lib.mkDefault pkg; | ||
| services.hackage-server.datafilesDir = lib.mkDefault ( | ||
| # The Cabal data-files are installed under an ABI-specific path | ||
| # like share/ghc-X.Y.Z/<abi-hash>/hackage-server-0.6/ | ||
| # We use a derivation to resolve the glob at build time. | ||
| pkgs.runCommand "hackage-server-datafiles" {} '' | ||
| datadir=$(dirname $(find ${pkg.data}/share -name templates -type d | head -1)) | ||
| if [ -z "$datadir" ]; then | ||
| echo "Could not find hackage-server data files in ${pkg.data}" >&2 | ||
| exit 1 | ||
| fi | ||
| ln -s "$datadir" $out | ||
| '' | ||
| ); | ||
| }; | ||
|
|
||
| perSystem = { system, lib, config, pkgs, ... }: | ||
| { | ||
| checks = lib.optionalAttrs pkgs.stdenv.isLinux { | ||
| nixos-test = import ./test.nix { | ||
| hackage-server = config.packages.hackage-server; | ||
| inherit pkgs; | ||
| }; | ||
| }; | ||
|
|
||
| apps.default.program = pkgs.writeShellApplication { | ||
| name = "run-hackage-server"; | ||
| runtimeInputs = [ config.packages.default ]; | ||
| text = '' | ||
| if [ ! -d "state" ]; then | ||
| hackage-server init --static-dir=datafiles --state-dir=state | ||
| else | ||
| echo "'state' state-dir already exists" | ||
| fi | ||
| hackage-server run \ | ||
| --static-dir=datafiles \ | ||
| --state-dir=state \ | ||
| --base-uri=http://127.0.0.1:8080 \ | ||
| --required-base-host-header=localhost:8080 \ | ||
| --user-content-uri=http://127.0.0.1:8080 | ||
| ''; | ||
| }; | ||
|
|
||
| apps.mirror-hackage-server.program = pkgs.writeShellApplication { | ||
| name = "mirror-hackage-server"; | ||
| runtimeInputs = [ config.packages.default ]; | ||
| text = '' | ||
| echo 'Copying packages from real Hackage Server into local Hackage Server.' | ||
| echo 'This assumes the local Hackage Server uses default credentials;' | ||
| echo 'otherwise, override in nix-default-servers.cfg' | ||
| hackage-mirror nix-default-servers.cfg "$@" | ||
| ''; | ||
| }; | ||
|
|
||
| packages.default = config.packages.hackage-server; | ||
|
|
||
| haskellProjects.default = { | ||
| basePackages = pkgs.haskell.packages.ghc912; | ||
| # Only include files relevant to the Haskell build so that | ||
| # changes to nix/, flake.nix, etc. don't trigger a rebuild. | ||
| projectRoot = lib.fileset.toSource { | ||
| root = ../.; | ||
| fileset = let | ||
| haskell = f: lib.hasSuffix ".hs" f.name; | ||
| in lib.fileset.unions [ | ||
| ../cabal.project | ||
| ../hackage-server.cabal | ||
| ../LICENSE | ||
| (lib.fileset.fileFilter haskell ../src) | ||
| (lib.fileset.fileFilter haskell ../exes) | ||
| (lib.fileset.fileFilter haskell ../benchmarks) | ||
| ../tests # includes .hs, golden files, test tarballs, etc. | ||
| ../datafiles | ||
| ../libstemmer_c | ||
| ../src/Distribution/Server/Util/NLP/LICENSE | ||
| ]; | ||
| }; | ||
| settings = { | ||
| hackage-server.check = false; | ||
|
|
||
| Cabal-syntax = { super, ... }: | ||
| { custom = _: super.Cabal-syntax_3_16_1_0; }; | ||
| Cabal = { super, ... }: | ||
| { custom = _: super.Cabal_3_16_1_0; }; | ||
|
|
||
| sandwich.check = false; | ||
|
|
||
| threads.check = false; | ||
|
|
||
| unicode-data.check = false; | ||
| }; | ||
| packages = { | ||
| # https://community.flake.parts/haskell-flake/dependency#path | ||
| # tls.source = "1.9.0"; | ||
| tar.source = "0.7.0.0"; | ||
| }; | ||
| devShell = { | ||
| tools = hp: { | ||
| inherit (pkgs) | ||
| cabal-install | ||
| ghc | ||
| # https://github.com/haskell/hackage-server/pull/1219#issuecomment-1597140858 | ||
| # glibc | ||
| icu67 | ||
| zlib | ||
| openssl | ||
| # cryptodev | ||
| pkg-config | ||
| brotli | ||
|
|
||
| gd | ||
| libpng | ||
| libjpeg | ||
| fontconfig | ||
| freetype | ||
| expat | ||
| ; | ||
| }; | ||
| hlsCheck.enable = false; | ||
| }; | ||
| }; | ||
| }; | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| { config, lib, pkgs, ... }: | ||
|
|
||
| let | ||
| cfg = config.services.hackage-server; | ||
| pkg = cfg.package; | ||
| in | ||
| { | ||
| options.services.hackage-server = { | ||
| enable = lib.mkEnableOption "hackage-server, a Haskell package repository"; | ||
|
|
||
| package = lib.mkPackageOption pkgs "hackage-server" { }; | ||
|
|
||
| baseUri = lib.mkOption { | ||
| type = lib.types.str; | ||
| example = "https://hackage.example.org"; | ||
| description = "The server's public base URI."; | ||
| }; | ||
|
|
||
| userContentUri = lib.mkOption { | ||
| type = lib.types.str; | ||
| example = "https://hackage-content.example.org"; | ||
| description = '' | ||
| The server's public user content base URI, used for untrusted | ||
| content to defeat XSS-style attacks. | ||
| ''; | ||
| }; | ||
|
|
||
| requiredBaseHostHeader = lib.mkOption { | ||
| type = lib.types.str; | ||
| example = "hackage-origin.example.org"; | ||
| description = '' | ||
| Required Host header value for incoming requests. This may be | ||
| an internal hostname if the server is behind a reverse proxy. | ||
| ''; | ||
| }; | ||
|
|
||
| stateDir = lib.mkOption { | ||
| type = lib.types.path; | ||
| default = "/var/lib/hackage-server"; | ||
| description = "Directory for the server's persistent state."; | ||
| }; | ||
|
|
||
| datafilesDir = lib.mkOption { | ||
| type = lib.types.path; | ||
| description = '' | ||
| Directory containing HTML templates, static files, and TUF keys. | ||
| ''; | ||
| }; | ||
|
|
||
| port = lib.mkOption { | ||
| type = lib.types.port; | ||
| default = 8080; | ||
| description = "TCP port to listen on."; | ||
| }; | ||
|
|
||
| ip = lib.mkOption { | ||
| type = lib.types.str; | ||
| default = "127.0.0.1"; | ||
| description = "IPv4 address to bind."; | ||
| }; | ||
|
|
||
| user = lib.mkOption { | ||
| type = lib.types.str; | ||
| default = "hackage"; | ||
| description = "User account under which hackage-server runs."; | ||
| }; | ||
|
|
||
| group = lib.mkOption { | ||
| type = lib.types.str; | ||
| default = "hackage"; | ||
| description = "Group under which hackage-server runs."; | ||
| }; | ||
| }; | ||
|
|
||
| config = lib.mkIf cfg.enable { | ||
|
|
||
| users.users.${cfg.user} = { | ||
| isSystemUser = true; | ||
| group = cfg.group; | ||
| home = cfg.stateDir; | ||
| description = "Hackage Server service user"; | ||
| }; | ||
|
|
||
| users.groups.${cfg.group} = { }; | ||
|
|
||
| systemd.tmpfiles.rules = [ | ||
| "d ${cfg.stateDir} 0750 ${cfg.user} ${cfg.group} -" | ||
| "d ${cfg.stateDir}/state 0750 ${cfg.user} ${cfg.group} -" | ||
| ]; | ||
|
|
||
| systemd.services.hackage-server = { | ||
| description = "Hackage Server"; | ||
| after = [ "network-online.target" ]; | ||
| wants = [ "network-online.target" ]; | ||
| wantedBy = [ "multi-user.target" ]; | ||
|
|
||
| preStart = '' | ||
| if [ ! -d "${cfg.stateDir}/state/db" ]; then | ||
| ${lib.getExe pkg} init \ | ||
| --state-dir="${cfg.stateDir}/state" \ | ||
| --static-dir="${cfg.datafilesDir}" | ||
| fi | ||
| ''; | ||
|
|
||
| serviceConfig = { | ||
| Type = "simple"; | ||
| User = cfg.user; | ||
| Group = cfg.group; | ||
| Restart = "on-failure"; | ||
| RestartSec = 3; | ||
| TimeoutStopSec = 120; | ||
| LimitNOFILE = 1073741824; | ||
| WorkingDirectory = cfg.stateDir; | ||
|
|
||
| ExecStart = lib.concatStringsSep " " [ | ||
| (lib.getExe pkg) | ||
| "run" | ||
| "--ip=${cfg.ip}" | ||
| "--port=${toString cfg.port}" | ||
| "--base-uri=${cfg.baseUri}" | ||
| "--user-content-uri=${cfg.userContentUri}" | ||
| "--required-base-host-header=${cfg.requiredBaseHostHeader}" | ||
| "--state-dir=${cfg.stateDir}/state" | ||
| "--static-dir=${cfg.datafilesDir}" | ||
| "--tmp-dir=${cfg.stateDir}/state/tmp" | ||
| ]; | ||
| }; | ||
| }; | ||
| }; | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| { hackage-server, pkgs, ... }: | ||
|
|
||
| pkgs.testers.runNixOSTest { | ||
| name = "hackage-server"; | ||
|
|
||
| containers.machine = { pkgs, ... }: { | ||
| imports = [ ./nixos-module.nix ]; | ||
|
|
||
| services.hackage-server = { | ||
| enable = true; | ||
| package = hackage-server; | ||
| datafilesDir = pkgs.runCommand "hackage-server-datafiles" {} '' | ||
| datadir=$(dirname $(find ${hackage-server.data}/share -name templates -type d | head -1)) | ||
| ln -s "$datadir" $out | ||
| ''; | ||
| baseUri = "http://localhost:8080"; | ||
| userContentUri = "http://localhost:8080"; | ||
| requiredBaseHostHeader = "localhost:8080"; | ||
| port = 8080; | ||
| }; | ||
|
|
||
| environment.systemPackages = [ pkgs.curl ]; | ||
| }; | ||
|
|
||
| testScript = '' | ||
| machine.start() | ||
| machine.wait_for_unit("hackage-server.service") | ||
| machine.wait_for_open_port(8080) | ||
|
|
||
| # Smoke test | ||
| machine.succeed("curl -fsS --max-time 10 http://localhost:8080/") | ||
| machine.succeed("curl -fsS --max-time 10 http://localhost:8080/users/.json") | ||
| ''; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR. Some feedback: why remove this? We have an account on
cachixfor this