Commit example

This commit is contained in:
Olivier 'reivilibre' 2022-04-05 09:39:09 +01:00
commit b286b12c21
13 changed files with 452 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
/target
nix_flake/test_vm/nixos.qcow2
nix_flake/test_vm/result
nix_flake/result

7
Cargo.lock generated Normal file
View File

@ -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"

8
Cargo.toml Normal file
View File

@ -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]

5
nix_flake/README.md Normal file
View File

@ -0,0 +1,5 @@
# Nix flake for Hallo
Building:
`nix build '.#' -j 8`

74
nix_flake/flake.lock Normal file
View File

@ -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
}

38
nix_flake/flake.nix Normal file
View File

@ -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 ];
};
});
}

View File

@ -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 ];
};
}

View File

@ -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`.)

View File

@ -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
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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
];
};
};
}

3
src/main.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}