autosurfer/flake.nix

103 lines
3.1 KiB
Nix
Raw Normal View History

2024-08-04 15:57:29 +02:00
{
inputs = {
nixpkgs-unstable = {
url = "github:NixOS/nixpkgs/nixos-unstable";
};
};
outputs = {
self,
nixpkgs,
...
}: let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
env = pkgs.buildEnv {
name = "autosurfer-env";
pathsToLink = ["/bin" "/autosurfer"];
paths = [
(pkgs.lib.fileset.toSource {
root = ./.;
fileset = ./autosurfer;
})
# https://discourse.nixos.org/t/declare-firefox-extensions-and-settings/36265/7
(pkgs.wrapFirefox pkgs.firefox-unwrapped {
# https://mozilla.github.io/policy-templates/
extraPolicies = {
# We *want* to leak DNS requests
DNSOverHTTPS = {
Enabled = false;
};
# cba leaking tabs
PopupBlocking = {
Default = true;
Locked = true; # doesn't work without locking
};
# Disable downloading
DownloadDirectory = "/unwritable-downloads";
ExtensionSettings = {
"uBlock0@raymondhill.net" = {
install_url = "https://addons.mozilla.org/firefox/downloads/latest/ublock-origin/latest.xpi";
installation_mode = "force_installed";
};
};
};
})
pkgs.geckodriver
(pkgs.python3.withPackages (ps: [
2024-09-11 00:01:14 +02:00
ps.cryptography
ps.httpx
2024-08-04 15:57:29 +02:00
ps.selenium
2024-09-11 00:01:14 +02:00
ps.structlog
2024-08-04 15:57:29 +02:00
]))
# pkgs.bashInteractive
# pkgs.coreutils
];
};
in {
# https://wiki.nixos.org/wiki/Flakes
# `nix build`
packages.${system} = {
# https://wiki.nixos.org/wiki/Docker#Creating_images
# https://nixos.org/manual/nixpkgs/stable/#sec-pkgs-dockerTools
# https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/docker/examples.nix
oci = pkgs.dockerTools.streamLayeredImage {
name = "autosurfer";
2024-08-05 20:25:39 +02:00
tag = "dev";
2024-08-04 15:57:29 +02:00
created = builtins.substring 0 8 self.lastModifiedDate;
contents = [
env
# Firefox ships with its own certificate store, but the websockets
# python library does not.
pkgs.dockerTools.caCertificates
];
extraCommands = ''
# Selenium requires /tmp
mkdir --mode=1777 tmp/
# There doesn't seem to be a way to disable downloads in Firefox, but
# they will all fail if the downloads folder is unwritable.
mkdir unwritable-downloads/
${pkgs.busybox}/bin/chattr +i unwritable-downloads/
'';
config = {
Env = [
2024-08-05 21:39:02 +02:00
# Show print()s in podman logs
"PYTHONUNBUFFERED=1"
2024-08-04 15:57:29 +02:00
# HOME is not set by podman (but it is by docker??), and is
# required for Firefox to start.
"HOME=/"
];
2024-09-11 00:01:14 +02:00
# Entrypoint = ["python" "/autosurfer/main.py"];
Entrypoint = ["python" "/autosurfer/ct.py"];
2024-08-04 15:57:29 +02:00
};
};
2024-09-11 00:01:14 +02:00
};
apps.${system}.default = {
type = "app";
program = "${self.packages.${system}.default}/bin/python autosurfer/ct.py";
2024-08-04 15:57:29 +02:00
};
};
}