From a62e395a208482441958986f4fec13d0f39dd786 Mon Sep 17 00:00:00 2001 From: Daniel Kempkens Date: Wed, 24 Jul 2024 09:54:07 +0200 Subject: [PATCH] all: lix, deploy-rs and just --- flake.nix | 5 +++-- home/programs/fish.nix | 32 +++++++++++++++++++++++++++- home/programs/scripts/nixpkgs-switch | 2 +- justfile | 29 +++++++++++++++++++++++++ system/flakes/argon.nix | 27 +++++++++++++---------- system/hosts/argon.nix | 4 ++-- 6 files changed, 82 insertions(+), 17 deletions(-) create mode 100644 justfile diff --git a/flake.nix b/flake.nix index 9b395c1..cad1ade 100644 --- a/flake.nix +++ b/flake.nix @@ -109,8 +109,8 @@ }; argon = import ./system/flakes/argon.nix { - inherit (inputs) nixpkgs nixos-hardware home-manager agenix; - inherit inputs; + inherit (inputs) nixpkgs nixos-hardware home-manager agenix neovim-nightly-overlay nifoc-overlay; + inherit lix-module; }; neon = import ./system/flakes/neon.nix { @@ -201,6 +201,7 @@ packages = [ inputs'.agenix.packages.agenix inputs'.deploy-rs.packages.default + pkgs.just pkgs.nix-output-monitor ]; diff --git a/home/programs/fish.nix b/home/programs/fish.nix index 210f643..602c79a 100644 --- a/home/programs/fish.nix +++ b/home/programs/fish.nix @@ -62,7 +62,6 @@ in ]; shellAliases = { - nrsw = "nixpkgs-switch"; upa = "nix flake update ~/.config/nixpkgs -v && upn"; ngc = "nix-collect-garbage -d && sudo nix-collect-garbage -d"; nsr = "sudo nix-store --verify --check-contents --repair"; @@ -79,6 +78,37 @@ in echo "$argv" | base64 --decode ''; + nrsw = /* fish */ '' + set -f os (uname) + set -f other_hostname $argv[1] + + switch $os + case Darwin + set -f config_dir "$HOME/.config/nixpkgs" + case Linux + set -f config_dir /etc/nixos + case '*' + echo "Unsupported OS" + exit 1 + end + + pushd "$config_dir" + rm -rf result + + if test -z "$DIRENV_DIR" + eval (direnv export fish 2>/dev/null) + end + + if test "$other_hostname" = "" + just deploy-local-machine (hostname -s) + else + just deploy-remote-machine "$other_hostname" + end + + rm -f result + popd + ''; + upn = /* fish */ '' set -f os (uname) diff --git a/home/programs/scripts/nixpkgs-switch b/home/programs/scripts/nixpkgs-switch index d794642..a56e263 100755 --- a/home/programs/scripts/nixpkgs-switch +++ b/home/programs/scripts/nixpkgs-switch @@ -35,7 +35,7 @@ if test "$other_hostname" = "" end else git pull - nom build --eval-store auto --store "ssh-ng://$other_hostname.ts.kempkens.network" ".#nixosConfigurations.$other_hostname.config.system.build.toplevel" + nom build --eval-store auto --store "ssh-ng://root@$other_hostname.ts.kempkens.network" ".#nixosConfigurations.$other_hostname.config.system.build.toplevel" if test $status -eq 0 deploy --skip-checks ".#$other_hostname" end diff --git a/justfile b/justfile new file mode 100644 index 0000000..c1802c4 --- /dev/null +++ b/justfile @@ -0,0 +1,29 @@ +default: + @just --list + +# Format the entire source tree +fmt: + treefmt + +# Build a local machine +build-local-machine target type='darwin': + nom build ".#{{type}}Configurations.{{target}}.config.system.build.toplevel" + +# Build a remote machine +build-remote-machine target type='nixos': + nom build --eval-store auto \ + --store 'ssh-ng://root@{{target}}.ts.kempkens.network' \ + '.#{{type}}Configurations.{{target}}.config.system.build.toplevel' + +# Deploy to a local machine +deploy-local-machine target type='darwin': _git-pull (build-local-machine target type) + env TERM=xterm-256color {{type}}-rebuild switch --flake ".#{{target}}" + attic push nifoc-systems /run/current-system + +# Deploy to a remote machine +deploy-remote-machine target type='nixos': _git-pull (build-remote-machine target type) + deploy --skip-checks '.#{{target}}' + ssh -t '{{target}}' attic push nifoc-systems /run/current-system + +_git-pull: + -git pull diff --git a/system/flakes/argon.nix b/system/flakes/argon.nix index c0c6246..c987f7a 100644 --- a/system/flakes/argon.nix +++ b/system/flakes/argon.nix @@ -1,12 +1,12 @@ -{ nixpkgs, nixos-hardware, home-manager, agenix, inputs, ... }: +{ nixpkgs, lix-module, nixos-hardware, home-manager, agenix, neovim-nightly-overlay, nifoc-overlay }: let default-system = "aarch64-linux"; nixpkgsConfig = { overlays = [ - inputs.neovim-nightly-overlay.overlays.default - inputs.nifoc-overlay.overlay + neovim-nightly-overlay.overlays.default + nifoc-overlay.overlay ]; config = { @@ -23,25 +23,30 @@ in system = nixpkgs.lib.nixosSystem { system = default-system; modules = [ - ../hosts/argon.nix + { + nixpkgs = nixpkgsConfig; + nix = { + registry.nixpkgs.to = { type = "path"; path = nixpkgs.outPath; }; + nixPath = nixpkgs.lib.mkForce [ "nixpkgs=flake:nixpkgs" ]; + }; + } nixos-hardware.nixosModules.raspberry-pi-4 + lix-module.nixosModules.default + home-manager.nixosModules.home-manager - - agenix.nixosModules.default - { - nixpkgs = nixpkgsConfig; - nix.nixPath = [ "nixpkgs=${nixpkgs}" ]; - nix.registry.nixpkgs.flake = nixpkgs; - home-manager = { useGlobalPkgs = true; useUserPackages = true; users.daniel = import ../../home/hosts/argon.nix; }; } + + agenix.nixosModules.default + + ../hosts/argon.nix ]; }; diff --git a/system/hosts/argon.nix b/system/hosts/argon.nix index 50cf281..0f964f3 100644 --- a/system/hosts/argon.nix +++ b/system/hosts/argon.nix @@ -45,8 +45,6 @@ in system.stateVersion = "22.11"; nix = { - package = pkgs.nixVersions.stable; - settings = { experimental-features = [ "nix-command" "flakes" ]; @@ -60,6 +58,7 @@ in "https://attic.cache.daniel.sx/nifoc-ci?priority=35" "https://nix-community.cachix.org?priority=50" "https://cache.garnix.io?priority=60" + "https://cache.lix.systems?priority=70" ]; extra-trusted-public-keys = [ @@ -67,6 +66,7 @@ in "nifoc-ci:JpD9zqVQi8JuS7B8htPDOQZh08rhInMnGFS9RVhiuwk=" "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" "cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g=" + "cache.lix.systems:aBnZUw8zA7H35Cz2RyKFVs3H4PlGTLawyY5KRbvJR8o=" ]; trusted-users = [