diff options
40 files changed, 1887 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fcfc4a1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +result* diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..4b18507 --- /dev/null +++ b/flake.lock @@ -0,0 +1,172 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1653893745, + "narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1", + "type": "github" + }, + "original": { + "id": "flake-utils", + "type": "indirect" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1652776076, + "narHash": "sha256-gzTw/v1vj4dOVbpBSJX4J0DwUR6LIyXo7/SuuTJp1kM=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "04c1b180862888302ddfb2e3ad9eaa63afc60cf8", + "type": "github" + }, + "original": { + "id": "flake-utils", + "type": "indirect" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1654845941, + "narHash": "sha256-uXulXu4BQ9ch1ItV0FlL2Ns8X83m6unT5h/0X//VRLQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7b3e907a6fef935794b5049c2c57c519853deb90", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1653738054, + "narHash": "sha256-IaR8iLN4Ms3f5EjU1CJkXSc49ZzyS5qv03DtVAti6/s=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "17b62c338f2a0862a58bb6951556beecd98ccda9", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1648219316, + "narHash": "sha256-Ctij+dOi0ZZIfX5eMhgwugfvB+WZSrvVNAyAuANOsnQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "30d3d79b7d3607d56546dd2a6b49e156ba0ec634", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_4": { + "locked": { + "lastModified": 1637875414, + "narHash": "sha256-Ica++SXFuLyxX9Q7YxhfZulUif6/gwM8AEQYlUxqSgE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3bea86e918d8b54aa49780505d2d4cd9261413be", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-21.05", + "type": "indirect" + } + }, + "nixturris": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1653841080, + "narHash": "sha256-WKjNzLTN6Sp86LqUbMfl/O9roNfSA6gJvqIUXHarAeM=", + "ref": "refs/heads/master", + "rev": "38a4faa40f2d6ec6decd8863b1784809952933c7", + "revCount": 28, + "type": "git", + "url": "https://git.cynerd.cz/nixturris" + }, + "original": { + "type": "git", + "url": "https://git.cynerd.cz/nixturris" + } + }, + "personal-secret": { + "locked": { + "lastModified": 1654761075, + "narHash": "sha256-wzG0P8A9p7ca8S4NnKB42OlhSj8TZX5PlqVvnm9m0vM=", + "ref": "refs/heads/master", + "rev": "a5a2d42e69ef2b10ec5753a976d36228916090b1", + "revCount": 9, + "type": "git", + "url": "ssh://git@cynerd.cz/nixos-personal-secret" + }, + "original": { + "type": "git", + "url": "ssh://git@cynerd.cz/nixos-personal-secret" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "nixturris": "nixturris", + "personal-secret": "personal-secret", + "shellrc": "shellrc", + "sterm": "sterm" + } + }, + "shellrc": { + "inputs": { + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1654780370, + "narHash": "sha256-IYqHhFNG8GP4P3dI8DCUR9lrlr+QHsEfGJ6Qf7pCem0=", + "ref": "refs/heads/master", + "rev": "9e4f4d2631b2d9ba537f25299c5d9fc5783ca776", + "revCount": 55, + "type": "git", + "url": "https://git.cynerd.cz/shellrc" + }, + "original": { + "type": "git", + "url": "https://git.cynerd.cz/shellrc" + } + }, + "sterm": { + "inputs": { + "nixpkgs": "nixpkgs_4" + }, + "locked": { + "lastModified": 1654787204, + "narHash": "sha256-SFzlL4FxwazJqzMPvLPT0IVWaYqV+NMdHxOEOawZ9Z8=", + "owner": "cynerd", + "repo": "sterm", + "rev": "aec0022e09119ec4e0cf8ba85515cbde907384b6", + "type": "github" + }, + "original": { + "owner": "cynerd", + "ref": "comp", + "repo": "sterm", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..d39fbff --- /dev/null +++ b/flake.nix @@ -0,0 +1,80 @@ +{ + description = "Cynerd's personal flake"; + + inputs = { + shellrc.url = "git+https://git.cynerd.cz/shellrc"; + nixturris.url = "git+https://git.cynerd.cz/nixturris"; + personal-secret.url = "git+ssh://git@cynerd.cz/nixos-personal-secret"; + + #sterm.url = "github:wentasah/sterm"; + sterm.url = "github:cynerd/sterm/comp"; + }; + + outputs = { self + , nixpkgs, flake-utils + , shellrc, nixturris, personal-secret + , sterm + }: + with flake-utils.lib; + { + overlays.default = final: prev: import ./pkgs { nixpkgs = prev; }; + nixosModules = import ./nixos nixpkgs; + + nixosConfigurations = let + + modules = hostname: [ + self.nixosModules.default + self.nixosModules."machine-${hostname}" + shellrc.nixosModule + (personal-secret.lib.personalSecrets hostname) + { + networking.hostName = hostname; + nixpkgs.overlays = [ + self.overlays.default + sterm.overlay + ]; + } + ]; + + genericSystem = system: hostname: { + ${hostname} = nixpkgs.lib.nixosSystem { + system = system; + modules = modules hostname; + }; + }; + amd64System = genericSystem "x86_64-linux"; + armv7lSystem = genericSystem "armv7l-linux"; + aarch64System = genericSystem "aarch64-linux"; + + turrisSystem = board: hostname: { + ${hostname} = nixturris.lib.nixturrisSystem { + nixpkgs = nixpkgs; + board = board; + modules = modules hostname; + }; + }; + turrisMoxSystem = turrisSystem "mox"; + turrisOmniaSystem = turrisSystem "omnia"; + + in + amd64System "albert" // + amd64System "binky" // + amd64System "errol" // + amd64System "lipwig" // + amd64System "ridcully" // + amd64System "susan" // + armv7lSystem "spt-mpd" // + aarch64System "adm-mpd" // + turrisOmniaSystem "spt-omnia" // + turrisMoxSystem "spt-mox" // + turrisMoxSystem "spt-mox2" // + turrisOmniaSystem "adm-omnia" // + turrisOmniaSystem "adm-omnia2"; + + } // eachDefaultSystem (system: { + packages = filterPackages system (flattenTree ( + import ./pkgs { nixpkgs = nixpkgs.legacyPackages."${system}"; } + )); + }); + +} diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..a707ed4 --- /dev/null +++ b/install.sh @@ -0,0 +1,31 @@ +#!/bin/sh +set -eu +hostname="${1:-$(hostname)}" + +if [ "$(id -u)" -ne 0 ]; then + echo "Please run as root!" >&2 + exit 1 +fi + +if [ "$hostname" = "nixos" ]; then + echo "The hostname is the default one, that is not right for sure." >&2 + echo "Please specify the correct hostname as the first argument!" >&2 + exit 1 +fi + +if [ ! -s /.personal-secrets.key ]; then + echo "Please paste the personal secret key (terminate using ^D)" >&2 + cat >/.personal-secrets.key +fi + +mkdir -p ~/.ssh +cat >~/.ssh/config <<EOF +Match User git Host cynerd.cz + IdentityFile ~/.ssh/nixos-secret-access +EOF +echo "Please paste the SSH access key now (terminate using ^D):" >&2 +cat >~/.ssh/nixos-secret-access +trap "rm -f ~/.ssh/nixos-secret-access" EXIT + +nix-shell -p git --command \ + "nixos-rebuild switch --flake 'git+https://git.cynerd.cz/nixos-personal#$hostname' --fast" diff --git a/nixos/default.nix b/nixos/default.nix new file mode 100644 index 0000000..72eae65 --- /dev/null +++ b/nixos/default.nix @@ -0,0 +1,10 @@ +nixpkgs: + +let + + modules = import ./modules nixpkgs; + machines = import ./machine; + +in modules // machines // { + default = { imports = builtins.attrValues modules; }; +} diff --git a/nixos/machine/adm-mpd.nix b/nixos/machine/adm-mpd.nix new file mode 100644 index 0000000..3e103e1 --- /dev/null +++ b/nixos/machine/adm-mpd.nix @@ -0,0 +1,23 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + + config = { + fileSystems = { + "/" = { + device = "/dev/mmcblk0p2"; + options = ["compress=lzo" "subvol=@nix"]; + }; + "/home" = { + device = "/dev/mmcblk0p2"; + options = ["compress=lzo" "subvol=@home"]; + }; + "/boot" = { + device = "/dev/mmcblk0p1"; + }; + }; + }; + +} diff --git a/nixos/machine/adm-omnia.nix b/nixos/machine/adm-omnia.nix new file mode 100644 index 0000000..21bfeb6 --- /dev/null +++ b/nixos/machine/adm-omnia.nix @@ -0,0 +1,10 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + + config = { + }; + +} diff --git a/nixos/machine/adm-omnia2.nix b/nixos/machine/adm-omnia2.nix new file mode 100644 index 0000000..21bfeb6 --- /dev/null +++ b/nixos/machine/adm-omnia2.nix @@ -0,0 +1,10 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + + config = { + }; + +} diff --git a/nixos/machine/albert.nix b/nixos/machine/albert.nix new file mode 100644 index 0000000..0adad68 --- /dev/null +++ b/nixos/machine/albert.nix @@ -0,0 +1,31 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + + config = { + cynerd.desktop.enable = true; + + fileSystems = { + "/" = { + device = "/dev/disk/by-uuid/1c9bafac-fcf8-41c4-b394-bca5917ca82d"; + options = ["compress=lzo" "subvol=@nix"]; + }; + "/home" = { + device = "/dev/disk/by-uuid/1c9bafac-fcf8-41c4-b394-bca5917ca82d"; + options = ["compress=lzo" "subvol=@home"]; + }; + "/boot" = { + device = "/dev/disk/by-uuid/E403-124B"; + }; + + "/home2" = { + device = "/dev/disk/by-uuid/55e177a1-215e-475b-ba9c-771b5fa3f8f0"; + options = ["compress=lzo" "subvol=@home"]; + }; + }; + + }; + +} diff --git a/nixos/machine/binky.nix b/nixos/machine/binky.nix new file mode 100644 index 0000000..849c719 --- /dev/null +++ b/nixos/machine/binky.nix @@ -0,0 +1,60 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + + config = { + cynerd = { + desktop = { + enable = true; + laptop = true; + }; + wifiClient = true; + develop = true; + }; + + boot.initrd.availableKernelModules = ["nvme" "xhci_pci" "usb_storage" "sd_mod"]; + boot.kernelModules = ["kvm-amd"]; + + boot.initrd.luks.devices = { + "encroot".device = "/dev/disk/by-uuid/b317feb5-d68d-4ec3-a24f-0307c116cac8"; + }; + fileSystems = { + "/" = { + device = "/dev/mapper/encroot"; + fsType = "btrfs"; + options = ["compress=lzo" "subvol=@"]; + }; + "/nix" = { + device = "/dev/mapper/encroot"; + fsType = "btrfs"; + options = ["compress=lzo" "subvol=@nix"]; + }; + "/home" = { + device = "/dev/mapper/encroot"; + fsType = "btrfs"; + options = ["compress=lzo" "subvol=@home"]; + }; + "/boot" = { + device = "/dev/disk/by-uuid/8F7D-A154"; + fsType = "vfat"; + }; + }; + + services.syncthing = { + enable = true; + user = mkDefault "cynerd"; + group = mkDefault "cynerd"; + openDefaultPorts = true; + + overrideDevices = false; + overrideFolders = false; + + dataDir = "/home/cynerd"; + configDir = "/home/cynerd/.config/syncthing"; + }; + + }; + +} diff --git a/nixos/machine/default.nix b/nixos/machine/default.nix new file mode 100644 index 0000000..bfd2594 --- /dev/null +++ b/nixos/machine/default.nix @@ -0,0 +1,17 @@ +{ + machine-albert = import ./albert.nix; + machine-binky = import ./binky.nix; + machine-errol = import ./errol.nix; + machine-lipwig = import ./lipwig.nix; + machine-ridcully = import ./ridcully.nix; + machine-susan = import ./susan.nix; + + machine-spt-omnia = import ./spt-omnia.nix; + machine-spt-mox = import ./spt-mox.nix; + machine-spt-mox2 = import ./spt-mox2.nix; + machine-spt-mpd = import ./spt-mpd.nix; + + machine-adm-omnia = import ./adm-omnia.nix; + machine-adm-omnia2 = import ./adm-omnia2.nix; + machine-adm-mpd = import ./spt-mpd.nix; +} diff --git a/nixos/machine/errol.nix b/nixos/machine/errol.nix new file mode 100644 index 0000000..707d8eb --- /dev/null +++ b/nixos/machine/errol.nix @@ -0,0 +1,35 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + + config = { + cynerd.desktop.enable = true; + + fileSystems = { + "/" = { + device = "/dev/disk/by-uuid/b4b3dd52-29d0-4cb9-91c9-694dfcd9672c"; + options = ["compress=lzo" "subvol=@nix"]; + }; + "/home" = { + device = "/dev/disk/by-uuid/b4b3dd52-29d0-4cb9-91c9-694dfcd9672c"; + options = ["compress=lzo" "subvol=@home"]; + }; + "/boot" = { + device = "/dev/disk/by-uuid/87B0-A1D5"; + }; + + "/home2" = { + device = "/dev/disk/by-uuid/259d078f-b3d9-4bcc-90cc-6a0d7271a03d"; + options = ["compress=lzo" "subvol=@home"]; + }; + "/var/build" = { + device = "/dev/disk/by-uuid/259d078f-b3d9-4bcc-90cc-6a0d7271a03d"; + options = ["compress=lzo" "subvol=@build" "uid=build" "gid=build"]; + }; + }; + + }; + +} diff --git a/nixos/machine/lipwig.nix b/nixos/machine/lipwig.nix new file mode 100644 index 0000000..aa3d448 --- /dev/null +++ b/nixos/machine/lipwig.nix @@ -0,0 +1,58 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + + config = { + boot.isContainer = true; + boot.loader.initScript.enable = true; + + cynerd.openvpn.enable = true; + + # Git ###################################################################### + services.gitolite = { + enable = false; + user = "git"; + group = "git"; + dataDir = "/var/lib/git"; + adminPubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIaMmBV0wPvG5JQIWxi20IDlLokhRBumTEbUUD9TNWoY Bootstrap gitolite key"; + }; + services.gitDaemon = { + enable = false; + user = "gitdemon"; + group = "gitdaemon"; + basePath = "/var/lib/git/repositories"; + }; + + # CalDAV and CardDAV ####################################################### + services.radicale = { + enable = true; + settings = { + server = { + hosts = [ "0.0.0.0:5232" "[::]:5232" ]; + ssl = true; + certificate = "/run/secrets/radicale/radicale.crt"; + key = "/run/secrets/radicale/radicale.key"; + }; + encoding = { + request = "utf-8"; + stock = "utf-8"; + }; + auth = { + type = "htpasswd"; + htpasswd_filename = "/run/secrets/radicale/users"; + htpasswd_encryption = "bcrypt"; + delay = 1; + }; + storage = { + filesystem_folder = "/var/lib/radicale/"; + }; + web = { + type = "none"; + }; + }; + }; + }; + +} diff --git a/nixos/machine/ridcully.nix b/nixos/machine/ridcully.nix new file mode 100644 index 0000000..882f967 --- /dev/null +++ b/nixos/machine/ridcully.nix @@ -0,0 +1,31 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + + config = { + cynerd.desktop.enable = true; + + fileSystems = { + "/" = { + device = "/dev/disk/by-uuid/3b3063aa-c284-4075-bb37-8820df12a2f5"; + options = ["compress=lzo" "subvol=@nix"]; + }; + "/home" = { + device = "/dev/disk/by-uuid/3b3063aa-c284-4075-bb37-8820df12a2f5"; + options = ["compress=lzo" "subvol=@home"]; + }; + "/boot" = { + device = "/dev/disk/by-uuid/C1A0-B7C9"; + }; + + "/home2" = { + device = "/dev/disk/by-uuid/c9aa0b7b-7482-4d4a-bcc3-8bd6a853ae7f"; + options = ["compress=lzo" "subvol=@home"]; + }; + }; + + }; + +} diff --git a/nixos/machine/spt-mox.nix b/nixos/machine/spt-mox.nix new file mode 100644 index 0000000..eb304b2 --- /dev/null +++ b/nixos/machine/spt-mox.nix @@ -0,0 +1,31 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + + config = { + networking = { + vlans = { + "eth0.2" = { + id = 2; + interface = "eth0"; + }; + }; + bridges = { + brlan = { + interfaces = [ + "eth0" "lan1" "lan2" "lan3" "lan4" + ]; + }; + brguest = { + interfaces = [ + "eth0.2" + ]; + }; + }; + dhcpcd.allowInterfaces = [ "brlan" ]; + }; + }; + +} diff --git a/nixos/machine/spt-mox2.nix b/nixos/machine/spt-mox2.nix new file mode 100644 index 0000000..ed6a028 --- /dev/null +++ b/nixos/machine/spt-mox2.nix @@ -0,0 +1,78 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + + config = { + + #boot.kernelPatches = [{ + # name = "rwtm"; + # patch = null; + # extraConfig = '' + # TURRIS_MOX_RWTM y + # ARMADA_37XX_RWTM_MBOX y + # ''; + #}]; + + networking.hostapd = { + "mlan0" = { + countryCode = "CZ"; + ssid = "TurrisRules"; + wpa = true; + wpaPskFile = "/run/secrets/wifi/TurrisRules.psk"; + }; + "wlp1s0" = { + countryCode = "CZ"; + hwMode = "a"; + channel = 36; + ieee80211ac = true; + ht_capab = ["HT40+" "LDPC" "SHORT-GI-20" "SHORT-GI-40" "TX-STBC" "RX-STBC1" "MAX-AMSDU-7935" "DSSS_CCK-40"]; + vht_capab = ["RXLDPC" "SHORT-GI-80" "TX-STBC-2BY1" "RX-ANTENNA-PATTERN" "TX-ANTENNA-PATTERN" "RX-STBC-1" "MAX-MPDU-11454" "MAX-A-MPDU-LEN-EXP7"]; + ssid = "TurrisRules5"; + wpa = true; + wpaPskFile = "/run/secrets/wifi/TurrisRules5.psk"; + bss = { + "wlp1s0host" = { + ssid = "NixTurris5Guest"; + wpa = true; + wpaPassphrase = "somepassword"; + }; + }; + }; + }; + + networking = { + vlans = { + "eth0.2" = { + id = 2; + interface = "eth0"; + }; + }; + bridges = { + brlan = { + interfaces = [ + "eth0" #"mlan0" "wlp1s0" + ]; + }; + brguest = { + interfaces = [ + "eth0.2" #"mlan0host" "wlp1s0host" + ]; + }; + }; + interfaces.brlan = { + ipv4 = { + addresses = [{ + address = config.cynerd.hosts.spt.mox2; + prefixLength = 24; + }]; + }; + }; + defaultGateway = config.cynerd.hosts.spt.omnia; + nameservers = [ config.cynerd.hosts.spt.omnia "1.1.1.1" "8.8.8.8" ]; + dhcpcd.allowInterfaces = [ "brlan" ]; + }; + }; + +} diff --git a/nixos/machine/spt-mpd.nix b/nixos/machine/spt-mpd.nix new file mode 100644 index 0000000..3e103e1 --- /dev/null +++ b/nixos/machine/spt-mpd.nix @@ -0,0 +1,23 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + + config = { + fileSystems = { + "/" = { + device = "/dev/mmcblk0p2"; + options = ["compress=lzo" "subvol=@nix"]; + }; + "/home" = { + device = "/dev/mmcblk0p2"; + options = ["compress=lzo" "subvol=@home"]; + }; + "/boot" = { + device = "/dev/mmcblk0p1"; + }; + }; + }; + +} diff --git a/nixos/machine/spt-omnia.nix b/nixos/machine/spt-omnia.nix new file mode 100644 index 0000000..21bfeb6 --- /dev/null +++ b/nixos/machine/spt-omnia.nix @@ -0,0 +1,10 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + + config = { + }; + +} diff --git a/nixos/machine/susan.nix b/nixos/machine/susan.nix new file mode 100644 index 0000000..b452ed9 --- /dev/null +++ b/nixos/machine/susan.nix @@ -0,0 +1,26 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + + config = { + cynerd.desktop.enable = true; + + fileSystems = { + "/" = { + device = "/dev/disk/by-uuid/e092a3ad-fb32-44fa-bc1f-14c2733da033"; + options = ["compress=lzo" "subvol=@nix"]; + }; + "/home" = { + device = "/dev/disk/by-uuid/e092a3ad-fb32-44fa-bc1f-14c2733da033"; + options = ["compress=lzo" "subvol=@home"]; + }; + "/boot" = { + device = "/dev/disk/by-uuid/EB3E-3635"; + }; + }; + + }; + +} diff --git a/nixos/modules/compile.nix b/nixos/modules/compile.nix new file mode 100644 index 0000000..a1709e6 --- /dev/null +++ b/nixos/modules/compile.nix @@ -0,0 +1,30 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + + options = { + cynerd.compile = mkOption { + type = types.bool; + default = false; + description = "If machine is about to be used for compilation."; + }; + }; + + config = mkIf config.cynerd.compile { + + environment.systemPackages = with pkgs; [ + # Tools + git bash + #uroot + qemu + + # Python + python3Packages.pip + + ]; + + }; + +} diff --git a/nixos/modules/default.nix b/nixos/modules/default.nix new file mode 100644 index 0000000..fe401df --- /dev/null +++ b/nixos/modules/default.nix @@ -0,0 +1,11 @@ +nixpkgs: { + cynerd-compile = import ./compile.nix; + cynerd-desktop = import ./desktop.nix; + cynerd-develop = import ./develop.nix nixpkgs; + cynerd-generic = import ./generic.nix; + cynerd-hardware = import ./hardware.nix; + cynerd-hosts = import ./hosts.nix; + cynerd-openvpn = import ./openvpn.nix; + cynerd-syncthing = import ./syncthing.nix; + cynerd-wifi-client = import ./wifi-client.nix; +} diff --git a/nixos/modules/desktop.nix b/nixos/modules/desktop.nix new file mode 100644 index 0000000..41efa0b --- /dev/null +++ b/nixos/modules/desktop.nix @@ -0,0 +1,158 @@ +{ config, lib, pkgs, ... }: + +with lib; +let + + cnf = config.cynerd.desktop; + +in { + + options = { + cynerd.desktop = { + enable = mkOption { + type = types.bool; + default = false; + description = "Enable my desktop"; + }; + laptop = mkOption { + type = types.bool; + default = false; + description = "The desktop requires Laptop extensions"; + }; + }; + }; + + config = mkIf cnf.enable { + cynerd.hosts.enable = true; + + # TODO autologin but only on tty1 + services.gpm.enable = true; + + programs.sway.enable = true; + programs.sway.extraPackages = with pkgs; [ + gnome.dconf-editor + glib gsettings-desktop-schemas + i3blocks sysstat + wofi rofimoji wev + swaybackground myswaylock + + alacritty + + kanshi wdisplays wayvnc wl-mirror + slurp grim + xdg-desktop-portal-wlr xdg-desktop-portal-gtk pipewire wf-recorder + wl-clipboard wl-color-picker + swayidle + dunst + + isync msmtp notmuch astroid + taskwarrior vdirsyncer khal khard + gnupg pass pinentry-gnome pinentry-curses + + firefox chromium + ferdi + libreoffice + mupdf pdfgrep + + xdg-utils xdg-launch + mesa-demos vulkan-tools + + pulsemixer + mpd mpc-cli ncmpcpp + feh shotwell id3lib + vlc mpv youtube-dl + + delft-icon-theme gnome3.adwaita-icon-theme + vanilla-dmz + sound-theme-freedesktop + gucharmap + + samba cifs-utils + + tigervnc freerdp + kdeconnect + + hdparm ethtool multipath-tools + usb-modeswitch + v4l-utils + + # Calculating + python3Packages.numpy python3Packages.sympy python3Packages.matplotlib + + # Creation + simple-scan + audacity + gimp inkscape + blender + kdenlive + + # GStreamer + gst_all_1.gst-libav + gst_all_1.gst-plugins-bad + gst_all_1.gst-plugins-base + gst_all_1.gst-plugins-good + gst_all_1.gst-plugins-ugly + gst_all_1.gst-plugins-viperfx + + ] ++ ( [ + # Power management + powertop + acpi + ]); + programs.vim.package = pkgs.vimHugeX; + programs.shellrc.desktop = true; + xdg.portal.enable = true; + xdg.portal.wlr.enable = true; + xdg.portal.gtkUsePortal = true; + xdg.mime.defaultApplications = { + "application/pdf" = [ "mupdf.desktop" ]; + }; + + programs.gnupg.agent = { + enable = true; + enableSSHSupport = true; + enableBrowserSocket = true; + }; + services.dbus.packages = [ pkgs.gcr ]; + + services.pipewire = { + enable = true; + alsa.enable = true; + alsa.support32Bit = true; + pulse.enable = true; + }; + security.rtkit.enable = true; + + services.printing = { + enable = true; + drivers = with pkgs; [ + gutenprint gutenprintBin + cnijfilter2 + ]; + }; + + fonts.fonts = with pkgs; [ + arkpandora_ttf + corefonts + dejavu_fonts + font-awesome + freefont_ttf + hack-font + liberation_ttf + libertine + noto-fonts + noto-fonts-emoji + terminus_font_ttf + ubuntu_font_family + unifont + ]; + + services.udev.extraRules = '' + ACTION=="add|change", KERNEL=="sd*[!0-9]", ATTR{queue/scheduler}="bfq" + ''; + hardware.opengl.driSupport = true; + hardware.opengl.driSupport32Bit = true; + + + }; +} diff --git a/nixos/modules/develop.nix b/nixos/modules/develop.nix new file mode 100644 index 0000000..bf5c2de --- /dev/null +++ b/nixos/modules/develop.nix @@ -0,0 +1,105 @@ +nixpkgs: { config, lib, pkgs, ... }: + +with lib; + +let + + armv6l = (import nixpkgs.outPath { + localSystem = config.system.build.toplevel.system; + crossSystem = { + config = "armv6l-none-eabi"; + libc = "newlib"; + }; + }); + armv7l = (import nixpkgs.outPath { + localSystem = config.system.build.toplevel.system; + crossSystem = { + config = "armv7l-none-eabi"; + libc = "newlib"; + }; + }); + +in { + + options = { + cynerd.develop = mkOption { + type = types.bool; + default = false; + description = "If machine is about to be used for development."; + }; + }; + + config = mkIf config.cynerd.develop { + cynerd.compile = true; + environment.systemPackages = with pkgs; [ + # Tools + tig gource hub github-cli # Git + wlc # Weblate + cloc + openssl + sterm + + # Nix + nix-prefetch-git nix-prefetch-github nix-prefetch-scripts + + # C + ccls bear + check + valgrind + cppcheck flawfinder + gdb + lcov massif-visualizer + + # Shell + dash # Posix shell + bats + shellcheck + + # Python + python3 python3Packages.ipython + twine + python3Packages.pytest python3Packages.pytest-html #python3Packages.pytest-tap + python3Packages.coverage + python3Packages.python-lsp-black + mypy + pylint python3Packages.pydocstyle + + # Lua + lua51Packages.luacheck + + # Ansible + ansible + + # U-Boot + ubootTools + tftp-hpa + + # Network + iperf2 iperf3 + wireshark + inetutils + + # Gtk + glade + + # Containers + lxc lxd + docker + + # Barcode generation + barcode + + # D-Bus + dfeet + + # Bare metal + openocd + #armv6l.buildPackages.gcc armv6l.buildPackages.gdb + #armv7l.buildPackages.gcc armv7l.buildPackages.gdb + pkgsCross.arm-embedded.buildPackages.gcc + + ]; + + }; + +} diff --git a/nixos/modules/generic.nix b/nixos/modules/generic.nix new file mode 100644 index 0000000..31f0829 --- /dev/null +++ b/nixos/modules/generic.nix @@ -0,0 +1,98 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + + config = { + system.stateVersion = "22.05"; + + nix = { + extraOptions = "experimental-features = nix-command flakes"; + autoOptimiseStore = true; + registry = { + personal.to = { + type = "git"; + url = "https://git.cynerd.cz/nixos-personal"; + }; + }; + }; + + boot.loader.systemd-boot.enable = mkDefault true; + boot.loader.efi.canTouchEfiVariables = true; + boot.kernelPackages = pkgs.linuxPackages_latest; + boot.kernelParams = ["boot.shell_on_fail"]; + hardware.enableAllFirmware = true; + + + nixpkgs.config.allowUnfree = true; + environment.systemPackages = with pkgs; [ + git # We need git for this repository to even work + # Administration tools + coreutils moreutils psmisc progress lshw + dig + + # NCurses tools + htop iotop glances + mc + screen tmux + ncdu + + # ls tools + tree + mlocate + lsof + strace + + sourceHighlight # Colors for less + unrar p7zip + + # Vim plugins (used for root account) + vimPlugins.vim-nix + vimPlugins.vim-nftables + + # Network + nmap netcat traceroute + iftop nethogs + # TODO add mdns + + lm_sensors + + ] ++ optional (system == "x86_64-linux") ltrace; + + users.mutableUsers = false; + users.groups.cynerd.gid = 1000; + users.users = { + root = { + passwordFile = "/run/secrets/root.pass"; + }; + cynerd = { + uid = 1000; + subUidRanges = [{ count = 65534; startUid = 10000; }]; + subGidRanges = [{ count = 65534; startGid = 10000; }]; + group = "cynerd"; + isNormalUser = true; + createHome = true; + shell = pkgs.zsh.out; + extraGroups = ["users" "wheel"]; + passwordFile = "/run/secrets/cynerd.pass"; + openssh.authorizedKeys.keyFiles = [ + (config.personal-secrets + "/unencrypted/git-private.pub") + ]; + }; + }; + programs.zsh.enable = true; + programs.shellrc.enable = true; + programs.vim.defaultEditor = mkDefault true; + + security.sudo.extraRules = [ + { groups = [ "wheel" ]; commands = [ "ALL" ]; } + ]; + + services.openssh.enable = true; + + time.timeZone = "Europe/Prague"; + i18n.defaultLocale = "en_US.UTF-8"; + }; + +} diff --git a/nixos/modules/hardware.nix b/nixos/modules/hardware.nix new file mode 100644 index 0000000..d6bbd94 --- /dev/null +++ b/nixos/modules/hardware.nix @@ -0,0 +1,12 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + + options = { }; + + config = { + }; + +} diff --git a/nixos/modules/hosts.nix b/nixos/modules/hosts.nix new file mode 100644 index 0000000..19f877e --- /dev/null +++ b/nixos/modules/hosts.nix @@ -0,0 +1,104 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cnf = config.cynerd.hosts; + + staticZoneOption = mkOption { + type = types.attrsOf types.str; + readOnly = true; + }; + +in { + + options = { + cynerd.hosts = { + enable = mkOption { + type = types.bool; + default = false; + description = "Use my personal static hosts"; + }; + vpn = staticZoneOption; + spt = staticZoneOption; + adm = staticZoneOption; + }; + }; + + config = { + cynerd.hosts = { + vpn = { + "lipwig" = "10.8.0.1"; + # Portable + "android" = "10.8.0.2"; + "albert" = "10.8.0.3"; + "dean" = "10.8.0.4"; + "susan" = "10.8.0.5"; + "binky" = "10.8.0.6"; + # Endpoints + "spt-omnia" = "10.8.0.50"; + "adm-omnia" = "10.8.0.51"; + }; + spt = { + # Network + "omnia" = "10.8.2.1"; + "mox" = "10.8.2.2"; + "mox2" = "10.8.2.3"; + # Local + "mpd" = "10.8.2.51"; + "errol" = "10.8.2.60"; + # Portable + "albert" = "10.8.2.61"; + "susan" = "10.8.2.62"; + "binky" = "10.8.2.63"; + }; + adm = { + # Network + "omnia" = "10.8.3.1"; + "omnia2" = "10.8.3.3"; + # Local + "ridcully" = "10.8.3.60"; + "3dprint" = "10.8.3.80"; + "mpd" = "192.168.0.51"; + # Portable + "albert" ="10.8.3.61"; + "susan" = "10.8.3.62"; + "binky" = "10.8.3.63"; + }; + }; + + networking.hosts = mkIf cnf.enable { + # VPN + "${cnf.vpn.lipwig}" = ["lipwig.vpn"]; + "${cnf.vpn.android}" = ["android.vpn"]; + "${cnf.vpn.albert}" = ["albert.vpn"]; + "${cnf.vpn.dean}" = ["dean.vpn"]; + "${cnf.vpn.susan}" = ["susan.vpn"]; + "${cnf.vpn.binky}" = ["binky.vpn"]; + "${cnf.vpn.spt-omnia}" = ["spt.vpn"]; + "${cnf.vpn.adm-omnia}" = ["adm.vpn"]; + # Spt + "${cnf.spt.omnia}" = ["omnia.spt"]; + "${cnf.spt.mox}" = ["mox.spt"]; + "${cnf.spt.mox2}" = ["mox2.spt"]; + "10.8.2.4" = ["mi3g.spt"]; + "${cnf.spt.mpd}" = ["mpd.spt"]; + "${cnf.spt.errol}" = ["errol" "desktop.spt"]; + "${cnf.spt.albert}" = ["albert.spt"]; + "${cnf.spt.susan}" = ["susan.spt"]; + "${cnf.spt.binky}" = ["binky.spt"]; + # Adm + "${cnf.adm.omnia}" = ["omnia.adm"]; + "10.8.3.2" = ["redmi.adm"]; + "${cnf.adm.omnia2}" = ["omnia2.adm"]; + "${cnf.adm.ridcully}" = ["ridcully" "desktop.adm"]; + "${cnf.adm.albert}" = ["albert.adm"]; + "${cnf.adm.susan}" = ["susan.adm"]; + "${cnf.adm.binky}" = ["binky.adm"]; + "${cnf.adm."3dprint"}" = ["3dprint"]; + "${cnf.adm.mpd}" = ["mpd.adm"]; + }; + }; + +} diff --git a/nixos/modules/openvpn.nix b/nixos/modules/openvpn.nix new file mode 100644 index 0000000..abcd1f0 --- /dev/null +++ b/nixos/modules/openvpn.nix @@ -0,0 +1,26 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cnf = config.cynerd.openvpn; + +in { + + options = { + cynerd.openvpn.enable = mkOption { + type = types.bool; + default = false; + description = "My personal OpenVPN"; + }; + }; + + config = mkIf cnf.enable { + services.openvpn.servers.personal = { + config = "config /run/secrets/personal.ovpn"; + }; + }; + +} + diff --git a/nixos/modules/syncthing.nix b/nixos/modules/syncthing.nix new file mode 100644 index 0000000..44c1ac1 --- /dev/null +++ b/nixos/modules/syncthing.nix @@ -0,0 +1,115 @@ +{ config, lib, pkgs, ... }: + +with builtins; +with lib; + +let + + cnf = config.cynerd.syncthing; + hostName = config.networking.hostName; + allDevices = [ + "albert" "binky" "errol" "lipwig" "ridcully" "susan" "spt-omnia" + ]; + mediaDevices = [ + "lipwig" "binky" "errol" "ridcully" "spt-omnia" + ]; + bigStorageDevices = [ + "errol" "ridcully" "spt-omnia" + ]; + filterDevice = folders: filterAttrs (n: v: any (d: d == hostName) v.devices) folders; + +in { + + options = { + cynerd.syncthing = { + + enable = mkOption { + type = types.bool; + default = false; + description = "My personal Syncthing configuration"; + }; + + baseDir = mkOption { + type = types.str; + default = "/home/cynerd"; + description = "Base directory for all folders being synced."; + }; + + }; + }; + + config = mkIf cnf.enable { + services.syncthing = { + enable = any (n: n == hostName) allDevices; + user = mkDefault "cynerd"; + key = "/run/secrets/syncthing/key.pem"; + cert = "/run/secrets/syncthing/cert.pem"; + + openDefaultPorts = true; + + overrideFolders = true; + folders = filterDevice { + "${cnf.baseDir}/documents" = { + label = "Documents"; + id = "documents"; + devices = allDevices; + ignorePerms = false; + }; + "${cnf.baseDir}/notes" = { + label = "Notes"; + id = "notes"; + devices = allDevices; + ignorePerms = false; + }; + "${cnf.baseDir}/projects" = { + label = "Projects"; + id = "projects"; + devices = allDevices; + ignorePerms = false; + }; + "${cnf.baseDir}/pictures" = { + label = "Pictures"; + id = "pictures"; + devices = mediaDevices; + ignorePerms = false; + }; + # TODO phone-photos + "${cnf.baseDir}/music/primary" = { + label = "Music-primary"; + id = "music-primary"; + devices = mediaDevices; + ignorePerms = false; + }; + "${cnf.baseDir}/music/secondary" = { + label = "Music-secondary"; + id = "music-secondary"; + devices = bigStorageDevices; + ignorePerms = false; + }; + "${cnf.baseDir}/music/flac" = { + label = "Music-flac"; + id = "music-flac"; + devices = bigStorageDevices; + ignorePerms = false; + }; + "${cnf.baseDir}/video" = { + label = "Video"; + id = "video"; + devices = bigStorageDevices; + ignorePerms = false; + }; + }; + + overrideDevices = true; + devices = recursiveUpdate + (genAttrs allDevices (name: { + id = config.secrets.syncthingIDs."${name}"; + })) + { + lipwig.addresses = ["tcp://cynerd.cz"]; + }; + # TODO phone + }; + }; + +} diff --git a/nixos/modules/wifi-client.nix b/nixos/modules/wifi-client.nix new file mode 100644 index 0000000..af09155 --- /dev/null +++ b/nixos/modules/wifi-client.nix @@ -0,0 +1,23 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + + options = { + cynerd.wifiClient = mkOption { + type = types.bool; + default = false; + description = "Enable Wi-Fi client support"; + }; + }; + + config = mkIf config.cynerd.wifiClient { + networking.wireless = { + enable = true; + networks = config.secrets.wifiNetworks; + environmentFile = "/run/secrets/wifi.env"; + userControlled.enable = true; + }; + }; +} diff --git a/pkgs/default.nix b/pkgs/default.nix new file mode 100644 index 0000000..2d9af4d --- /dev/null +++ b/pkgs/default.nix @@ -0,0 +1,28 @@ +{ nixpkgs ? <nixpkgs>, nixlib ? nixpkgs.lib }: + +let + pkgs = nixpkgs // personalpkgs; + callPackage = nixlib.callPackageWith pkgs; + + personalpkgs = with pkgs; { + + wireplumber = nixpkgs.wireplumber.overrideAttrs (oldAttrs: { + patches = [ + ./patches/0001-wpctl-Add-get-volume-command-and-functionality.patch + ./patches/0002-wpctl-allow-modifying-volume-levels-using-percentage.patch + ]; + }); + + delft-icon-theme = callPackage ./theme/delft-icon-theme.nix { }; + background-lnxpcs = callPackage ./theme/background-lnxpcs.nix { }; + swaybackground = callPackage ./theme/swaybackground.nix { }; + myswaylock = callPackage ./theme/myswaylock.nix { }; + + #personalPython3Packages = python3.withPackages (pythonPackages: + #with pythonPackages; [ + # (pythonPackages.callPackage ./python/notify-send.nix { }) + #]); + + }; + +in personalpkgs diff --git a/pkgs/patches/0001-wpctl-Add-get-volume-command-and-functionality.patch b/pkgs/patches/0001-wpctl-Add-get-volume-command-and-functionality.patch new file mode 100644 index 0000000..4bae05f --- /dev/null +++ b/pkgs/patches/0001-wpctl-Add-get-volume-command-and-functionality.patch @@ -0,0 +1,123 @@ +From c44a369a14a13045462018e55595f1e2d83e1d6b Mon Sep 17 00:00:00 2001 +From: Varnit Singh <varnitcls@gmail.com> +Date: Wed, 8 Jun 2022 09:18:34 +0000 +Subject: [PATCH 1/2] wpctl: Add get-volume command and functionality + +--- + src/tools/wpctl.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 86 insertions(+) + +diff --git a/src/tools/wpctl.c b/src/tools/wpctl.c +index ca5ea01..9f7c6bb 100644 +--- a/src/tools/wpctl.c ++++ b/src/tools/wpctl.c +@@ -47,6 +47,10 @@ static struct { + gboolean is_pid; + } set_volume; + ++ struct { ++ guint64 id; ++ } get_volume; ++ + struct { + guint64 id; + guint mute; +@@ -471,6 +475,78 @@ status_run (WpCtl * self) + g_main_loop_quit (self->loop); + } + ++/* get-volume */ ++ ++static gboolean ++get_volume_parse_positional (gint argc, gchar ** argv, GError **error) ++{ ++ if (argc < 3) { ++ g_set_error (error, wpctl_error_domain_quark(), 0, ++ "ID is required"); ++ return FALSE; ++ } else { ++ return parse_id (true, false, argv[2], &cmdline.get_volume.id, error); ++ } ++} ++ ++static gboolean ++get_volume_prepare (WpCtl * self, GError ** error) ++{ ++ wp_object_manager_add_interest (self->om, WP_TYPE_NODE, NULL); ++ wp_object_manager_request_object_features (self->om, WP_TYPE_GLOBAL_PROXY, ++ WP_PIPEWIRE_OBJECT_FEATURES_MINIMAL); ++ return TRUE; ++} ++ ++static void ++do_print_volume (WpCtl * self, WpPipewireObject *proxy) ++{ ++ g_autoptr (WpPlugin) mixer_api = wp_plugin_find (self->core, "mixer-api"); ++ GVariant *variant = NULL; ++ gboolean mute = FALSE; ++ gdouble volume = 1.0; ++ guint32 id = wp_proxy_get_bound_id (WP_PROXY (proxy)); ++ ++ g_signal_emit_by_name (mixer_api, "get-volume", id, &variant); ++ if (!variant) { ++ fprintf (stderr, "Node %d does not support volume\n", id); ++ return; ++ } ++ g_variant_lookup (variant, "volume", "d", &volume); ++ g_variant_lookup (variant, "mute", "b", &mute); ++ g_clear_pointer (&variant, g_variant_unref); ++ ++ printf ("Volume: %.2f%s", volume, mute ? " [MUTED]\n" : "\n"); ++} ++ ++static void ++get_volume_run (WpCtl * self) ++{ ++ g_autoptr (WpPlugin) def_nodes_api = NULL; ++ g_autoptr (GError) error = NULL; ++ g_autoptr (WpPipewireObject) proxy = NULL; ++ guint32 id; ++ ++ def_nodes_api = wp_plugin_find (self->core, "default-nodes-api"); ++ ++ if (!translate_id (def_nodes_api, cmdline.get_volume.id, &id, &error)) { ++ fprintf(stderr, "Translate ID error: %s\n\n", error->message); ++ goto out; ++ } ++ ++ proxy = wp_object_manager_lookup (self->om, WP_TYPE_GLOBAL_PROXY, ++ WP_CONSTRAINT_TYPE_G_PROPERTY, "bound-id", "=u", id, NULL); ++ if (!proxy) { ++ fprintf (stderr, "Node '%d' not found\n", id); ++ goto out; ++ } ++ ++ do_print_volume (self, proxy); ++ ++out: ++ g_main_loop_quit (self->loop); ++} ++ + /* inspect */ + + static gboolean +@@ -1150,6 +1226,16 @@ static const struct subcommand { + .prepare = status_prepare, + .run = status_run, + }, ++ { ++ .name = "get-volume", ++ .positional_args = "ID", ++ .summary = "Displays volume information about the specified node in PipeWire", ++ .description = NULL, ++ .entries = { { NULL } }, ++ .parse_positional = get_volume_parse_positional, ++ .prepare = get_volume_prepare, ++ .run = get_volume_run, ++ }, + { + .name = "inspect", + .positional_args = "ID", +-- +2.36.1 + diff --git a/pkgs/patches/0002-wpctl-allow-modifying-volume-levels-using-percentage.patch b/pkgs/patches/0002-wpctl-allow-modifying-volume-levels-using-percentage.patch new file mode 100644 index 0000000..9e51797 --- /dev/null +++ b/pkgs/patches/0002-wpctl-allow-modifying-volume-levels-using-percentage.patch @@ -0,0 +1,118 @@ +From 43d8753c5ef4cbd4d2f6558182b290d083644521 Mon Sep 17 00:00:00 2001 +From: Varnit Singh <varnitcls@gmail.com> +Date: Wed, 8 Jun 2022 09:25:45 +0000 +Subject: [PATCH 2/2] wpctl: allow modifying volume levels using + percentage/step amount. + +--- + src/tools/wpctl.c | 63 ++++++++++++++++++++++++++++++++++++++++++++--- + 1 file changed, 59 insertions(+), 4 deletions(-) + +diff --git a/src/tools/wpctl.c b/src/tools/wpctl.c +index 9f7c6bb..0f5bc8c 100644 +--- a/src/tools/wpctl.c ++++ b/src/tools/wpctl.c +@@ -45,6 +45,7 @@ static struct { + guint64 id; + gfloat volume; + gboolean is_pid; ++ gchar type; + } set_volume; + + struct { +@@ -846,11 +847,38 @@ set_volume_parse_positional (gint argc, gchar ** argv, GError **error) + { + if (argc < 4) { + g_set_error (error, wpctl_error_domain_quark(), 0, +- "ID and VOL are required"); ++ "ID and VOL[%%][-/+] are required"); ++ return FALSE; ++ } ++ ++ GRegex *regex = g_regex_new ("^(\\d*\\.?\\d*)(%?)([-+]?)$", 0, 0, NULL); ++ GMatchInfo *info = NULL; ++ ++ if (g_regex_match(regex, argv[3], 0, &info)) { ++ cmdline.set_volume.volume = strtof(g_match_info_fetch(info, 1), NULL); ++ cmdline.set_volume.type = 'a'; ++ ++ if (g_strcmp0(g_match_info_fetch(info, 2), "%") == 0) { ++ cmdline.set_volume.type = 'p'; ++ } ++ ++ if (g_strcmp0(g_match_info_fetch(info, 3), "-") == 0) { ++ cmdline.set_volume.volume = -(cmdline.set_volume.volume); ++ if (cmdline.set_volume.type != 'p') { ++ cmdline.set_volume.type = 's'; ++ } ++ } else if (g_strcmp0(g_match_info_fetch(info, 3), "+") == 0 && cmdline.set_volume.type != 'p') { ++ cmdline.set_volume.type = 's'; ++ } ++ g_match_info_free (info); ++ g_regex_unref (regex); ++ } else { ++ g_regex_unref (regex); ++ g_set_error (error, wpctl_error_domain_quark(), 0, ++ "Invalid volume argument. See wpctl set-volume --help"); + return FALSE; + } + +- cmdline.set_volume.volume = strtof (argv[3], NULL); + return parse_id (!cmdline.set_volume.is_pid, false, argv[2], + &cmdline.set_volume.id, error); + } +@@ -874,6 +902,7 @@ do_set_volume (WpCtl * self, WpPipewireObject *proxy) + g_autoptr (GError) error = NULL; + GVariant *variant = NULL; + gboolean res = FALSE; ++ gdouble curr_volume = 1.0; + guint32 id = wp_proxy_get_bound_id (WP_PROXY (proxy)); + + if (WP_IS_ENDPOINT (proxy)) { +@@ -885,6 +914,27 @@ do_set_volume (WpCtl * self, WpPipewireObject *proxy) + id = atoi (str); + } + ++ g_signal_emit_by_name (mixer_api, "get-volume", id, &variant); ++ if (!variant) { ++ fprintf (stderr, "Node %d does not support volume\n", id); ++ g_clear_pointer (&variant, g_variant_unref); ++ return FALSE; ++ } ++ g_variant_lookup (variant, "volume", "d", &curr_volume); ++ g_clear_pointer (&variant, g_variant_unref); ++ ++ if (cmdline.set_volume.type == 'a') { ++ cmdline.set_volume.volume = cmdline.set_volume.volume; ++ } else if (cmdline.set_volume.type == 's') { ++ cmdline.set_volume.volume = (cmdline.set_volume.volume + curr_volume); ++ } else if (cmdline.set_volume.type == 'p') { ++ gfloat delta = (cmdline.set_volume.volume) * (curr_volume); ++ cmdline.set_volume.volume = (curr_volume + delta); ++ } ++ if (cmdline.set_volume.volume < 0) { ++ cmdline.set_volume.volume = 0.0; ++ } ++ + g_variant_builder_add (&b, "{sv}", "volume", + g_variant_new_double (cmdline.set_volume.volume)); + variant = g_variant_builder_end (&b); +@@ -1266,8 +1316,13 @@ static const struct subcommand { + }, + { + .name = "set-volume", +- .positional_args = "ID VOL", +- .summary = "Sets the volume of ID to VOL (floating point, 1.0 is 100%%)", ++ .positional_args = "ID VOL[%%][-/+]", ++ .summary = "Sets the volume of ID from specified argument. " ++ "(floating point, 1.0 is 100%%)\n VOL%%[-/+] - " ++ "Step up/down volume by specified percent (Example:" ++ " 0.5%%+)\n VOL[-/+] - Step up/down volume by" ++ " specified value (Example: 0.5+)\n VOL - Set " ++ "volume as the specified value (Example: 0.5)", + .description = NULL, + .entries = { + { "pid", 'p', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, +-- +2.36.1 + diff --git a/pkgs/python/notify-send.nix b/pkgs/python/notify-send.nix new file mode 100644 index 0000000..8dfe953 --- /dev/null +++ b/pkgs/python/notify-send.nix @@ -0,0 +1,17 @@ +{ lib, buildPythonPackage, fetchPypi }: + +buildPythonPackage rec { + pname = "notify-send"; + version = "0.0.20"; + + src = fetchPypi { + inherit pname version; + sha256 = "6fddbc5b201728984d2de809959bb6aecf9abb0de5cfa55c7324ca6f48f41e03"; + }; + + meta = with lib; { + description = "Notify send"; + homepage = "https://pypi.org/project/notify-send"; + license = licenses.gpl3; + }; +} diff --git a/pkgs/theme/background-lnxpcs.nix b/pkgs/theme/background-lnxpcs.nix new file mode 100644 index 0000000..a3983af --- /dev/null +++ b/pkgs/theme/background-lnxpcs.nix @@ -0,0 +1,41 @@ +{ lib, stdenvNoCC, fetchFromGitHub, imagemagick }: + +stdenvNoCC.mkDerivation rec { + pname = "background-lnxpcs"; + version = "20190411"; + + src = fetchFromGitHub { + owner = "cynerd"; + repo = "lnxpcs"; + rev = "fd4487e1989fc040490fa437a2651d37afcde637"; + sha256 = "vtyyG0EHRmgWlxHmHgeckwtOv7t3C+hsuTt/vBdrRQM="; + }; + + nativeBuildInputs = [ imagemagick ]; + + wallpapers = "bash cron gcc gnu gnu-linux iptables kernel kill python root su sudo vim"; + buildPhase = '' + for img in $wallpapers; do + echo "Generating: $img" + ./makemywall 1920 1080 "cards/black/$img-card-black.png" + ./makemywall 2560 1440 "cards/black/$img-card-black.png" + ./makemywall 2560 1600 "cards/black/$img-card-black.png" + done + ''; + + installPhase = '' + mkdir -p $out + for img in $wallpapers; do + mv $img-card-black-1920x1080.png $out/ + mv $img-card-black-2560x1440.png $out/ + mv $img-card-black-2560x1600.png $out/ + done + ''; + + meta = with lib; { + description = "Background pictures from lnxpcs and relevant scripts"; + homepage = "https://mega.nz/#F!mXgW3apI!Tdikb01SoOaTmNLiaTRhMg"; + license = licenses.gpl3Only; + platforms = platforms.linux; + }; +} diff --git a/pkgs/theme/delft-icon-theme.nix b/pkgs/theme/delft-icon-theme.nix new file mode 100644 index 0000000..08ed773 --- /dev/null +++ b/pkgs/theme/delft-icon-theme.nix @@ -0,0 +1,35 @@ +{ lib, stdenv, stdenvNoCC, fetchFromGitHub, gtk3, gnome-icon-theme, hicolor-icon-theme }: + +stdenv.mkDerivation rec { + pname = "delft-icon-theme"; + version = "1.15"; + + src = fetchFromGitHub { + owner = "madmaxms"; + repo = "iconpack-delft"; + rev = "v${version}"; + sha256 = "fluSh2TR1CdIW54wkUp1QRB0m9akFKnSn4d+0z6gkLA="; + }; + + nativeBuildInputs = [ gtk3 ]; + + propagatedBuildInputs = [ gnome-icon-theme hicolor-icon-theme ]; + + dontDropIconThemeCache = true; + + installPhase = '' + mkdir -p $out/share/icons + cp -a Delft* $out/share/icons/ + + for theme in $out/share/icons/*; do + gtk-update-icon-cache $theme + done + ''; + + meta = with lib; { + description = "Delft icon theme"; + homepage = "https://github.com/madmaxms/iconpack-delft"; + license = licenses.gpl3Only; + platforms = platforms.linux; + }; +} diff --git a/pkgs/theme/myswaylock.nix b/pkgs/theme/myswaylock.nix new file mode 100644 index 0000000..6b74ce1 --- /dev/null +++ b/pkgs/theme/myswaylock.nix @@ -0,0 +1,19 @@ +{ lib, stdenvNoCC, makeWrapper +, bash, jq, sway, swaylock +, background-lnxpcs +}: + +stdenvNoCC.mkDerivation { + pname = "myswaylock"; + version = "1.0"; + + nativeBuildInputs = [ makeWrapper ]; + phases = [ "installPhase" ]; + installPhase = '' + mkdir -p $out/bin + cp ${./myswaylock.sh} $out/bin/myswaylock + wrapProgram $out/bin/myswaylock \ + --prefix PATH : ${lib.makeBinPath [ bash jq sway swaylock ]} \ + --prefix BACKGROUND_LNXPCS : ${ background-lnxpcs } + ''; +} diff --git a/pkgs/theme/myswaylock.sh b/pkgs/theme/myswaylock.sh new file mode 100755 index 0000000..c204a57 --- /dev/null +++ b/pkgs/theme/myswaylock.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +# Switch to the US keyboard (to make sure that we have the correct one) +swaymsg input type:keyboard xkb_layout us + +resolution="$(swaymsg -t get_outputs \ + | jq -r '.[0].rect | [.width,.height] | join("x")')" +case "$resolution" in + 1920x1080|2560x1440|2560x1600) + ;; + *) + resolution="1920x1080" + ;; +esac + +exec swaylock -f \ + -n -c 000000 \ + -i "$(shuf -n1 -e "$BACKGROUND_LNXPCS"/*"$resolution.png")" \ + -s fill diff --git a/pkgs/theme/swaybackground.nix b/pkgs/theme/swaybackground.nix new file mode 100644 index 0000000..856d774 --- /dev/null +++ b/pkgs/theme/swaybackground.nix @@ -0,0 +1,19 @@ +{ lib, stdenvNoCC, makeWrapper +, bash, jq, sway +, background-lnxpcs +}: + +stdenvNoCC.mkDerivation { + pname = "swaybackground"; + version = "1.0"; + + nativeBuildInputs = [ makeWrapper ]; + phases = [ "installPhase" ]; + installPhase = '' + mkdir -p $out/bin + cp ${./swaybackground.sh} $out/bin/swaybackground + wrapProgram $out/bin/swaybackground \ + --prefix PATH : ${lib.makeBinPath [ bash jq sway ]} \ + --prefix BACKGROUND_LNXPCS : ${ background-lnxpcs } + ''; +} diff --git a/pkgs/theme/swaybackground.sh b/pkgs/theme/swaybackground.sh new file mode 100755 index 0000000..0999943 --- /dev/null +++ b/pkgs/theme/swaybackground.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +_background() { + local resolution="${1:-1920x1080}" + case "$resolution" in + 1920x1080|2560x1440|2560x1600) + ;; + *) + resolution="1920x1080" + ;; + esac + find "$BACKGROUND_LNXPCS" -type f -name "*-$resolution.png" | shuf -n 1 +} + +background() { + local width="$1" + local height="$2" + local res + res="$(_background "${width}x${height}")" + if [ -n "$res" ]; then + res="$(_background)" + fi + echo "$res" +} + +set_backgrounds() { + local ipc="$1" + swaymsg -t get_outputs | jq -r '.[] | [.name,.rect.width,.rect.height] | join(",")' \ + | while IFS=, read -r name width height; do + swaymsg $ipc \ + output "$name" \ + background "$(background "$width" "$height")" fill + done +} + +if [ -n "$WAYLAND_DISPLAY" ]; then + set_backgrounds +else + find "/run/user/$(id -u)/" -name "sway-ipc*" \ + | while read -r ipc; do + set_backgrounds "-s '$ipc'" + done +fi diff --git a/update.sh b/update.sh new file mode 100755 index 0000000..7d99ca4 --- /dev/null +++ b/update.sh @@ -0,0 +1,6 @@ +#!/bin/sh +set -eu + +nix flake update +git add flake.lock +git commit -m 'Flake inputs update' |