From 3c2e26c98e198eff665419c0d5210a1022ff9754 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Thu, 2 Feb 2023 05:35:19 -0700 Subject: [PATCH] lib; init with common functions --- flake.nix | 6 +++++- hosts/europa/default.nix | 18 ++---------------- hosts/pwntie/default.nix | 32 ++++++++------------------------ lib/default.nix | 18 ++++++++++++++++++ 4 files changed, 33 insertions(+), 41 deletions(-) create mode 100644 lib/default.nix diff --git a/flake.nix b/flake.nix index 6c44e91..6cc9b30 100644 --- a/flake.nix +++ b/flake.nix @@ -97,6 +97,7 @@ , tsRevProx, taskobs, mcchunkie, gqrss, darwin, xin-secrets, talon, peerix , ... }@inputs: let + xinlib = import ./lib; supportedSystems = [ "x86_64-linux" ]; #[ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; forAllSystems = unstable.lib.genAttrs supportedSystems; @@ -158,7 +159,10 @@ buildSys = sys: sysBase: extraMods: name: sysBase.lib.nixosSystem { system = sys; - specialArgs = { inherit inputs; }; + specialArgs = { + inherit inputs; + inherit xinlib; + }; modules = hostBase.modules ++ extraMods ++ [{ nix = { registry.nixpkgs.flake = sysBase; diff --git a/hosts/europa/default.nix b/hosts/europa/default.nix index 663a324..159b41e 100644 --- a/hosts/europa/default.nix +++ b/hosts/europa/default.nix @@ -1,16 +1,10 @@ -{ config, pkgs, lib, modulesPath, inputs, ... }: +{ config, pkgs, lib, modulesPath, inputs, xinlib, ... }: let myEmacs = pkgs.callPackage ../../configs/emacs.nix { }; peerixUser = if builtins.hasAttr "peerix" config.users.users then config.users.users.peerix.name else "root"; - mkCronScript = name: src: '' - . /etc/profile; - set -x - # autogenreated ${name} - ${src} - ''; jobs = [ { name = "brain"; @@ -31,14 +25,6 @@ let path = [ pkgs.taskobs ] ++ pkgs.taskobs.buildInputs; } ]; - jobToService = job: { - name = "${job.name}"; - value = { - script = mkCronScript "${job.name}_script" job.script; - inherit (job) startAt; - inherit (job) path; - }; - }; in { _module.args.isUnstable = true; @@ -200,7 +186,7 @@ in { ''; }; - systemd.user.services = lib.listToAttrs (builtins.map jobToService jobs); + systemd.user.services = lib.listToAttrs (builtins.map xinlib.jobToService jobs); systemd.services."whytailscalewhy" = { description = "Tailscale restart on resume"; wantedBy = [ "post-resume.target" ]; diff --git a/hosts/pwntie/default.nix b/hosts/pwntie/default.nix index 1d372e1..15904df 100644 --- a/hosts/pwntie/default.nix +++ b/hosts/pwntie/default.nix @@ -1,32 +1,16 @@ -{ config, pkgs, lib, ... }: +{ config, pkgs, lib, xinlib, ... }: let myEmacs = pkgs.callPackage ../../configs/emacs.nix { }; pubKeys = [ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO7v+/xS8832iMqJHCWsxUZ8zYoMWoZhjj++e26g1fLT europa" ]; - mkCronScript = name: src: '' - . /etc/profile; - set -x - # autogenreated ${name} - ${src} - ''; - jobs = [ - { - name = "xin-ci"; - script = "cd ~/src/xin && ./ci"; - startAt = "daily"; - path = [ ]; - } - ]; - jobToService = job: { - name = "${job.name}"; - value = { - script = mkCronScript "${job.name}_script" job.script; - inherit (job) startAt; - inherit (job) path; - }; - }; + jobs = [{ + name = "xin-ci"; + script = "cd ~/src/xin && ./ci"; + startAt = "daily"; + path = [ ]; + }]; in { _module.args.isUnstable = true; imports = [ ./hardware-configuration.nix ]; @@ -37,7 +21,7 @@ in { boot.loader.efi.efiSysMountPoint = "/boot/efi"; boot.kernelPackages = pkgs.linuxPackages_latest; - systemd.user.services = lib.listToAttrs (builtins.map jobToService jobs); + systemd.user.services = lib.listToAttrs (builtins.map xinlib.jobToService jobs); networking = { hostName = "pwntie"; diff --git a/lib/default.nix b/lib/default.nix new file mode 100644 index 0000000..62cc92c --- /dev/null +++ b/lib/default.nix @@ -0,0 +1,18 @@ +let + mkCronScript = name: src: '' + . /etc/profile; + set -x + # autogenreated ${name} + ${src} + ''; + jobToService = job: { + name = "${job.name}"; + value = { + script = mkCronScript "${job.name}_script" job.script; + inherit (job) startAt path; + }; + }; + + xinlib = { inherit mkCronScript jobToService; }; + +in xinlib