❄️ Dotfiles and NixOS configurations
at main 34 lines 952 B view raw
1{ 2 self, 3 lib, 4 ... 5}: let 6 inherit (lib) escapeShellArgs filterAttrs mapAttrs' nameValuePair; 7 8 validConfigurations = filterAttrs (_: nixosSystem: nixosSystem._module.args ? deploy) self.nixosConfigurations; 9 10 mkDeploymentApp = self: name: deploy: pkgs: { 11 type = "app"; 12 program = pkgs.writeShellApplication { 13 name = "deploy-${name}"; 14 15 runtimeInputs = with pkgs; [ 16 nixos-rebuild-ng 17 ]; 18 19 text = '' 20 goal="''${1:-switch}" 21 flake="${self}" 22 name="${name}" 23 targetHost="${deploy.targetHost}" 24 extraFlags=(${escapeShellArgs (deploy.extraFlags or [])}) 25 26 nixos-rebuild "$goal" --flake "$flake#$name" --target-host "$targetHost" "''${extraFlags[@]}" 27 ''; 28 }; 29 }; 30in { 31 perSystem = {pkgs, ...}: { 32 apps = mapAttrs' (name: nixosSystem: nameValuePair "deploy-${name}" (mkDeploymentApp self name nixosSystem._module.args.deploy pkgs)) validConfigurations; 33 }; 34}