diff options
author | notgne2 | 2020-10-02 12:58:11 -0700 |
---|---|---|
committer | notgne2 | 2020-10-02 12:58:11 -0700 |
commit | 5674670a59168fb05f26e5b4fb41dd2662810e94 (patch) | |
tree | 621f526c3f4a53fbd0165d351e5ce74ce37f1b58 /examples | |
parent | 05803e0ebaf417d9ba40645b6548a48bf51f9213 (diff) |
General improvements, deprecate `activate` profile option in favor of executing $PROFILE/activate (Wrap It Yourself) to ensure successful rollback activations
Diffstat (limited to 'examples')
-rw-r--r-- | examples/simple/flake.nix | 47 | ||||
-rw-r--r-- | examples/system/flake.nix | 88 |
2 files changed, 86 insertions, 49 deletions
diff --git a/examples/simple/flake.nix b/examples/simple/flake.nix index 800363f..f53352b 100644 --- a/examples/simple/flake.nix +++ b/examples/simple/flake.nix @@ -5,21 +5,40 @@ { description = "Deploy GNU hello to localhost"; - outputs = { self, nixpkgs }: { - deploy.nodes.example = { - hostname = "localhost"; - profiles.hello = { - user = "balsoft"; - path = nixpkgs.legacyPackages.x86_64-linux.hello; - # Just to test that it's working - activate = "$PROFILE/bin/hello"; + outputs = { self, nixpkgs }: + let + setActivate = base: activate: nixpkgs.legacyPackages.x86_64-linux.symlinkJoin { + name = ("activatable-" + base.name); + paths = [ + base + (nixpkgs.legacyPackages.x86_64-linux.writeTextFile { + name = base.name + "-activate-path"; + text = '' + #!${nixpkgs.legacyPackages.x86_64-linux.runtimeShell} + ${activate} + ''; + executable = true; + destination = "/activate"; + }) + ]; }; - }; - checks = builtins.mapAttrs (_: pkgs: { - jsonschema = pkgs.runCommandNoCC "jsonschema-deploy-simple" { } - "${pkgs.python3.pkgs.jsonschema}/bin/jsonschema -i ${ + in + { + + deploy.nodes.example = { + hostname = "localhost"; + profiles.hello = { + user = "balsoft"; + path = setActivate nixpkgs.legacyPackages.x86_64-linux.hello "./bin/hello"; + }; + }; + checks = builtins.mapAttrs + (_: pkgs: { + jsonschema = pkgs.runCommandNoCC "jsonschema-deploy-simple" { } + "${pkgs.python3.pkgs.jsonschema}/bin/jsonschema -i ${ pkgs.writeText "deploy.json" (builtins.toJSON self.deploy) } ${../../interface/deploy.json} && touch $out"; - }) nixpkgs.legacyPackages; - }; + }) + nixpkgs.legacyPackages; + }; } diff --git a/examples/system/flake.nix b/examples/system/flake.nix index 5179258..68cf3ce 100644 --- a/examples/system/flake.nix +++ b/examples/system/flake.nix @@ -5,47 +5,65 @@ { description = "Deploy a full system with hello service as a separate profile"; - outputs = { self, nixpkgs }: { - nixosConfigurations.example-nixos-system = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ ./configuration.nix ]; - }; + outputs = { self, nixpkgs }: + let + setActivate = base: activate: nixpkgs.legacyPackages.x86_64-linux.symlinkJoin { + name = ("activatable-" + base.name); + paths = [ + base + (nixpkgs.legacyPackages.x86_64-linux.writeTextFile { + name = base.name + "-activate-path"; + text = '' + #!${nixpkgs.legacyPackages.x86_64-linux.runtimeShell} + ${activate} + ''; + executable = true; + destination = "/activate"; + }) + ]; + }; + in + { + nixosConfigurations.example-nixos-system = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ ./configuration.nix ]; + }; - nixosConfigurations.bare = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = - [ ./bare.nix "${nixpkgs}/nixos/modules/virtualisation/qemu-vm.nix" ]; - }; + nixosConfigurations.bare = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = + [ ./bare.nix "${nixpkgs}/nixos/modules/virtualisation/qemu-vm.nix" ]; + }; - # This is the application we actually want to run - defaultPackage.x86_64-linux = import ./hello.nix nixpkgs; + # This is the application we actually want to run + defaultPackage.x86_64-linux = import ./hello.nix nixpkgs; - deploy.nodes.example = { - sshOpts = [ "-p" "2221" ]; - hostname = "localhost"; - fastConnection = true; - profiles = { - system = { - sshUser = "admin"; - activate = "$PROFILE/bin/switch-to-configuration switch"; - path = - self.nixosConfigurations.example-nixos-system.config.system.build.toplevel; - user = "root"; - }; - hello = { - sshUser = "hello"; - activate = "$PROFILE/bin/activate"; - path = self.defaultPackage.x86_64-linux; - user = "hello"; + deploy.nodes.example = { + sshOpts = [ "-p" "2221" ]; + hostname = "localhost"; + fastConnection = true; + profiles = { + system = { + sshUser = "admin"; + path = + setActivate self.nixosConfigurations.example-nixos-system.config.system.build.toplevel "./bin/switch-to-configuration switch"; + user = "root"; + }; + hello = { + sshUser = "hello"; + path = setActivate self.defaultPackage.x86_64-linux "./bin/activate"; + user = "hello"; + }; }; }; - }; - checks = builtins.mapAttrs (_: pkgs: { - jsonschema = pkgs.runCommandNoCC "jsonschema-deploy-system" { } - "${pkgs.python3.pkgs.jsonschema}/bin/jsonschema -i ${ + checks = builtins.mapAttrs + (_: pkgs: { + jsonschema = pkgs.runCommandNoCC "jsonschema-deploy-system" { } + "${pkgs.python3.pkgs.jsonschema}/bin/jsonschema -i ${ pkgs.writeText "deploy.json" (builtins.toJSON self.deploy) } ${../../interface/deploy.json} && touch $out"; - }) nixpkgs.legacyPackages; - }; + }) + nixpkgs.legacyPackages; + }; } |