From 6adfa8034bdf2cafc81c77fb412d0857f09731ee Mon Sep 17 00:00:00 2001 From: Chris Martin Date: Wed, 17 Jan 2024 19:45:09 -0700 Subject: [PATCH] add nixos module (#22) --- main/flake.lock | 17 +++++++++++++++++ main/flake.nix | 9 ++++++--- main/nixos-modules.nix | 31 +++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 main/nixos-modules.nix diff --git a/main/flake.lock b/main/flake.lock index 42b1355..add0d00 100644 --- a/main/flake.lock +++ b/main/flake.lock @@ -18,6 +18,22 @@ "type": "github" } }, + "nixpkgs-22-11": { + "locked": { + "lastModified": 1688392541, + "narHash": "sha256-lHrKvEkCPTUO+7tPfjIcb7Trk6k31rz18vkyqmkeJfY=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "ea4c80b39be4c09702b0cb3b42eab59e2ba4f24b", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-22.11", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs-23-05": { "locked": { "lastModified": 1701362232, @@ -133,6 +149,7 @@ "root": { "inputs": { "flake-utils": "flake-utils", + "nixpkgs-22-11": "nixpkgs-22-11", "nixpkgs-23-05": "nixpkgs-23-05", "nixpkgs-master-2023-05-06": "nixpkgs-master-2023-05-06", "nixpkgs-master-2023-07-18": "nixpkgs-master-2023-07-18", diff --git a/main/flake.nix b/main/flake.nix index 59d0800..14af248 100644 --- a/main/flake.nix +++ b/main/flake.nix @@ -1,6 +1,7 @@ { inputs = { nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-23.11"; + nixpkgs-22-11.url = "github:nixos/nixpkgs/nixos-22.11"; nixpkgs-23-05.url = "github:nixos/nixpkgs/nixos-23.05"; nixpkgs-stable-2023-07-25.url = "github:nixos/nixpkgs/6dc93f0daec55ee2f441da385aaf143863e3d671"; nixpkgs-master-2023-05-06.url = "github:nixos/nixpkgs/16b3b0c53b1ee8936739f8c588544e7fcec3fc60"; @@ -10,11 +11,13 @@ flake-utils.url = "github:numtide/flake-utils"; }; outputs = inputs: - inputs.flake-utils.lib.eachDefaultSystem (system: + (inputs.flake-utils.lib.eachDefaultSystem (system: rec { packages = import ./packages.nix { inherit inputs system; }; lib = import ./lib.nix { inherit inputs system packages; }; checks = import ./checks.nix { inherit inputs system packages lib; }; - } - ); + }) + ) // { + nixosModules = import ./nixos-modules.nix { inherit inputs; }; + }; } diff --git a/main/nixos-modules.nix b/main/nixos-modules.nix new file mode 100644 index 0000000..0a17189 --- /dev/null +++ b/main/nixos-modules.nix @@ -0,0 +1,31 @@ +{ inputs }: +{ + docker-for-local-dev = + { config, ... }: + let + pkgs = import inputs.nixpkgs-22-11 { inherit (config.nixpkgs) system; }; + in + { + # Enable Docker + virtualisation.docker.enable = true; + + # Allow Docker to see the host + networking.firewall.allowedTCPPorts = [ 3000 ]; + + # Pretend that localhost.com is a domain that points to our own machine + networking.extraHosts = '' + 127.0.0.1 localhost.com + 127.0.0.1 api.localhost.com + 127.0.0.1 assets.localhost.com + 127.0.0.1 classroom.localhost.com + 127.0.0.1 school.localhost.com + 127.0.0.1 student.localhost.com + 127.0.0.1 console.localhost.com + 127.0.0.1 faktory.localhost.com + 127.0.0.1 tts.localhost.com + 127.0.0.1 sso.localhost.com + ''; + + virtualisation.docker.package = pkgs.docker; + }; +}