From 2e8711a58820fa84b4a14c6b6e754a614f22bc0e Mon Sep 17 00:00:00 2001 From: Quentin Aristote Date: Sun, 13 Nov 2022 21:21:00 +0100 Subject: use flakes --- flake.lock | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 21 +++++++++++++ tests/configuration.nix | 41 ++++++++++++++++++++++++ tests/run-tests.sh | 2 +- tests/vm.nix | 41 ------------------------ 5 files changed, 147 insertions(+), 42 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 tests/configuration.nix delete mode 100644 tests/vm.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..eb376cd --- /dev/null +++ b/flake.lock @@ -0,0 +1,84 @@ +{ + "nodes": { + "data": { + "inputs": { + "flake-utils": [ + "personal-webpage" + ], + "nixpkgs": [ + "personal-webpage" + ] + }, + "locked": { + "lastModified": 1668340813, + "narHash": "sha256-S3rKgiJqBGsH69zU/A3tlogMC/jpICHtSAzd/CBTVUI=", + "owner": "qaristote", + "repo": "info", + "rev": "946290203abdc6075b01a40672509bbaabd260d5", + "type": "github" + }, + "original": { + "owner": "qaristote", + "repo": "info", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1668266328, + "narHash": "sha256-+nAW+XR8nswyEnt5IkQlkrz9erTcQWBVLkhtNHxckFw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5ca8e2e9e1fa5e66a749b39261ad6bd0e07bc87f", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "personal-webpage": { + "inputs": { + "data": "data", + "flake-utils": "flake-utils", + "nixpkgs": [] + }, + "locked": { + "lastModified": 1668369630, + "narHash": "sha256-aaXUpBgOhMjDYDSsnGs28MExA4o0cXn7tV5ndfxpikU=", + "owner": "qaristote", + "repo": "webpage", + "rev": "b0cb171f641dca185cad98506d6c0e104c67dab0", + "type": "github" + }, + "original": { + "owner": "qaristote", + "repo": "webpage", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "personal-webpage": "personal-webpage" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..d02d308 --- /dev/null +++ b/flake.nix @@ -0,0 +1,21 @@ +{ + inputs.personal-webpage = { + url = "github:qaristote/webpage"; + inputs.nixpkgs.follows = ""; + }; + + outputs = { self, nixpkgs, ... }@attrs: { + nixosConfigurations = { + hermes = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + specialArgs = attrs; + modules = [ ./configuration.nix ]; + }; + hermes-test = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + specialArgs = attrs; + modules = [ ./tests/configuration.nix ]; + }; + }; + }; +} diff --git a/tests/configuration.nix b/tests/configuration.nix new file mode 100644 index 0000000..e878c12 --- /dev/null +++ b/tests/configuration.nix @@ -0,0 +1,41 @@ +{ config, lib, ... }: + +let + nginxPorts = lib.concatLists + (lib.mapAttrsToList (_: cfg: (builtins.map (x: x.port) cfg.listen)) + config.services.nginx.virtualHosts); + nginxMakeLocal = port: { + listen = lib.mkForce [{ + inherit port; + addr = "0.0.0.0"; + }]; + forceSSL = lib.mkForce false; + enableACME = lib.mkForce false; + }; +in { + imports = [ ../configuration.nix ]; + + networking = lib.mkForce { + domain = "aristote.vm"; + + interfaces = { }; + defaultGateway = null; + nameservers = [ ]; + + firewall = { allowedTCPPorts = nginxPorts; }; + }; + + services.filtron.rules = lib.mkForce [ ]; + + services.nginx.virtualHosts = { + quentin = nginxMakeLocal 8080; + searx = nginxMakeLocal 8081; + money = nginxMakeLocal 8082; + rss = nginxMakeLocal 8083; + webkeydirectory = nginxMakeLocal 8084; + }; + + environment.etc."searx/secrets".text = '' + SECRET_KEY=secret_key + ''; +} diff --git a/tests/run-tests.sh b/tests/run-tests.sh index a55e282..b74a6fe 100755 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -8,7 +8,7 @@ function cleanup { } sudo nixos-container stop hermes || exit 2 -sudo nixos-container update hermes --config-file ./vm.nix || exit 2 +sudo nixos-container update hermes --flake ..#hermes-test || exit 2 echo Starting container ... sudo nixos-container start hermes || exit 2 diff --git a/tests/vm.nix b/tests/vm.nix deleted file mode 100644 index e878c12..0000000 --- a/tests/vm.nix +++ /dev/null @@ -1,41 +0,0 @@ -{ config, lib, ... }: - -let - nginxPorts = lib.concatLists - (lib.mapAttrsToList (_: cfg: (builtins.map (x: x.port) cfg.listen)) - config.services.nginx.virtualHosts); - nginxMakeLocal = port: { - listen = lib.mkForce [{ - inherit port; - addr = "0.0.0.0"; - }]; - forceSSL = lib.mkForce false; - enableACME = lib.mkForce false; - }; -in { - imports = [ ../configuration.nix ]; - - networking = lib.mkForce { - domain = "aristote.vm"; - - interfaces = { }; - defaultGateway = null; - nameservers = [ ]; - - firewall = { allowedTCPPorts = nginxPorts; }; - }; - - services.filtron.rules = lib.mkForce [ ]; - - services.nginx.virtualHosts = { - quentin = nginxMakeLocal 8080; - searx = nginxMakeLocal 8081; - money = nginxMakeLocal 8082; - rss = nginxMakeLocal 8083; - webkeydirectory = nginxMakeLocal 8084; - }; - - environment.etc."searx/secrets".text = '' - SECRET_KEY=secret_key - ''; -} -- cgit v1.2.3