Deployment and lifecycle management for Nix
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add HM module, move seed type default

+93 -13
+10 -9
cli/src/main.rs
··· 22 22 name: Option<String>, 23 23 24 24 #[arg( 25 - value_enum, 25 + value_enum, 26 26 long = "type", 27 27 short = 't', 28 - default_value_t = SeedType::Nixos, 29 28 global = true, 30 29 value_name = "TYPE" 31 30 )] 32 - seed_type: SeedType, 31 + seed_type: Option<SeedType>, 33 32 34 33 #[arg(short, long, global = true, value_name = "SOWER_URL")] 35 34 url: Option<String>, ··· 93 92 #[derive(Debug, Deserialize)] 94 93 pub struct Config { 95 94 name: Option<String>, 95 + #[serde(rename(deserialize = "type"))] 96 96 seed_type: Option<SeedType>, 97 97 url: Option<String>, 98 98 } ··· 106 106 } 107 107 } 108 108 109 - pub fn seed_type(self, seed_type: SeedType) -> Self { 110 - Self { 111 - seed_type: Some(seed_type), 112 - ..self 109 + pub fn seed_type(self, seed_type: Option<SeedType>) -> Self { 110 + if let Some(_) = &seed_type { 111 + Self { seed_type, ..self } 112 + } else { 113 + self 113 114 } 114 115 } 115 116 ··· 180 181 .expect("failed to activate"); 181 182 182 183 if reboot.clone() { 183 - Tree::reboot(yes.clone()); 184 + tree.reboot(yes.clone()); 184 185 } 185 186 } 186 - TreeCommands::Reboot { yes } => Tree::reboot(yes.clone()), 187 + TreeCommands::Reboot { yes } => tree.reboot(yes.clone()), 187 188 }, 188 189 } 189 190
+9 -4
cli/src/sower.rs
··· 69 69 } 70 70 } 71 71 72 - #[derive(Clone, Copy, Debug, Display, VariantNames, Deserialize, ValueEnum)] 72 + #[derive(Clone, Copy, Debug, Deserialize, Display, PartialEq, ValueEnum, VariantNames)] 73 73 #[serde(rename_all = "kebab-case")] 74 74 #[strum(serialize_all = "kebab-case")] 75 75 pub enum SeedType { ··· 151 151 }) 152 152 } 153 153 154 - pub fn reboot(confirm: bool) { 154 + pub fn reboot(&self, confirm: bool) { 155 + if self.seed_type != SeedType::Nixos { 156 + println!("Non-NixOS Trees aren't rebootable"); 157 + return; 158 + } 159 + 155 160 if Self::reboot_needed().expect("failed to check reboot state") { 156 161 println!("Reboot needed."); 157 162 } else { ··· 167 172 Self::run_reboot() 168 173 } 169 174 170 - pub fn reboot_needed() -> std::io::Result<bool> { 175 + fn reboot_needed() -> std::io::Result<bool> { 171 176 let profile_paths = &["initrd", "kernel", "kernel-modules"]; 172 177 let result = profile_paths.iter().any(|&path| { 173 178 let current_path = format!("/nix/var/nix/profiles/system/{}", path); ··· 180 185 Ok(result) 181 186 } 182 187 183 - pub fn run_reboot() { 188 + fn run_reboot() { 184 189 run_command( 185 190 "systemd-run".to_string(), 186 191 vec![
+1
flake.nix
··· 121 121 }; 122 122 123 123 flake.nixosModules.sower = ./nix/module.nix; 124 + flake.homeModules.sower = ./nix/home-module.nix; 124 125 125 126 # don't support darwin 126 127 flake.packages.x86_64-linux = rec {
+73
nix/home-module.nix
··· 1 + { 2 + config, 3 + lib, 4 + pkgs, 5 + ... 6 + }: 7 + let 8 + cfg = config.services.sower; 9 + toml = pkgs.formats.toml { }; 10 + tomlType = toml.type; 11 + in 12 + { 13 + options = { 14 + services.sower = { 15 + enable = lib.mkEnableOption "Sower agent"; 16 + 17 + package = lib.mkOption { type = lib.types.package; }; 18 + 19 + config = lib.mkOption { 20 + type = lib.types.submodule { 21 + freeformType = tomlType; 22 + 23 + options = { 24 + url = lib.mkOption { 25 + type = lib.types.str; 26 + description = "URL to Sower, e.g. https://mysower.org/"; 27 + }; 28 + 29 + type = lib.mkOption { 30 + type = lib.types.enum [ 31 + "nixos" 32 + "home-manager" 33 + "nix-darwin" 34 + ]; 35 + default = "home-manager"; 36 + }; 37 + }; 38 + }; 39 + description = "Sower configuration file"; 40 + default = null; 41 + }; 42 + }; 43 + }; 44 + 45 + config = lib.mkIf cfg.enable { 46 + assertions = [ 47 + { 48 + assertion = cfg.config.url != null; 49 + message = "Sower URL is required"; 50 + } 51 + ]; 52 + 53 + systemd.user.services.sower = { 54 + Service = { 55 + Environment = [ "PATH=${lib.makeBinPath [ pkgs.nix ]}" ]; 56 + ExecStart = "${lib.getExe cfg.package} tree upgrade"; 57 + }; 58 + }; 59 + 60 + systemd.user.timers.sower = { 61 + Install.WantedBy = [ "timers.target" ]; 62 + 63 + Timer = { 64 + OnCalendar = "daily"; 65 + Persistent = true; 66 + }; 67 + }; 68 + 69 + xdg.configFile."sower/config.toml".source = lib.mkIf (cfg.config != null) ( 70 + toml.generate "sower-config.toml" cfg.config 71 + ); 72 + }; 73 + }