From 4b90002e45ab7704f75f5b0a0500dadc8a4019e4 Mon Sep 17 00:00:00 2001 From: Victor Date: Mon, 26 Dec 2022 13:02:48 +0100 Subject: [PATCH] add hm modules: riff --- flake.lock | 24 +++++----- nixos/common/default.nix | 9 ++-- nixos/common/hm-modules/default.nix | 5 ++ nixos/common/hm-modules/riff.nix | 28 +++++++++++ nixos/hosts/thalassa/aoife/home/default.nix | 6 ++- nixos/util.nix | 52 ++++++++++----------- 6 files changed, 79 insertions(+), 45 deletions(-) create mode 100644 nixos/common/hm-modules/default.nix create mode 100644 nixos/common/hm-modules/riff.nix diff --git a/flake.lock b/flake.lock index 3f25682..09f0efd 100644 --- a/flake.lock +++ b/flake.lock @@ -454,11 +454,11 @@ "xdph": "xdph" }, "locked": { - "lastModified": 1671841202, - "narHash": "sha256-w6vfVa6gj48YWjK+GUezq5U3UkvvGo/DEzdhAmr9Mhw=", + "lastModified": 1671982931, + "narHash": "sha256-cRInW7YYjw9xbjDTYOQD9PGo04aPAJWWu78PQ1HPkiQ=", "owner": "hyprwm", "repo": "Hyprland", - "rev": "d87d2dac0b1385a4ab944df293bc48877564106c", + "rev": "cd08fa22fd1ddbb8604e42d01043617a8eb10520", "type": "github" }, "original": { @@ -581,11 +581,11 @@ "utils": "utils_4" }, "locked": { - "lastModified": 1671843840, - "narHash": "sha256-oYVOnPL+rpnDFKiNeEtSDiH1H2sMqpoJmCmtfcs8lT4=", + "lastModified": 1672017029, + "narHash": "sha256-VGztJsDy094qcoaP5gxY0kqpcKGa7olw5v5W1yWqHoc=", "owner": "jyooru", "repo": "nix-minecraft-servers", - "rev": "5a5f7a399e40c0e258aa0fd00529613b5ae2b7e7", + "rev": "8ded123b238808a95e8f3e8588d1dcfb96bdfa65", "type": "github" }, "original": { @@ -800,11 +800,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1671936867, - "narHash": "sha256-tOok3/MJWoRUEoPU5Ma/cTCeuw8ACx3Ozu1MlFcdvc8=", + "lastModified": 1671997655, + "narHash": "sha256-8zUwvnJrBwiFIdw9VgARj1PIQsto5Spn9J5v34b0O7A=", "owner": "nixos", "repo": "nixpkgs", - "rev": "18ee49839ea8817218c3bfe3a62e06f47a10fdd5", + "rev": "aac1f0b25e6b04afad8e05dec5828f5c02398bd1", "type": "github" }, "original": { @@ -886,11 +886,11 @@ }, "nur": { "locked": { - "lastModified": 1671975941, - "narHash": "sha256-n5fEPkVVarOnmO70xxuMFlMwYiNQGEaFm/k1ebx/vMo=", + "lastModified": 1672047887, + "narHash": "sha256-+Ckjrzz+mXVRB2fm12QEpa8Cz/9hm/48emkzyPxh97E=", "owner": "nix-community", "repo": "NUR", - "rev": "ce94b3d5d00080485f7a6dba0243a21d10c69273", + "rev": "0457d302f72e13b29dcf914f19b9616cbec5e44e", "type": "github" }, "original": { diff --git a/nixos/common/default.nix b/nixos/common/default.nix index ae72ddd..09ef92a 100644 --- a/nixos/common/default.nix +++ b/nixos/common/default.nix @@ -1,13 +1,12 @@ { inputs, lib, config, ... }: { # This file deals with everything requiring `inputs`, the rest being delagated to `common.nix` # this is because we can't import inputs from all contexts as that can lead to infinite recursion. - imports = [ - ./common.nix - inputs.vault-secrets.nixosModules.vault-secrets - ]; + imports = [ ./common.nix inputs.vault-secrets.nixosModules.vault-secrets ]; nix.nixPath = [ "nixpkgs=${inputs.nixpkgs}" ]; - nix.registry.nixpkgs.flake = inputs.nixpkgs; + nix.registry.nixpkgs.flake = inputs.nixpkgs; + + home-manager.sharedModules = [ ./hm-modules ]; vault-secrets = let inherit (config.networking) domain hostName; diff --git a/nixos/common/hm-modules/default.nix b/nixos/common/hm-modules/default.nix new file mode 100644 index 0000000..9676a72 --- /dev/null +++ b/nixos/common/hm-modules/default.nix @@ -0,0 +1,5 @@ +{ ... }: { + imports = [ + ./riff.nix + ]; +} \ No newline at end of file diff --git a/nixos/common/hm-modules/riff.nix b/nixos/common/hm-modules/riff.nix new file mode 100644 index 0000000..509a782 --- /dev/null +++ b/nixos/common/hm-modules/riff.nix @@ -0,0 +1,28 @@ +{ config, pkgs, lib, inputs, ... }: +with lib; +let cfg = config.programs.riff; +in { + options.programs.riff = { + enable = mkEnableOption "riff"; + direnv = mkOption { + type = types.bool; + default = false; + description = '' + Whether to enable direnv support + ''; + }; + }; + config = mkIf cfg.enable { + home.packages = [ inputs.riff.packages.${pkgs.system}.riff ]; + + xdg.configFile."direnv/lib/riff.sh" = mkIf cfg.direnv { + executable = true; + text = '' + use_riff() { + watch_file Cargo.toml watch_file Cargo.lock + eval "$(riff --offline print-dev-env)" + } + ''; + }; + }; +} diff --git a/nixos/hosts/thalassa/aoife/home/default.nix b/nixos/hosts/thalassa/aoife/home/default.nix index 5a2dcab..6acb417 100644 --- a/nixos/hosts/thalassa/aoife/home/default.nix +++ b/nixos/hosts/thalassa/aoife/home/default.nix @@ -21,7 +21,6 @@ in { gcc gimp inputs.comma.packages.${pkgs.system}.default - inputs.riff.packages.${pkgs.system}.riff inputs.webcord.packages.${pkgs.system}.default jetbrains.clion jetbrains.idea-ultimate @@ -36,6 +35,11 @@ in { yt-dlp ]; + programs.riff = { + enable = true; + direnv = true; + }; + xdg.mimeApps.enable = true; xdg.mimeApps.defaultApplications = { "text/html" = "firefox.desktop"; diff --git a/nixos/util.nix b/nixos/util.nix index 75294cd..7345fca 100644 --- a/nixos/util.nix +++ b/nixos/util.nix @@ -3,32 +3,31 @@ let inherit (builtins) filter attrValues concatLists; # Helper function to resolve what should be imported depending on the type of config (lxc, vm, bare metal) - resolve_imports = - let - # lookup table - import_cases = { - "lxc" = [ - "${nixpkgs}/nixos/modules/virtualisation/lxc-container.nix" - ./common/generic-lxc.nix - ]; - "vm" = [ - ./common/generic-vm.nix - ]; - "local" = [ - hyprland.nixosModules.default - ]; - }; - in - { hostname, realm, profile ? hostname, type ? "lxc", ... }: [ - home-manager.nixosModules.home-manager - mailserver.nixosModules.mailserver - ./common - "${./.}/hosts/${realm}/${profile}/configuration.nix" - ] ++ import_cases.${type}; -in -{ + resolve_imports = let + # lookup table + import_cases = { + "lxc" = [ + "${nixpkgs}/nixos/modules/virtualisation/lxc-container.nix" + ./common/generic-lxc.nix + ]; + "vm" = [ ./common/generic-vm.nix ]; + "local" = [ hyprland.nixosModules.default ]; + }; + in { hostname, realm, profile ? hostname, type ? "lxc", ... }: + [ + home-manager.nixosModules.home-manager + mailserver.nixosModules.mailserver + ./common + "${./.}/hosts/${realm}/${profile}/configuration.nix" + ] ++ import_cases.${type}; +in { # Add to whatever realm a host belong to its list of tags - add_realm_to_tags = realm: map ({ tags ? [ ], ... }@host: host // { tags = [ realm ] ++ tags; inherit realm; }); + add_realm_to_tags = realm: + map ({ tags ? [ ], ... }@host: + host // { + tags = [ realm ] ++ tags; + inherit realm; + }); # Flatten all hosts to a single list flatten_hosts = hosts: concatLists (attrValues hosts); # Filter out all hosts which aren't nixos @@ -39,8 +38,7 @@ in let # this makes local apply work a bit nicer name = if realm == "thalassa" then hostname else "${hostname}.${realm}"; - in - { + in { "${name}" = { imports = resolve_imports host; networking = {