From d339ee4c07c5aadd04135a17409080a3f301d84c Mon Sep 17 00:00:00 2001 From: Philipp Hochkamp Date: Fri, 19 Aug 2022 17:12:21 +0200 Subject: [PATCH] feat: added octoprint --- flake.lock | 41 +++++++++++++++++++--- flake.nix | 38 ++++++++++---------- hosts/octopine/default.nix | 72 +++++++++++++++++++++++++++++++++++++- nixos-common.nix | 4 +-- 4 files changed, 130 insertions(+), 25 deletions(-) diff --git a/flake.lock b/flake.lock index c0550962..f175046a 100644 --- a/flake.lock +++ b/flake.lock @@ -131,17 +131,16 @@ "mobile-nixos": { "flake": false, "locked": { - "lastModified": 1656299939, - "narHash": "sha256-gODt71CCv0gnMNeU4GYdSBJkxsfmBy0uNv8owQC1oPs=", + "lastModified": 1659299256, + "narHash": "sha256-MzeeBiULuqsj8TpaWWxI44ciYjrR6H3CwljJDwkT6TU=", "owner": "NixOS", "repo": "mobile-nixos", - "rev": "de9a88a70f0ae5fc0839ff94bf29e8a30af399f8", + "rev": "87e579471c42def38f719028ad6c5d746f26027b", "type": "github" }, "original": { "owner": "NixOS", "repo": "mobile-nixos", - "rev": "de9a88a70f0ae5fc0839ff94bf29e8a30af399f8", "type": "github" } }, @@ -244,6 +243,38 @@ "type": "github" } }, + "octoprint-spoolmanager": { + "flake": false, + "locked": { + "lastModified": 1647619589, + "narHash": "sha256-JKPegbnv7nxyhAi8AqF/TDQVaj67JTlcWYHhetX5AGQ=", + "owner": "OllisGit", + "repo": "OctoPrint-SpoolManager", + "rev": "dea8d64c1849c970f3616e158260c4c6fef5a4b7", + "type": "github" + }, + "original": { + "owner": "OllisGit", + "repo": "OctoPrint-SpoolManager", + "type": "github" + } + }, + "octoprint-telegram": { + "flake": false, + "locked": { + "lastModified": 1646577349, + "narHash": "sha256-z/Nhixz83pikM616OEn+bK1889DTdC8F1E7WiBy8gsY=", + "owner": "fabianonline", + "repo": "OctoPrint-Telegram", + "rev": "d8fa9ac4a65600a25deacad9bc0d3e9cc0167751", + "type": "github" + }, + "original": { + "owner": "fabianonline", + "repo": "OctoPrint-Telegram", + "type": "github" + } + }, "pandoc-latex-template": { "flake": false, "locked": { @@ -295,6 +326,8 @@ "nixpkgs": "nixpkgs_2", "nixpkgs-master": "nixpkgs-master", "nnn-vim": "nnn-vim", + "octoprint-spoolmanager": "octoprint-spoolmanager", + "octoprint-telegram": "octoprint-telegram", "pandoc-latex-template": "pandoc-latex-template", "rnix-lsp": "rnix-lsp", "utils": "utils_3", diff --git a/flake.nix b/flake.nix index 4e2844c5..6fe05fb1 100644 --- a/flake.nix +++ b/flake.nix @@ -17,8 +17,12 @@ utils.url = "github:numtide/flake-utils"; #pinephone - mobile-nixos.url = "github:NixOS/mobile-nixos?rev=de9a88a70f0ae5fc0839ff94bf29e8a30af399f8"; + mobile-nixos.url = "github:NixOS/mobile-nixos"; mobile-nixos.flake = false; # whyever this isn't a flake + octoprint-telegram.url = "github:fabianonline/OctoPrint-Telegram"; + octoprint-telegram.flake = false; + octoprint-spoolmanager.url = "github:OllisGit/OctoPrint-SpoolManager"; + octoprint-spoolmanager.flake = false; ## emacs emacs-overlay.url = "github:nix-community/emacs-overlay"; @@ -71,10 +75,10 @@ inherit system; config.allowUnfree = true; }; - overlays = [ - self.overlays.default - emacs-overlay.overlay - ]; + overlays = [ + self.overlays.default + emacs-overlay.overlay + ]; hmConfig = { hm, pkgs, inputs, config, ... }: { @@ -125,19 +129,17 @@ specialArgs = { inherit lib; }; modules = [ home-manager.darwinModules.home-manager - ({ config, inputs, self, ... }: { - config = { - #system.darwinLabel = "${config.system.darwinLabel}@${rev}"; - _module.args = { inherit lib inputs self darwin; }; - nixpkgs.pkgs = pkgs; - nixpkgs.overlays = overlays; - networking.hostName = hostName; - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - home-manager.extraSpecialArgs = { inherit inputs; }; - home-manager.users.ragon = hmConfig; - }; - }) + { + #system.darwinLabel = "${config.system.darwinLabel}@${rev}"; + _module.args = { inherit lib inputs self darwin; }; + nixpkgs.pkgs = pkgs; + nixpkgs.overlays = overlays; + networking.hostName = hostName; + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.extraSpecialArgs = { inherit inputs; }; + home-manager.users.ragon = hmConfig; + } ./darwin-common.nix ] ++ (lib.my.mapModulesRec' (toString ./darwin-modules) import) ++ extraModules; }; diff --git a/hosts/octopine/default.nix b/hosts/octopine/default.nix index 7a71b4ae..f0e1005f 100644 --- a/hosts/octopine/default.nix +++ b/hosts/octopine/default.nix @@ -3,6 +3,10 @@ # and in the NixOS manual (accessible by running ‘nixos-help’). { config, inputs, pkgs, lib, ... }: +with lib; +let + compressLargeArtifacts = false; +in { imports = [ @@ -10,9 +14,76 @@ services.octoprint = { enable = true; + plugins = plugins: with plugins; [ telegram ]; }; + mobile.generatedFilesystems.rootfs = { + type = "ext4"; + label = "NIXOS_SYSTEM"; + id = "44444444-4444-4444-8888-888888888888"; + populateCommands = + let + closureInfo = pkgs.buildPackages.closureInfo { rootPaths = config.system.build.toplevel; }; + in + '' + mkdir -p ./nix/store + echo "Copying system closure..." + while IFS= read -r path; do + echo " Copying $path" + cp -prf "$path" ./nix/store + done < "${closureInfo}/store-paths" + echo "Done copying system closure..." + cp -v ${closureInfo}/registration ./nix-path-registration + ''; + + # Give some headroom for initial mounting. + extraPadding = pkgs.imageBuilder.size.MiB 600; # without this much of a padding inodes are too small for some reason + + # FIXME: See #117, move compression into the image builder. + # Zstd can take a long time to complete successfully at high compression + # levels. Increasing the compression level could lead to timeouts. + postProcess = optionalString compressLargeArtifacts '' + (PS4=" $ "; set -x + PATH="$PATH:${buildPackages.zstd}/bin" + cd $out + ls -lh + time zstd -10 --rm "$filename" + ls -lh + ) + '' + '' + (PS4=" $ "; set -x + mkdir $out/nix-support + cat < $out/nix-support/hydra-build-products + file rootfs${optionalString compressLargeArtifacts "-zstd"} $out/$filename${optionalString compressLargeArtifacts ".zst"} + EOF + ) + ''; + + zstd = compressLargeArtifacts; + }; + + networking.useDHCP = true; services.mjpg-streamer.enable = true; + services.mjpg-streamer.inputPlugin = "input_uvc.so -d /dev/video1 -r 640x480 -f 15 -u"; + hardware.opengl.enable = true; + services.getty.autologinUser = "ragon"; + home-manager.users.ragon = ({ config, pkgs, ... }: { + programs.zsh.loginExtra = '' + [ "$(tty)" = "/dev/tty1" ] && exec sway + ''; + + }); + + security.sudo.wheelNeedsPassword = false; + programs.sway = { + enable = true; + }; + networking.firewall.allowedTCPPorts = [ 5000 5050 ]; + environment.etc."sway/config".text = '' + output DSI-1 transform 90 anticlockwise # widescreen + exec swayidle timeout 1805 'swaymsg "output * dpms off"' resume 'swaymsg "output * dpms on"' + exec ${pkgs.chromium}/bin/chromium http://localhost:5000 --start-fullscreen --kiosk + ''; ragon = { cli.enable = true; @@ -20,7 +91,6 @@ system.security.enable = false; services = { - docker.enable = true; ssh.enable = true; }; }; diff --git a/nixos-common.nix b/nixos-common.nix index c7cfb9b0..93d991f2 100644 --- a/nixos-common.nix +++ b/nixos-common.nix @@ -49,13 +49,13 @@ in registry = registryInputs // { conf.flake = inputs.self; }; }; system.configurationRevision = with inputs; mkIf (self ? rev) self.rev; - system.stateVersion = "21.05"; + system.stateVersion = "22.05"; ## Some reasonable, global defaults # This is here to appease 'nix flake check' for generic hosts with no # hardware-configuration.nix or fileSystem config. - fileSystems."/".device = mkDefault "/dev/disk/by-label/nixos"; + boot = { loader = {