Deployment and lifecycle management for Nix
0
fork

Configure Feed

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

iterate on nixing

+178 -115
+2 -1
config/runtime.exs
··· 32 32 For example: /var/lib/sower/sower.db 33 33 """ 34 34 35 - config :sower, Sower.Repo, database: database_path 35 + maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: [] 36 + config :sower, Sower.Repo, database: database_path, socket_options: maybe_ipv6 36 37 37 38 # The secret key base is used to sign/encrypt cookies and other secrets. 38 39 # A default value is used in config/dev.exs and config/test.exs but you
+4 -2
flake.nix
··· 9 9 outputs = 10 10 inputs@{ flake-parts, ... }: 11 11 flake-parts.lib.mkFlake { inherit inputs; } { 12 - imports = [ ./nix/part.nix ]; 12 + imports = [ ./nix/flakemodule.nix ]; 13 13 14 14 systems = [ "x86_64-linux" ]; # needs support in package as well 15 15 ··· 55 55 ]; 56 56 }; 57 57 58 - packages = rec { 58 + packages = { 59 59 default = pkgs.callPackage ./nix/package.nix { beamPackages = beam; }; 60 60 }; 61 61 }; 62 + 63 + flake.nixosModules.sower = ./nix/module.nix; 62 64 }; 63 65 }
+95
nix/flakemodule.nix
··· 1 + { 2 + config, 3 + lib, 4 + self, 5 + ... 6 + }: 7 + let 8 + cfg = config.sower.seed; 9 + in 10 + { 11 + options = { 12 + sower.seed.buildOutputs = lib.mkOption { 13 + type = lib.types.listOf ( 14 + lib.types.enum [ 15 + "devShells" 16 + "darwinConfigurations" 17 + "homeConfigurations" 18 + "nixosConfigurations" 19 + "packages" 20 + ] 21 + ); 22 + description = "Outputs to automatically expose"; 23 + default = [ 24 + "devShells" 25 + "darwinConfigurations" 26 + "homeConfigurations" 27 + "nixosConfigurations" 28 + "packages" 29 + ]; 30 + }; 31 + }; 32 + 33 + config = { 34 + flake.flakeModules.seed = ./flakemodule.nix; 35 + 36 + flake.sower = 37 + let 38 + enabledOutput = 39 + let 40 + outputs = builtins.attrNames self; 41 + in 42 + output: 43 + (builtins.elem output outputs) && (builtins.elem output cfg.buildOutputs); 44 + 45 + nonSystemOutputToSower = 46 + output: lib.mapAttrs (n: v: { systems = [ v.pkgs.hostPlatform.system ]; }) output; 47 + 48 + perSystemOutputToSower = 49 + output: 50 + let 51 + systemOutputs = lib.mapAttrs (on: ov: (lib.mapAttrs (n: v: n) ov)) output; 52 + allOutputs = 53 + lib.foldlAttrs 54 + ( 55 + acc: n: v: 56 + acc 57 + ++ 58 + builtins.map 59 + (dsv: { 60 + name = dsv; 61 + system = n; 62 + }) 63 + (builtins.attrNames v) 64 + ) 65 + [ ] 66 + systemOutputs; 67 + in 68 + lib.foldl 69 + ( 70 + acc: n: 71 + acc 72 + // { 73 + "${n.name}" = { 74 + systems = (acc.${n.name}.systems or [ ]) ++ [ n.system ]; 75 + }; 76 + } 77 + ) 78 + { } 79 + allOutputs; 80 + in 81 + { 82 + dev-shell = lib.optionalAttrs (enabledOutput "devShells") (perSystemOutputToSower self.devShells); 83 + darwin = lib.optionalAttrs (enabledOutput "darwinConfigurations") ( 84 + nonSystemOutputToSower self.darwinConfigurations 85 + ); 86 + home-manager = lib.optionalAttrs (enabledOutput "homeConfigurations") ( 87 + nonSystemOutputToSower self.homeConfigurations 88 + ); 89 + nixos = lib.optionalAttrs (enabledOutput "nixosConfigurations") ( 90 + nonSystemOutputToSower self.nixosConfigurations 91 + ); 92 + package = lib.optionalAttrs (enabledOutput "packages") (perSystemOutputToSower self.packages); 93 + }; 94 + }; 95 + }
+75
nix/module.nix
··· 1 + { 2 + config, 3 + lib, 4 + pkgs, 5 + ... 6 + }: let 7 + cfg = config.services.sower; 8 + in { 9 + options = { 10 + services.sower = { 11 + enable = lib.mkEnableOption "Enable Sower service"; 12 + 13 + package = lib.mkOption { 14 + type = lib.types.package; 15 + default = pkgs.sower; 16 + }; 17 + 18 + initSecrets = lib.mkOption { 19 + type = lib.types.bool; 20 + default = true; 21 + description = lib.mdDoc '' 22 + Whether to initialise non‐existent secrets with random values. 23 + ''; 24 + }; 25 + 26 + environment = lib.mkOption { 27 + type = lib.types.attrsOf lib.types.str; 28 + default = {}; 29 + }; 30 + }; 31 + }; 32 + 33 + config = lib.mkIf cfg.enable { 34 + systemd.services.sower = { 35 + description = "Sower NixOS management platform"; 36 + 37 + wantedBy = ["multi-user.target"]; 38 + after = ["network-online.target"]; 39 + 40 + serviceConfig = { 41 + DynamicUser = true; 42 + StateDirectory = "sower"; 43 + RuntimeDirectory = "sower"; 44 + 45 + ExecStop = "${cfg.package}/bin/sower stop"; 46 + }; 47 + 48 + environment = 49 + { 50 + RELEASE_DISTRIBUTION = "none"; 51 + DATABASE_PATH = "%S/sower/sower-prod.db"; 52 + PHX_SERVER = "true"; 53 + } 54 + // (lib.optionalAttrs cfg.initSecrets { 55 + RELEASE_COOKIE = "%t/sower/COOKIE"; 56 + SECRET_KEY_BASE_FILE = "%S/sower/secret-key-base"; 57 + }) 58 + // cfg.environment; 59 + 60 + preStart = lib.optionalString cfg.initSecrets '' 61 + ${pkgs.coreutils}/bin/dd if=/dev/urandom bs=1 count=16 | ${pkgs.hexdump}/bin/hexdump -e '16/1 "%02x"' > "$RELEASE_COOKIE" 62 + ${lib.getExe pkgs.pwgen} --capitalize --secure 64 1 | ${pkgs.coreutils}/bin/tr -d '\n' > "$SECRET_KEY_BASE_FILE" 63 + ''; 64 + 65 + script = 66 + (lib.optionalString cfg.initSecrets '' 67 + export SECRET_KEY_BASE=$(cat $SECRET_KEY_BASE_FILE) 68 + '') 69 + + '' 70 + ${cfg.package}/bin/sower eval Sower.Release.migrate 71 + ${cfg.package}/bin/sower start 72 + ''; 73 + }; 74 + }; 75 + }
+2
nix/package.nix
··· 17 17 fileset = lib.fileset.union ./.. (lib.fileset.fileFilter (file: !file.hasExt "nix") ./..); 18 18 }; 19 19 20 + elixir = beamPackages.elixir_1_16; 21 + 20 22 mixNixDeps = import ./mix.nix { 21 23 inherit lib beamPackages; 22 24 overrides = _: prev: {
-112
nix/part.nix
··· 1 - { 2 - config, 3 - lib, 4 - self, 5 - ... 6 - }: 7 - let 8 - cfg = config.sower.seed; 9 - in 10 - { 11 - options = { 12 - sower.seed.buildTypes = lib.mkOption { 13 - type = lib.types.listOf ( 14 - lib.types.enum [ 15 - "devShells" 16 - "darwinConfigurations" 17 - "homeConfigurations" 18 - "nixosConfigurations" 19 - "packages" 20 - ] 21 - ); 22 - description = "Outputs to automatically expose"; 23 - default = [ 24 - "devShells" 25 - "darwinConfigurations" 26 - "homeConfigurations" 27 - "nixosConfigurations" 28 - "packages" 29 - ]; 30 - }; 31 - }; 32 - 33 - config = { 34 - flake.flakeModules.seed = ./part.nix; 35 - flake.sower = 36 - let 37 - perSystemTopToSower = 38 - top: 39 - let 40 - systemTops = lib.mapAttrs (on: ov: (lib.mapAttrs (n: v: n) ov)) top; 41 - allTops = 42 - lib.foldlAttrs 43 - ( 44 - acc: n: v: 45 - acc 46 - ++ 47 - builtins.map 48 - (dsv: { 49 - name = dsv; 50 - system = n; 51 - }) 52 - (builtins.attrNames v) 53 - ) 54 - [ ] 55 - systemTops; 56 - in 57 - 58 - lib.foldl 59 - ( 60 - acc: n: 61 - acc 62 - // { 63 - "${n.name}" = { 64 - systems = (acc.${n.name}.systems or [ ]) ++ [ n.system ]; 65 - }; 66 - } 67 - ) 68 - { } 69 - allTops; 70 - in 71 - { 72 - dev-shell = 73 - lib.optionalAttrs 74 - ( 75 - (builtins.elem "devShells" (builtins.attrNames self)) && (builtins.elem "devShells" cfg.buildTypes) 76 - ) 77 - perSystemTopToSower 78 - self.devShells; 79 - # darwin = 80 - # lib.optionalAttrs 81 - # ( 82 - # (builtins.elem "darwinConfigurations" (builtins.attrNames self)) 83 - # && (builtins.elem "darwinConfigurations" cfg.buildTypes) 84 - # ) 85 - # lib.mapAttrs 86 - # (n: v: { systems = [ v.pkgs.hostPlatform.system ]; }) 87 - # self.darwinConfigurations; 88 - # home-manager = 89 - # lib.optionalAttrs lib.mapAttrs 90 - # ( 91 - # (builtins.elem "homeConfigurations" (builtins.attrNames self)) 92 - # && (builtins.elem "homeConfigurations" cfg.buildTypes) 93 - # ) 94 - # (n: v: { systems = [ v.pkgs.hostPlatform.system ]; }) 95 - # self.homeConfigurations; 96 - nixos = 97 - lib.optionalAttrs 98 - ( 99 - (builtins.elem "nixosConfigurations" (builtins.attrNames self)) 100 - && (builtins.elem "nixosConfigurations" cfg.buildTypes) 101 - ) 102 - lib.mapAttrs 103 - (n: v: { systems = [ v.pkgs.hostPlatform.system ]; }) 104 - self.nixosConfigurations; 105 - package = 106 - lib.optionalAttrs 107 - ((builtins.elem "packages" (builtins.attrNames self)) && (builtins.elem "packages" cfg.buildTypes)) 108 - perSystemTopToSower 109 - self.packages; 110 - }; 111 - }; 112 - }