convert flake-update to a submodule type
Signed-off-by: ahuston-0 <aliceghuston@gmail.com>
This commit is contained in:
parent
3fb96c2248
commit
3696ebd976
10
flake.nix
10
flake.nix
@ -186,6 +186,16 @@
|
|||||||
|
|
||||||
formatter = forEachSystem (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style);
|
formatter = forEachSystem (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style);
|
||||||
|
|
||||||
|
# adds our lib functions to lib namespace
|
||||||
|
lib = nixpkgs.lib.extend (
|
||||||
|
self: super: {
|
||||||
|
my = import ./lib {
|
||||||
|
inherit nixpkgs inputs;
|
||||||
|
lib = self;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
nixosConfigurations =
|
nixosConfigurations =
|
||||||
let
|
let
|
||||||
constructSystem =
|
constructSystem =
|
||||||
|
@ -7,20 +7,18 @@
|
|||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.services.autopull;
|
cfg = config.services.autopull;
|
||||||
in
|
|
||||||
{
|
autopull-type = lib.types.submodule {
|
||||||
options = {
|
enable = lib.mkEnableOption "autopull for ${cfg.account-name}";
|
||||||
services.autopull = {
|
|
||||||
enable = lib.mkEnableOption "autopull";
|
|
||||||
name = lib.mkOption {
|
name = lib.mkOption {
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
default = "dotfiles";
|
default = config.module._args.name;
|
||||||
description = "A name for the service which needs to be pulled";
|
description = "A name for the service which needs to be pulled";
|
||||||
};
|
};
|
||||||
|
|
||||||
path = lib.mkOption {
|
path = lib.mkOption {
|
||||||
type = lib.types.nullOr lib.types.path;
|
type = lib.types.path;
|
||||||
default = null;
|
|
||||||
description = "Path that needs to be updated via git pull";
|
description = "Path that needs to be updated via git pull";
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -36,25 +34,47 @@ in
|
|||||||
description = "ssh-key used to pull the repository";
|
description = "ssh-key used to pull the repository";
|
||||||
};
|
};
|
||||||
|
|
||||||
triggersRebuild = lib.mkOption {
|
triggers-rebuild = lib.mkOption {
|
||||||
type = lib.types.bool;
|
type = lib.types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = "Whether or not the rebuild service should be triggered after pulling. Note that system.autoUpgrade must be pointed at the same directory as this service if you'd like to use this option.";
|
description = "Whether or not the rebuild service should be triggered after pulling. Note that system.autoUpgrade must be pointed at the same directory as this service if you'd like to use this option.";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
services.autopull = {
|
||||||
|
enable = lib.mkEnableOption "autopull";
|
||||||
|
|
||||||
|
repo = lib.mkOption { type = lib.types.attrsOf autopull-type; };
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf (cfg.enable && !(builtins.isNull cfg.path)) {
|
config =
|
||||||
|
let
|
||||||
|
repos = lib.filterAttrs (_: { enable, ... }: enable == true) cfg.repo;
|
||||||
|
in
|
||||||
|
lib.mkIf cfg.enable {
|
||||||
environment.systemPackages = [
|
environment.systemPackages = [
|
||||||
pkgs.openssh
|
pkgs.openssh
|
||||||
pkgs.git
|
pkgs.git
|
||||||
];
|
];
|
||||||
systemd.services."autopull@${cfg.name}" = {
|
systemd.services = lib.mapAttrs' (
|
||||||
wantedBy = [ "multi-user.target" ];
|
repo:
|
||||||
after = [ "network.target" ];
|
{
|
||||||
description = "Pull the latest data for ${cfg.name}";
|
name,
|
||||||
environment = lib.mkIf (cfg.ssh-key != "") {
|
ssh-key,
|
||||||
GIT_SSH_COMMAND = "${pkgs.openssh}/bin/ssh -i ${cfg.ssh-key} -o IdentitiesOnly=yes";
|
triggers-rebuild,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
lib.nameValuePair "autopull@${name}" {
|
||||||
|
requires = [ "multi-user.target" ];
|
||||||
|
wants = lib.optionals (triggers-rebuild) [ "nixos-service.service" ];
|
||||||
|
after = [ "multi-user.target" ];
|
||||||
|
before = lib.optionals (triggers-rebuild) [ "nixos-upgrade.service" ];
|
||||||
|
description = "Pull the latest data for ${name}";
|
||||||
|
environment = lib.mkIf (ssh-key != "") {
|
||||||
|
GIT_SSH_COMMAND = "${pkgs.openssh}/bin/ssh -i ${ssh-key} -o IdentitiesOnly=yes";
|
||||||
};
|
};
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
@ -62,15 +82,20 @@ in
|
|||||||
WorkingDirectory = cfg.path;
|
WorkingDirectory = cfg.path;
|
||||||
ExecStart = "${pkgs.git}/bin/git pull --all";
|
ExecStart = "${pkgs.git}/bin/git pull --all";
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
) repos;
|
||||||
|
|
||||||
systemd.timers."autopull@${cfg.name}" = {
|
systemd.timers."autopull@${cfg.name}" = lib.mapAttrs' (
|
||||||
|
repo:
|
||||||
|
{ name, frequency, ... }:
|
||||||
|
lib.nameValuePair "autopull@${name}" {
|
||||||
wantedBy = [ "timers.target" ];
|
wantedBy = [ "timers.target" ];
|
||||||
timerConfig = {
|
timerConfig = {
|
||||||
OnBootSec = cfg.frequency;
|
OnBootSec = cfg.frequency;
|
||||||
OnUnitActiveSec = cfg.frequency;
|
OnUnitActiveSec = cfg.frequency;
|
||||||
Unit = "autopull@${cfg.name}.service";
|
Unit = "autopull@${cfg.name}.service";
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
) repos;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
{ lib, ... }:
|
{ lib, ... }:
|
||||||
{
|
{
|
||||||
services.autopull = {
|
services.autopull = {
|
||||||
|
enable = lib.mkDefault true;
|
||||||
|
repo.dotfiles = {
|
||||||
enable = lib.mkDefault true;
|
enable = lib.mkDefault true;
|
||||||
ssh-key = lib.mkDefault "/root/.ssh/id_ed25519_ghdeploy";
|
ssh-key = lib.mkDefault "/root/.ssh/id_ed25519_ghdeploy";
|
||||||
path = lib.mkDefault /root/dotfiles;
|
path = lib.mkDefault /root/dotfiles;
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
system.autoUpgrade = {
|
system.autoUpgrade = {
|
||||||
enable = lib.mkDefault true;
|
enable = lib.mkDefault true;
|
||||||
|
21
utils/default.nix
Normal file
21
utils/default.nix
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
|
{
|
||||||
|
# create rad-dev namespace for lib
|
||||||
|
rad-dev = {
|
||||||
|
# any(), but checks if any value in the list is true
|
||||||
|
# type:
|
||||||
|
# anyBool:: [bool] -> bool
|
||||||
|
anyBool = lib.any (n: n);
|
||||||
|
|
||||||
|
# pulls a value out of an attrset and converts it to a list
|
||||||
|
# type:
|
||||||
|
# mapGetAttr :: String -> Attrset -> [Any]
|
||||||
|
mapGetAttr = (attr: set: lib.mapAttrsToList (_: attrset: lib.getAttr attr attrset) set);
|
||||||
|
};
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user