From b286b12c2183d2873d10b1c7137fd2b62b3b99db Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Tue, 5 Apr 2022 09:39:09 +0100 Subject: [PATCH] Commit example --- .gitignore | 5 + Cargo.lock | 7 ++ Cargo.toml | 8 ++ nix_flake/README.md | 5 + nix_flake/flake.lock | 74 +++++++++++ nix_flake/flake.nix | 38 ++++++ nix_flake/modules/halloSvc.nix | 44 +++++++ nix_flake/test_vm/README.md | 10 ++ nix_flake/test_vm/flake.lock | 189 +++++++++++++++++++++++++++++ nix_flake/test_vm/flake.nix | 18 +++ nix_flake/test_vm/nixos_config.nix | 15 +++ nix_flake/test_vm/outputs.nix | 36 ++++++ src/main.rs | 3 + 13 files changed, 452 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 nix_flake/README.md create mode 100644 nix_flake/flake.lock create mode 100644 nix_flake/flake.nix create mode 100644 nix_flake/modules/halloSvc.nix create mode 100644 nix_flake/test_vm/README.md create mode 100644 nix_flake/test_vm/flake.lock create mode 100644 nix_flake/test_vm/flake.nix create mode 100644 nix_flake/test_vm/nixos_config.nix create mode 100644 nix_flake/test_vm/outputs.nix create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d975bca --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/target + +nix_flake/test_vm/nixos.qcow2 +nix_flake/test_vm/result +nix_flake/result \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..e1efe16 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "hallo" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..30cc9ae --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "hallo" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/nix_flake/README.md b/nix_flake/README.md new file mode 100644 index 0000000..eeeb3ce --- /dev/null +++ b/nix_flake/README.md @@ -0,0 +1,5 @@ +# Nix flake for Hallo + +Building: + +`nix build '.#' -j 8` diff --git a/nix_flake/flake.lock b/nix_flake/flake.lock new file mode 100644 index 0000000..41fa965 --- /dev/null +++ b/nix_flake/flake.lock @@ -0,0 +1,74 @@ +{ + "nodes": { + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1649096192, + "narHash": "sha256-7O8e+eZEYeU+ET98u/zW5epuoN/xYx9G+CIh4DjZVzY=", + "owner": "nix-community", + "repo": "naersk", + "rev": "d626f73332a8f587b613b0afe7293dd0777be07d", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1648219316, + "narHash": "sha256-Ctij+dOi0ZZIfX5eMhgwugfvB+WZSrvVNAyAuANOsnQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "30d3d79b7d3607d56546dd2a6b49e156ba0ec634", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1648219316, + "narHash": "sha256-Ctij+dOi0ZZIfX5eMhgwugfvB+WZSrvVNAyAuANOsnQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "30d3d79b7d3607d56546dd2a6b49e156ba0ec634", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "naersk": "naersk", + "nixpkgs": "nixpkgs_2", + "utils": "utils" + } + }, + "utils": { + "locked": { + "lastModified": 1648297722, + "narHash": "sha256-W+qlPsiZd8F3XkzXOzAoR+mpFqzm3ekQkJNa+PIh1BQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "0f8662f1319ad6abf89b3380dd2722369fc51ade", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/nix_flake/flake.nix b/nix_flake/flake.nix new file mode 100644 index 0000000..e86a07f --- /dev/null +++ b/nix_flake/flake.nix @@ -0,0 +1,38 @@ +{ + description = "Hallo Nix Flakes"; + + inputs = { + utils.url = "github:numtide/flake-utils"; + naersk.url = "github:nix-community/naersk"; + }; + + outputs = { self, nixpkgs, utils, naersk }: + utils.lib.eachDefaultSystem (system: let + pkgs = nixpkgs.legacyPackages."${system}"; + naersk-lib = naersk.lib."${system}"; + in rec { + # `nix build` + packages.hallo = naersk-lib.buildPackage { + pname = "hallo"; + root = ./..; + }; + + defaultPackage = packages.hallo; + + # NixOS Modules + nixosModules = { + halloSvc = import ./modules/halloSvc.nix; + }; + + # `nix run` + apps.hallo = utils.lib.mkApp { + drv = packages.hallo; + }; + defaultApp = apps.hallo; + + # `nix develop` + devShell = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ rustc cargo ]; + }; + }); +} diff --git a/nix_flake/modules/halloSvc.nix b/nix_flake/modules/halloSvc.nix new file mode 100644 index 0000000..347486e --- /dev/null +++ b/nix_flake/modules/halloSvc.nix @@ -0,0 +1,44 @@ +{config, pkgs, lib, hallo, ...}: + +let + cfg = config.services.halloSvc; +in + +with lib; +builtins.trace ''hallo zzz: blar ${builtins.attrNames hallo.packages}'' +{ + options = { + services.halloSvc = { + enable = mkOption { + default = false; + type = with types; bool; + description = '' + Start the hallo service + ''; + }; + + user = mkOption { + default = "hallo"; + type = with types; uniq string; + description = '' + Name of the user. + ''; + }; + }; + }; + + config = mkIf cfg.enable { + systemd.services.halloSvc = { + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + description = "Start the halloSvc."; + serviceConfig = { + Type = "simple"; + User = "${cfg.user}"; + ExecStart = ''${pkgs.hello}/bin/hallo''; + }; + }; + + environment.systemPackages = [ pkgs.hello ]; + }; +} diff --git a/nix_flake/test_vm/README.md b/nix_flake/test_vm/README.md new file mode 100644 index 0000000..0e27342 --- /dev/null +++ b/nix_flake/test_vm/README.md @@ -0,0 +1,10 @@ +# Test VM for the Hallo Nix Flake + +To build and start a test VM, in this directory, with a copy of Nix that supports flakes, run: + +```shell +nix build .#nixosConfigurations.testvm.config.system.build.vm -j8 +./result/bin/run-nixos-vm +``` + +(An amd64 system is needed for now; otherwise you need to edit `outputs.nix`.) diff --git a/nix_flake/test_vm/flake.lock b/nix_flake/test_vm/flake.lock new file mode 100644 index 0000000..a6ec7d3 --- /dev/null +++ b/nix_flake/test_vm/flake.lock @@ -0,0 +1,189 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1648297722, + "narHash": "sha256-W+qlPsiZd8F3XkzXOzAoR+mpFqzm3ekQkJNa+PIh1BQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "0f8662f1319ad6abf89b3380dd2722369fc51ade", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "hallo": { + "inputs": { + "naersk": "naersk", + "nixpkgs": "nixpkgs_2", + "utils": "utils" + }, + "locked": { + "narHash": "sha256-VRCpO5SrQ/EcjVFJuWXb2uA8fEtVNT8TUaVkXQATeAc=", + "path": "..", + "type": "path" + }, + "original": { + "path": "..", + "type": "path" + } + }, + "lowdown-src": { + "flake": false, + "locked": { + "lastModified": 1633514407, + "narHash": "sha256-Dw32tiMjdK9t3ETl5fzGrutQTzh2rufgZV4A/BbxuD4=", + "owner": "kristapsdz", + "repo": "lowdown", + "rev": "d2c2b44ff6c27b936ec27358a2653caaef8f73b8", + "type": "github" + }, + "original": { + "owner": "kristapsdz", + "repo": "lowdown", + "type": "github" + } + }, + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1649096192, + "narHash": "sha256-7O8e+eZEYeU+ET98u/zW5epuoN/xYx9G+CIh4DjZVzY=", + "owner": "nix-community", + "repo": "naersk", + "rev": "d626f73332a8f587b613b0afe7293dd0777be07d", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, + "nix": { + "inputs": { + "lowdown-src": "lowdown-src", + "nixpkgs": "nixpkgs_3", + "nixpkgs-regression": "nixpkgs-regression" + }, + "locked": { + "lastModified": 1646680282, + "narHash": "sha256-m8tqCS6uHveDon5GSro5yZor9H+sHeh+v/veF1IGw24=", + "owner": "NixOS", + "repo": "nix", + "rev": "ffe155abd36366a870482625543f9bf924a58281", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "2.7.0", + "repo": "nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1648219316, + "narHash": "sha256-Ctij+dOi0ZZIfX5eMhgwugfvB+WZSrvVNAyAuANOsnQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "30d3d79b7d3607d56546dd2a6b49e156ba0ec634", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs-regression": { + "locked": { + "lastModified": 1643052045, + "narHash": "sha256-uGJ0VXIhWKGXxkeNnq4TvV3CIOkUJ3PAoLZ3HMzNVMw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1648219316, + "narHash": "sha256-Ctij+dOi0ZZIfX5eMhgwugfvB+WZSrvVNAyAuANOsnQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "30d3d79b7d3607d56546dd2a6b49e156ba0ec634", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1632864508, + "narHash": "sha256-d127FIvGR41XbVRDPVvozUPQ/uRHbHwvfyKHwEt5xFM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "82891b5e2c2359d7e58d08849e4c89511ab94234", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-21.05-small", + "type": "indirect" + } + }, + "nixpkgs_4": { + "locked": { + "lastModified": 1649024309, + "narHash": "sha256-AWbvj/NHZXVwAnHaVOFlxg7tcNerEKrKBmgGfztSHWM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "af0a9bc0e5341855518e9c1734d7ef913e5138b9", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-21.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "hallo": "hallo", + "nix": "nix", + "nixpkgs": "nixpkgs_4" + } + }, + "utils": { + "locked": { + "lastModified": 1648297722, + "narHash": "sha256-W+qlPsiZd8F3XkzXOzAoR+mpFqzm3ekQkJNa+PIh1BQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "0f8662f1319ad6abf89b3380dd2722369fc51ade", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/nix_flake/test_vm/flake.nix b/nix_flake/test_vm/flake.nix new file mode 100644 index 0000000..b44a304 --- /dev/null +++ b/nix_flake/test_vm/flake.nix @@ -0,0 +1,18 @@ +{ + description = "NixOS Test VM Flake"; + + # To update all inputs: + # $ nix flake update --recreate-lock-file + # (rei: think this may now be nix flake lock) + inputs = { + nix.url = "github:NixOS/nix/2.7.0"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.11"; + + # Useful for arch-independent flakes + flake-utils.url = "github:numtide/flake-utils"; + + hallo.url = "path:.."; + }; + + outputs = { ... } @ args: import ./outputs.nix args; +} diff --git a/nix_flake/test_vm/nixos_config.nix b/nix_flake/test_vm/nixos_config.nix new file mode 100644 index 0000000..da57bdc --- /dev/null +++ b/nix_flake/test_vm/nixos_config.nix @@ -0,0 +1,15 @@ +{ config, pkgs, ... }: +{ + imports = [ + + ]; + # Add a test user who can sudo to the root account for debugging + users.extraUsers.vm = { + isNormalUser = true; + password = "vm"; + shell = "${pkgs.bash}/bin/bash"; + group = "wheel"; + }; + + services.halloSvc.enable = true; +} diff --git a/nix_flake/test_vm/outputs.nix b/nix_flake/test_vm/outputs.nix new file mode 100644 index 0000000..75b0657 --- /dev/null +++ b/nix_flake/test_vm/outputs.nix @@ -0,0 +1,36 @@ +{ self, + nix, + nixpkgs, + flake-utils, + hallo +}: + +( + flake-utils.lib.eachDefaultSystem (system: let + pkgs = nixpkgs.legacyPackages.${system}; + in { + # This lets you type `nix develop` to get needed tools. + #devShell = pkgs.callPackage ./shell.nix {}; + # TODO figure this out devShells.${system}.default = pkgs.callPackage ./shell.nix {}; + } + ) +) // { + nixosConfigurations = { + testvm = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + { + nix.nixPath = [ + "nixpkgs=${nixpkgs}" + ]; + nix.registry = { + nixpkgs.flake = nixpkgs; + }; + } + # TODO: How to specify the system in just one place? rec? + hallo.nixosModules."x86_64-linux".halloSvc + ./nixos_config.nix + ]; + }; + }; +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}