diff --git a/flake.nix b/flake.nix index 37bc0df..5b1ae64 100644 --- a/flake.nix +++ b/flake.nix @@ -9,29 +9,35 @@ }; outputs = {nixpkgs, flake-utils, pip2nix, ...}: - flake-utils.lib.eachDefaultSystem (system: - let - pkgs = import nixpkgs { - inherit system; - overlays = [ - (import ./python-overlay.nix) - (import ./overlay.nix) + let + pkgs = system: import nixpkgs { + inherit system; + overlays = [ + (import ./python-overlay.nix) + (import ./overlay.nix) + ]; + }; + packages = flake-utils.lib.eachDefaultSystem (system: rec { + devEnv = pkgs.buildEnv { + name = "erpnext-nix-dev-env"; + paths = [ + pkgs.dasel ]; }; - in rec { - packages = { - devEnv = pkgs.buildEnv { - name = "erpnext-nix-dev-env"; - paths = [ - pkgs.dasel - ]; - }; - inherit pkgs; - run-erpnext = pkgs.run-erpnext; - pip2nix = import "${pip2nix}/default.nix" { inherit pkgs; pythonPackages = "python310Packages"; }; - erpnext = pkgs.python3.pkgs.erpnext; - bench = pkgs.python3.pkgs.bench; - pythonPkgs = pkgs.python3.pkgs; + inherit pkgs; + run-erpnext = pkgs.run-erpnext; + pip2nix = import "${pip2nix}/default.nix" { inherit pkgs; pythonPackages = "python310Packages"; }; + erpnext = pkgs.python3.pkgs.erpnext; + bench = pkgs.python3.pkgs.bench; + pythonPkgs = pkgs.python3.pkgs; + }); + nixosConfigurations = { + test-vm = nixpkgs.lib.nixosSystem { + pkgs = pkgs "x86_64-linux"; + system = "x86_64-linux"; + modules = [./test-vm/configuration.nix]; }; - }); + }; + in {inherit packages nixosConfigurations;}; + } diff --git a/test-vm/configuration.nix b/test-vm/configuration.nix new file mode 100644 index 0000000..202fbdf --- /dev/null +++ b/test-vm/configuration.nix @@ -0,0 +1,132 @@ +{ pkgs, lib, config, modulesPath, ... }: +with lib; +{ + imports = [ + "${modulesPath}/profiles/minimal.nix" + "${modulesPath}/profiles/qemu-guest.nix" + "${modulesPath}/virtualisation/qemu-vm.nix" + ]; + + config = { + services.qemuGuest.enable = true; + + fileSystems."/" = { + device = "/dev/disk/by-label/nixos"; + fsType = "ext4"; + autoResize = true; + }; + + boot = { + growPartition = true; + loader.timeout = 5; + }; + + virtualisation = { + diskSize = 8000; # MB + memorySize = 2048; # MB + + # We don't want to use tmpfs, otherwise the nix store's size will be bounded + # by a fraction of available RAM. + writableStoreUseTmpfs = false; + }; + + # So that we can ssh into the VM, see e.g. + # http://blog.patapon.info/nixos-local-vm/#accessing-the-vm-with-ssh + services.openssh.enable = true; + services.openssh.settings.PermitRootLogin = "yes"; + # Give root an empty password to ssh in. + users.extraUsers.root.password = ""; + users.mutableUsers = false; + + environment.systemPackages = with pkgs; [ + git + htop + neovim + ]; + + services.mysql = { + enable = true; + package = pkgs.mariadb; + }; + + services.redis.servers = { + # Queue, naming it "" makes it use default values. + "".enable = true; + + socketio = { + enable = true; + port = 12311; + }; + }; + + users.users.erpnext = { + description = "User to run erpnext"; + group = "erpnext"; + isSystemUser = true; + }; + + systemd.services.erpnext = + let + penv = python3.buildEnv.override { + extraLibs = [ + python3.pkgs.frappe + python3.pkgs.erpnext + python3.pkgs.bench + ]; + }; + in + { + enable = true; + wantedBy = [ "multi-user.target" ]; + after = [ "mysql.service" "redis.service" "redis-socketio.service" ]; + description = "ERPNext"; + confinement = { + enable = true; + packages = [ ]; + }; + script = '' + export PYTHON_PATH=${penv}/${python3.sitePackages} + + cat > /frappe-bench/sites/apps.txt </frape-bench/sites/common_site_config.json <