From fb4d9559017ce008a16646f367b80c1b56f6d5bd Mon Sep 17 00:00:00 2001 From: Daniel Wheeler Date: Thu, 3 Aug 2023 15:04:13 -0400 Subject: [PATCH] build(nix): implement docker build using nix --- flake.nix | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index 57732b238..99894478d 100644 --- a/flake.nix +++ b/flake.nix @@ -28,17 +28,32 @@ pkgs_old = nixpkgs_old.legacyPackages.${system}; pypkgs = pkgs.python3Packages; pfhub_ = pfhub.packages.${system}.pfhub; + USER = "main"; + REPOPATH = "https://github.com/usnistgov/pfhub"; - env = pkgs.mkShell rec { - packages = with pypkgs; [ + pythonEnv = pkgs.python3.buildEnv.override { + extraLibs = with pypkgs; [ pfhub_ jupytext papermill - pkgs_old.rubyPackages.github-pages - pkgs.nodePackages.surge pypkgs.python + jupyterlab + ipython + notebook + ipykernel pykwalify ]; + }; + + rubyEnv = pkgs_old.ruby.withPackages (ps: with ps; [pkgs_old.rubyPackages.github-pages ]); + + env = pkgs.mkShell rec { + + packages = [ + pythonEnv + rubyEnv + pkgs.nodePackages.surge + ]; shellHook = '' @@ -55,11 +70,64 @@ ''; }; + + dockerImage = pkgs.dockerTools.buildImage { + name = "wd15/pfhub"; + tag = "latest"; + + copyToRoot = pkgs.buildEnv { + name = "image-root"; + paths = [ + pythonEnv + rubyEnv + pkgs.bash + pkgs.coreutils + pkgs.openssh + pkgs.bashInteractive + pkgs.git + pkgs.cacert + pkgs.nodejs + ]; + pathsToLink = [ "/bin" ]; + }; + + runAsRoot = '' + #!${pkgs.stdenv.shell} + ${pkgs.dockerTools.shadowSetup} + groupadd --system --gid 65543 ${USER} + useradd --system --uid 65543 --gid 65543 -d / -s /sbin/nologin ${USER} + ''; + + extraCommands = '' + mkdir -m 1777 ./tmp + mkdir -m 777 -p ./home/${USER} + ''; + + config = { + Cmd = [ + "bash" + "-c" + "git clone ${REPOPATH}; bash" + ]; + User = USER; + Env = [ + "OMPI_MCA_plm_rsh_agent=${pkgs.openssh}/bin/ssh" + "HOME=/home/${USER}" + "SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt" + ]; + WorkingDir = "/home/${USER}"; + Expose = { + "8888/tcp" = {}; + }; + }; + }; + in { devShells.default = env; packages.pfhub = env; packages.default = self.packages.${system}.pfhub; + packages.docker = dockerImage; } )); }